Fix budget tracking: use cumulative cost with handler deltas#129
Open
le-big-mac wants to merge 2 commits into
Open
Fix budget tracking: use cumulative cost with handler deltas#129le-big-mac wants to merge 2 commits into
le-big-mac wants to merge 2 commits into
Conversation
Replace _child_cost with a single _cumulative_cost running total. Handler cost deltas are synced via _update_handler_cost in _completion_turn before code execution, so subcalls see accurate remaining budget. Child costs are added directly in _subcall. Budget tests exercise the real _completion_turn flow rather than setting _cumulative_cost directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When _subcall hits max_depth and does a plain LM completion instead of spawning a child RLM, the cost was not added to _cumulative_cost. This meant fallback subcall spending was invisible to budget tracking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.
Currently, RLM subcalls see the remaining budget not including what the model has spent in its last call, and
_check_iteration_limitsoverwritesself._cumulative_costwithcurrent_usage.total_cost, which ignores subcall costs.Fix:
_cumulative_costvia_update_handler_costin_completion_turnbefore code execution, so subcalls see accurate remaining budget. Child costs (including whennext_depth >= self.max_depth) are added directly in _subcall._cumulative_costin_check_iteration_limits.