Skip to content

refactor(agent): remove dead _budget_grace_call / _budget_exhausted_injected flags - #42840

Closed
YiRaaaan wants to merge 1 commit into
NousResearch:mainfrom
YiRaaaan:cleanup/remove-dead-budget-grace-flags
Closed

refactor(agent): remove dead _budget_grace_call / _budget_exhausted_injected flags#42840
YiRaaaan wants to merge 1 commit into
NousResearch:mainfrom
YiRaaaan:cleanup/remove-dead-budget-grace-flags

Conversation

@YiRaaaan

@YiRaaaan YiRaaaan commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Removes two unreachable flags — _budget_grace_call and _budget_exhausted_injected — along with their leftover consumer logic. Both are dead code: nothing in the tree ever sets either to True, 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 while loop had already exited (so the loop could never re-enter to use the "grace" call), and worse, it blocked the _handle_max_iterations fallback from running — leaving final_response = None and surfacing empty responses on budget exhaustion. #8935 fixed this 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 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_conversationagent/conversation_loop.py, extract __init__agent/agent_init.py):

Since neither flag is ever set True, ... or agent._budget_grace_call reduces to ... or False and if agent._budget_grace_call: is never taken — the loop always falls through to the normal iteration_budget.consume() path.

Changes

  • agent/conversation_loop.py: drop the dead disjunct from the loop condition; collapse the if/elif so 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 obsolete TestBudgetPressure::test_grace_call_flags_initialized (asserted the removed flags init to False).
  • AGENTS.md: drop the stale or self._budget_grace_call line and "one-turn grace call" wording from the loop pseudocode.

Net: 4 insertions, 28 deletions. No behavior change.

Verification

  • python -m py_compile on 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

…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>
@YiRaaaan

YiRaaaan commented Jun 9, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate. #32597 already removes both _budget_grace_call and _budget_exhausted_injected (among other unused code), and #38282 takes the opposite approach — reviving the grace-call path — and is already tagged needs-decision. Whether to remove or revive this code is best decided on those existing PRs, so this one is redundant. Apologies for the noise, and thanks!

@YiRaaaan YiRaaaan closed this Jun 9, 2026
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have labels Jun 9, 2026
@YiRaaaan
YiRaaaan deleted the cleanup/remove-dead-budget-grace-flags branch June 9, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants