fix(agent): explain turns stopped by iteration limits - #92563
Open
fangliquanflq wants to merge 1 commit into
Open
fix(agent): explain turns stopped by iteration limits#92563fangliquanflq wants to merge 1 commit into
fangliquanflq wants to merge 1 commit into
Conversation
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.
What does this PR do?
Turns that reach
agent.max_iterationsafter an earlier empty completion now run the existing summary fallback instead of ending with a blank response. TUI and Desktop clients also receive recoverable error semantics for this incomplete turn instead of a misleadingstatus=completeframe.Symptom
A tool-heavy turn can end at
api_calls=N/Nwithreason=unknown,last_msg_role=tool, andresponse_len=0. The TUI renders a blank completed reply, so the user must guess that they should sendcontinue.Impact
Users can lose the visible conclusion of long-running work and receive no explanation that the configured iteration limit stopped the turn.
Bug Cause
Trigger:
agent/turn_finalizer.py:finalize_turnwhen the API-call cap is reached with a refunded shared budget and a stale blankfinal_response.Causal chain:
final_response=""before recovery continues.max_iterationswhile iteration-budget refunds keepremaining > 0, so the loop falls through withturn_exit_reason="unknown".final_response is Nonefor the max-iteration summary fallback, so the stale blank suppressed both limit classification and summary generation. The TUI then ignoredcompleted=Falseand emittedstatus=complete.Why it is wrong: An empty string is not a usable final answer and must not bypass the same exhaustion handling as
None.Working sibling / contrast: The existing
Nonepath already classifies the exit asmax_iterations_reached(...), requests a toolless summary, and marks the result incomplete.Ruled out: The shared iteration budget itself was not exhausted in the reported trace (
182/240remained), which excludes the separateiteration_budget.consume()failure branch as the source of the warning.Fix
Treat blank string responses as unanswered at the max-iteration finalizer boundary, preserving the existing bounded summary and completion-explainer flow. In the TUI gateway, classify incomplete
max_iterations_reached(...)results as recoverable errors while retaining the generated summary text.Related Issue
Closes #92552
Type of Change
Changes Made
agent/turn_finalizer.py- allow blank responses to enter the existing max-iteration summary fallback.tui_gateway/server.py- emit recoverable error semantics for incomplete iteration-limit turns.tests/agent/test_turn_finalizer_iteration_limit_exit.py- reproduce the refunded-budget blank-response state.tests/tui_gateway/test_failed_turn_retention.py- verify the terminal frame and retained recovery snapshot.How to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) - N/Acli-config.yaml.exampleif I added/changed config keys - N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/AScreenshots / Logs
The regression tests encode the captured
api_calls=240/240, refunded-budget, blank-response state and the TUI terminal-frame behavior.