Skip to content

fix(codemode): Ask the model to wrap up past the turn limit on both tool paths - #2545

Merged
thomasjiangcy merged 2 commits into
mainfrom
fix/codemode-turn-limit-wrapup
Nov 2, 2026
Merged

thomasjiangcy merged 2 commits into
mainfrom
fix/codemode-turn-limit-wrapup

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes the regression from #2544 in the integration eval subagents.eval.ts > "when a child agent uses its turn budget, it reports its progress instead of failing". It failed live twice on run 41465177791. In both runs the child Turn failed with Agent turn exceeded execution limit (3 tool calls) and did not wrap up.

What happened

With Code Mode, the model can reach a tool in two ways: a direct call or a codemode script. The turn-limit text covered only one of them:

  • Direct path. The gate blocked the first step past the limit with systemTime is disabled in this Turn. … Do not call it again in this Turn. The text names one tool. If the model then makes a tool call through the other path, that second over-limit step gets stop, and the Turn fails.
  • Script path. The bridge failed each nested call past the limit with the terminal text Agent turn exceeded execution limit (N tool calls). It never told the model to reply with its progress.

Evidence from the CI artifacts (integration-results-2.json):

  • In the failing and the passing runs (for example 41441056295 and 41424882348), the case made the same number of gateway requests (/v1/messages: 9). The passing child made 5 model steps: systemTime ×3, a 4th systemTime that was blocked, then a reply. The failing child also made 5 steps. Its systemTime request count was more than 3, and it ended on stop. So the child made a tool call in the step after the wrap-up block.
  • Only the stop branch in agent/index.ts throws TurnToolCallLimitExceededError. A local repro confirmed that the bridge's nested failures stay inside the script result.
  • The eval reports do not keep the child transcript, and Roach dropped the failed sessions. So the tool that the 5th step called is not recorded. The step counts fit "4 direct calls, then codemode" best (hypothesis b). They also fit a few other orders that mix a script and direct calls. A local repro with fixed model output gives the same failed Turn and the same error for each order.

Change

  • services/turn-limit.ts: TURN_LIMIT_DISABLED_REASON becomes TURN_LIMIT_WRAP_UP_MESSAGE. The text names no single tool and says that codemode scripts are also disabled. It still asks for a progress reply.
  • agent/index.ts: the wrap_up block returns that message, not disabledToolMessage(toolCall.name, …).
  • codemode/bridge.ts: a nested call past the limit fails with the same message, not the terminal error text.
  • No change to createTurnLimitGate, the wrap_up/stop steps, bridge concurrency, or Guardian.

Tests

  • tests/integration/codemode/bridge.test.ts: when a script reaches the limit, the call that fits runs, and later calls fail with the wrap-up message.
  • evals/integration/agent/scripts.eval.ts: new case. When a script reaches the turn limit (maxToolCallsPerTurn: 3), the script result shows the wrap-up message, the Turn succeeds, and there is one reply. tests/ cannot run the agent (test-architecture:check), so the Turn-level check is an eval.

Checks

  • pnpm typecheck, pnpm lint, pnpm file-length:check: pass.
  • Vitest: tests/integration/codemode, tests/component/codemode, tests/unit/services, tests/component/runtime, tests/component/config, and the tool-support suites: 44 files, 388 tests pass.
  • Not run locally: the evals and pnpm cli -- chat QA. This sandbox has no ROACH_TOKEN and no AI Gateway credentials. CI records the new eval case and runs the turn budget case again live. The wording change is model-facing, so CI is the real check.

Open question

After a wrap-up, the gate still ends the Turn on the next tool call. If the model keeps trying after this change, the next step is a policy decision. One option is to allow a bounded second wrap-up step before stop. I did not make that change here.

via @thomasjiangcy.

--

View Session [Sentry]

…ool paths

With Code Mode, the model can call a tool directly or through a
`codemode` script. The turn-limit text covered only one path:

- The gate blocked a direct call with "<tool> is disabled in this
  Turn ... Do not call it again in this Turn." The model then called the
  same tool through the other path. That second over-limit step hit
  `stop`, and the turn failed with "Agent turn exceeded execution limit".
- The bridge failed a nested call past the limit with that same terminal
  error text, and never told the model to reply with its progress.

Both paths now return one message, `TURN_LIMIT_WRAP_UP_MESSAGE`. It names
no single tool, says that scripts are also disabled, and asks for a
progress reply. The gate and its `wrap_up`/`stop` steps do not change.

Co-Authored-By: Thomas Jiang <[email protected]>
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 2, 2026 4:04pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

7 screenshot changes — 7 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automation Run Details Light · Desktop
Automation Run Details Light · Desktop
Changed
Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Share Details · Desktop
Conversation Share Details · Desktop
Changed
Show 1 more changed screenshot
Location Detail · Desktop
Location Detail · Desktop
Changed

@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 2, 2026 16:16
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 2, 2026
@thomasjiangcy
thomasjiangcy merged commit 8d4e754 into main Nov 2, 2026
65 of 66 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/codemode-turn-limit-wrapup branch November 2, 2026 16:51

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 0f50108b Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant