Skip to content

fix(agents): reset task state for each run - #924

Open
daleselaji-dev wants to merge 1 commit into
SWE-agent:mainfrom
daleselaji-dev:agent/reset-run-state
Open

fix(agents): reset task state for each run#924
daleselaji-dev wants to merge 1 commit into
SWE-agent:mainfrom
daleselaji-dev:agent/reset-run-state

Conversation

@daleselaji-dev

Copy link
Copy Markdown

Fixes #909.

Root cause

DefaultAgent initializes its step count, cost, consecutive format-error count, and wall-clock start time only in __init__(). Although run() clears the message history, it keeps those task-scoped values.

Reusing an agent therefore gives the next task the previous task's consumed budget. A second run can stop with LimitsExceeded or TimeExceeded before making a model call, and stale format errors can contribute to an unrelated task.

What changed

  • Reset cost, n_calls, and n_consecutive_format_errors at the start of every run().
  • Start a fresh wall-clock budget for every run().
  • Add a regression test that reuses one agent for two tasks, injects stale cost/error/time state between them, and verifies that the second task receives one independent model call.

This keeps instance configuration, model/environment objects, global model statistics, and per-run trajectory serialization unchanged.

Validation

python -m pytest +  tests/agents/test_default.py::test_step_limit_enforcement +  tests/agents/test_default.py::test_run_resets_task_scoped_limits -q
6 passed

ruff check src/minisweagent/agents/default.py tests/agents/test_default.py
All checks passed!

ruff format --check src/minisweagent/agents/default.py tests/agents/test_default.py
2 files already formatted

The six pytest cases cover the text, tool-call, and Responses API deterministic model fixtures. I did not report the entire test_default.py file as green on this Windows host because several existing tests depend on Bash output semantics; the focused limit/reset cases are platform-independent and pass.

Risk and review notes

The behavioral change is intentionally limited to repeated calls to run() on the same agent instance. The primary review point is whether all four values are task-scoped; they already describe per-run limits and are emitted as per-instance trajectory statistics, while global accounting remains in GLOBAL_MODEL_STATS.

@daleselaji-dev
daleselaji-dev marked this pull request as ready for review August 4, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultAgent.run() retains per-run budget and timing state across invocations

1 participant