Repository navigation
feat(chat): Limit turns by spend and wrap up at the limit - #2152
Merged
Merged
Conversation
A turn now stops at a model spend budget (default $100) instead of a 250 tool-call cap. The tool-call cap stays as a 1,000-call backstop for models without cost data. When a turn reaches a limit, Junior blocks the next tool call and tells the model to reply with its progress. A child agent sends that reply to its parent as a normal result. Only a model that keeps calling tools after that fails the turn. An execution-limit failure in a child agent is now final on the first attempt. Before, the retry marked the Turn as a lost worker and hid the limit from the parent. Co-Authored-By: David Cramer <[email protected]>
Co-Authored-By: David Cramer <[email protected]>
Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
marked this pull request as ready for review
October 15, 2026 17:26
The integration evals recorded these model responses in https://github.com/getsentry/junior/actions/runs/38777214674. The evals of this commit replay them in strict mode. Eval-Suite: integration
Sentry Evalsjunior-behavioral
Base commit junior-guardian
Base commit junior-integration
Base commit junior-router
Base commit |
…lices Add discarded retry usage to the live spend check so provider, empty-output, and confirmation retries count toward maxTurnCostUsd. Persist the turn-limit wrap-up on the turn checkpoint. A resumed slice now stops instead of granting another wrap-up, so a model that keeps calling tools cannot loop through cooperative yields.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8f03725. Configure here.
The integration evals recorded these model responses in https://github.com/getsentry/junior/actions/runs/38781177646. The evals of this commit replay them in strict mode. Eval-Suite: integration
Once a step was told to wrap up, a later tool-calling step stops the turn even when the live totals no longer read as over the limit, such as a resumed slice whose saved usage missed the wrap-up step.
The integration evals recorded these model responses in https://github.com/getsentry/junior/actions/runs/38782319339. The evals of this commit replay them in strict mode. Eval-Suite: integration
Pass the saved wrap-up to the gate once per slice instead of on every call, and trim the limit comments. Co-Authored-By: David Cramer <[email protected]>
dcramer
approved these changes
Oct 15, 2026
The behavioral evals recorded these model responses in https://github.com/getsentry/junior/actions/runs/38783763368. The evals of this commit replay them in strict mode. Eval-Suite: behavioral
This branch was successfully deployed
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.

Child agents doing real work keep hitting the 250 tool-call cap from #1752. The turn fails, the parent sees "model failed", and the child's work is lost. The cap was meant to stop runaway loops, and what those loops really cost was model spend.
maxTurnCostUsdof model cost, $100 by default, across all its execution slices. Retries that Junior throws away count too. The tool-call cap goes from 250 to 1,000 and only matters for models without cost data.disableTools(fix(chat): Keep the tool list stable across Turn origins #2148) disabled. The tool list stays the same, so the provider cache stays valid. The model replies with what it finished, what is left, and how to continue, and a child agent sends that reply to its parent as a normal result. Any later tool call in the turn fails it. The turn checkpoint saves the wrap-up, so a later slice does not wrap up again.The $100 default comes from Sentry span cost estimates: one child agent that made 250 tool calls cost about $50.
Not in this PR:
task-execution/conversation-turn.ts, which still retries limit failures.The new subagent eval uses a 3-call limit to stand in for a spent budget.
Context: JUNIOR-96, event
49c00ccc6e12485e9f4b18a97c3010d6.via David Cramer.
--
View Junior Session [Sentry]