Skip to content

fix(agent): avoid duplicate goal-check wake on max-iteration complete - #22

Draft
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-management-aad2
Draft

fix(agent): avoid duplicate goal-check wake on max-iteration complete#22
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-management-aad2

Conversation

@cursor

@cursor cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

When a turn completes at max_iterations with active goals, two goal-check agent wakes were registered ~1s apart. That produced duplicate inject_turn goal-check rounds, wasted tokens, and could race goal state updates.

Root cause

AgentCore._finalize_turn was fixed to read run_result.metadata["status"] (e.g. completed) instead of a non-existent run_result.status attribute. run_loop still called _maybe_schedule_goal_continuation_wake() on the final iteration before yielding ReturnAction(status="completed"), so both paths scheduled a wake.

Fix and validation

  • Remove the duplicate scheduling in run_loop; rely on _finalize_turn for completed turns.
  • Overflow turns still schedule in run_loop only (_finalize_turn skips non-completed statuses).
  • Added regression test test_max_iteration_completed_registers_single_goal_wake.
  • tests/test_agent.py::TestProcessInput::test_goal_final_iteration_keeps_assistant_content now passes (was failing with 2 wake calls).
Open in Web View Automation 

_finalize_turn now reads status from run_result.metadata (completed).
run_loop had already scheduled goal-check at max_iterations, so both
paths fired and registered two wakes (~1s apart).

Drop the run_loop duplicate; overflow path still schedules in run_loop
because finalize skips non-completed statuses.

Co-authored-by: Yuxuan Liu <Osc-7@users.noreply.github.com>
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.

1 participant