refactor(agent): remove dead _budget_grace_call / _budget_exhausted_injected flags - #42840
Closed
YiRaaaan wants to merge 1 commit into
Closed
refactor(agent): remove dead _budget_grace_call / _budget_exhausted_injected flags#42840YiRaaaan wants to merge 1 commit into
YiRaaaan wants to merge 1 commit into
Conversation
…njected flags These flags backed the one-turn budget grace mechanism added in NousResearch#7983. NousResearch#8935 found that mechanism was broken — the flag was set *after* the while loop had already exited (so it could never re-enter), and it blocked the _handle_max_iterations fallback, leaving final_response=None and surfacing empty responses on budget exhaustion. NousResearch#8935 fixed it by calling _handle_max_iterations directly from the post-loop tail (now agent/turn_finalizer.finalize_turn), which already injects a summary request and makes one extra toolless API call. But NousResearch#8935 only removed the *producer* side (the setter + grace-message injection). The *consumer* side survived and was later carried into its current home by the god-file extraction refactors: - conversation_loop.py: the `or agent._budget_grace_call` disjunct in the while condition, plus the `if agent._budget_grace_call: = False` branch - agent_init.py: both `_budget_grace_call` and `_budget_exhausted_injected` initializers (the latter's setter was also removed in NousResearch#8935) Nothing sets either flag True anywhere in the tree, so both are unreachable. Runtime behavior is identical with them removed (`... or False` / `if False:`). Also drops the now-obsolete TestBudgetPressure test and a stale grace reference in AGENTS.md's loop pseudocode. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Closing as a duplicate. #32597 already removes both |
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.
Summary
Removes two unreachable flags —
_budget_grace_calland_budget_exhausted_injected— along with their leftover consumer logic. Both are dead code: nothing in the tree ever sets either toTrue, so the branches that read them are unreachable and behaviorally equivalent to being deleted.Why these are dead
The flags backed the one-turn budget grace mechanism introduced in #7983.
#8935 found that mechanism was broken: the flag was set after the
whileloop had already exited (so the loop could never re-enter to use the "grace" call), and worse, it blocked the_handle_max_iterationsfallback from running — leavingfinal_response = Noneand surfacing empty responses on budget exhaustion. #8935 fixed this by calling_handle_max_iterationsdirectly from the post-loop tail (nowagent/turn_finalizer.finalize_turn), which already injects a summary request and makes one extra tool-less API call.However, #8935 only removed the producer side (the setter + grace-message injection). The consumer side survived and was later carried into its current location by the god-file extraction refactors (
extract run_conversation→agent/conversation_loop.py,extract __init__→agent/agent_init.py):agent/conversation_loop.py— theor agent._budget_grace_calldisjunct in thewhilecondition, and theif agent._budget_grace_call: ... = Falsebranchagent/agent_init.py— the_budget_grace_calland_budget_exhausted_injectedinitializers (the latter's setter was also removed in fix: budget-exhausted conversations now get a summary instead of empty response #8935)Since neither flag is ever set
True,... or agent._budget_grace_callreduces to... or Falseandif agent._budget_grace_call:is never taken — the loop always falls through to the normaliteration_budget.consume()path.Changes
agent/conversation_loop.py: drop the dead disjunct from the loop condition; collapse theif/elifso budget consumption is the single check.agent/agent_init.py: remove both flag initializers and their (now-stale) comment block.tests/run_agent/test_run_agent.py: remove the obsoleteTestBudgetPressure::test_grace_call_flags_initialized(asserted the removed flags init toFalse).AGENTS.md: drop the staleor self._budget_grace_callline and "one-turn grace call" wording from the loop pseudocode.Net: 4 insertions, 28 deletions. No behavior change.
Verification
python -m py_compileon all touched modules — clean.grep -rn "_budget_grace_call\|_budget_exhausted_injected"across the tree — zero remaining references.pytest tests/run_agent/test_run_agent.py -k "budget or iteration or grace or max_iter or loop"— 13 passed; full file collects cleanly (371 tests).🤖 Generated with Claude Code