Skip to content

[BUG][P1] hourly_tracking: module-level _correction_attempts leaks across runs #27

Description

@mishrapravin114

Summary

examples/templates/hourly_tracking/tools.py uses a module-global _correction_attempts counter. It persists across agent runs in the same Python process, so a second hourly run can skip the auto-fix loop and jump straight to human review incorrectly.

Evidence

_correction_attempts = 0

@tool
def correct_transactions() -> dict[str, Any]:
    global _correction_attempts
    _correction_attempts += 1
    ...

@tool
def validate_transactions() -> dict[str, Any]:
    global _correction_attempts
    requires_human_review = not validation_passed and _correction_attempts >= 1

Daemon / timer mode (--daemon, 60-min timer) reuses the same process → state leak.

Expected behavior

Correction attempt count resets per session or per timer tick.

Proposed fix (pick one)

  1. Reset counter at start of fetch_transactions node via a small @tool reset_correction_state()
  2. Store count in session/shared memory keyed by run ID
  3. Use contextvars scoped to execution stream

Avoid breaking mock demo path (first run still shows auto-fix → HITL escalation).

Acceptance criteria

  • Two consecutive ./engine run examples/templates/hourly_tracking --input '{}' runs both follow the same validate → correct → HITL demo path
  • ./engine validate examples/templates/hourly_tracking passes
  • No global mutable state shared across unrelated sessions

Effort

~30 minutes

Related

#2 Hourly Tracking

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingphase-1Phase 1 — pilot / GTMpriority-p0P0 — critical path / do nowtype-agentVertical agent template

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions