Skip to content

Fix budget tracking: use cumulative cost with handler deltas#129

Open
le-big-mac wants to merge 2 commits into
alexzhang13:mainfrom
le-big-mac:cost_fix
Open

Fix budget tracking: use cumulative cost with handler deltas#129
le-big-mac wants to merge 2 commits into
alexzhang13:mainfrom
le-big-mac:cost_fix

Conversation

@le-big-mac

@le-big-mac le-big-mac commented Mar 2, 2026

Copy link
Copy Markdown

Currently, RLM subcalls see the remaining budget not including what the model has spent in its last call, and _check_iteration_limits overwrites self._cumulative_cost with current_usage.total_cost, which ignores subcall costs.

Fix:

  • Handler cost deltas are synced to _cumulative_cost via _update_handler_cost in _completion_turn before code execution, so subcalls see accurate remaining budget. Child costs (including when next_depth >= self.max_depth) are added directly in _subcall.
  • Don't overwrite _cumulative_cost in _check_iteration_limits.

le-big-mac and others added 2 commits March 1, 2026 17:47
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant