fix(agent): avoid duplicate goal-check wake on max-iteration complete - #22
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(agent): avoid duplicate goal-check wake on max-iteration complete#22cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
When a turn completes at
max_iterationswith active goals, twogoal-checkagent wakes were registered ~1s apart. That produced duplicateinject_turngoal-check rounds, wasted tokens, and could race goal state updates.Root cause
AgentCore._finalize_turnwas fixed to readrun_result.metadata["status"](e.g.completed) instead of a non-existentrun_result.statusattribute.run_loopstill called_maybe_schedule_goal_continuation_wake()on the final iteration before yieldingReturnAction(status="completed"), so both paths scheduled a wake.Fix and validation
run_loop; rely on_finalize_turnforcompletedturns.run_looponly (_finalize_turnskips non-completed statuses).test_max_iteration_completed_registers_single_goal_wake.tests/test_agent.py::TestProcessInput::test_goal_final_iteration_keeps_assistant_contentnow passes (was failing with 2 wake calls).