Repository navigation
fix(codemode): Say how scripts reach catalog and MCP tools - #2578
Merged
Merged
Conversation
Co-Authored-By: Thomas Jiang <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
7 screenshot changes — 7 changed · 0 added · 0 removed Review screenshots in Frameshift |
thomasjiangcy
approved these changes
Nov 3, 2026
thomasjiangcy
pushed a commit
that referenced
this pull request
Nov 5, 2026
In a Code Mode script, every `callMcpTool` call returned `{ objectCards:
[] }` with no MCP data. In [this
thread](https://sentry.slack.com/archives/C09FQH46YA2/p1793811592460889),
a GoCD `pipelines` lookup from a script came back empty. A direct call
to the same tool returned the full list.
The bridge from #2539 gives a script the `details` of a call. It uses
the text content only when `details` is `{}`. The `details` of
`callMcpTool` held only `objectCards`, so the MCP data never reached the
script. #2544 made `callMcpTool` a script tool, and #2578 told the model
to call MCP tools from scripts. Since #2578, many MCP calls go through
this path.
The `details` of `callMcpTool` now include `result`. It holds the MCP
`structuredContent`, or the text content when the tool returns none.
`result` is nested, so an MCP server cannot set root fields that the
runtime reads, such as `objectCards`, `continuation`, or
`permission_denied`. `objectCards` does not change, so reply cards work
as before. The Code Mode tool description tells scripts to read
`result`.
**Open question: duplicate data on direct calls**
Pi keeps `details` in the `toolResult` message, and Junior stores the
full message in the conversation event log. The model reads only
`content`. So on a direct call, `details.result` is a second stored copy
of the data in `content`. Script calls store no copy. The bridge gives
the inner result to the script, and the `codemode` row keeps only the
script value and the call status.
Most Junior tools already store two copies, because
`normalizeToolResult` builds `content` from `details`. Those tools limit
their data at the source, so both copies stay small. MCP is different:
`content` stops at 32 KB, but `details.result` has no limit. For the
GoCD `pipelines` call above, the stored row is 16.8 KB today, and
`result` adds about 10 KB. A large MCP response is stored in full.
A smaller alternative is to add `result` only for script calls.
`callFromScript` would pass a flag in the `execute` options, and
`callMcpTool` would add `result` only when the flag is set. Direct calls
would then store no copy, and scripts would still get the full data.
This PR does not include that change. The reviewer decides between the
two.
**Known gap:** cards from MCP calls in a script do not reach the reply,
because the `codemode` result does not forward nested `objectCards`.
This was true before this change.
<!-- junior-request-attribution:start -->
via @lcian.
<!-- junior-request-attribution:end -->
<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CCUMX7ET0%3A1793844026.815789 -->
--
[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CCUMX7ET0%3A1793844026.815789)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CCUMX7ET0%3A1793844026.815789/?project=4510944073809921)
<!-- junior-session-footer:end -->
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Lorenzo Cian <[email protected]>
thomasjiangcy
added a commit
that referenced
this pull request
Nov 12, 2026
Models keep calling `tools.executeTool(...)` and `tools.searchTools(...)` inside Code Mode scripts, even though the `codemode` description says scripts cannot call them (#2578). Reported by @dcramer. Today pi-codemode's `tools` proxy fails the property read with its own hint: "ALL_TOOLS lists every tool; searchTools(query) finds tools by topic." That hint is wrong for Junior, because `searchTools` is not a script tool either. So it steers the model into its next failure. The error also happens before any host call. A script that catches it hides the mistake completely: the call list is empty and the return value looks like "no results". Now the bridge declares `executeTool` and `searchTools` in the VM, but they never run. A call to one reaches the bridge with its arguments and fails at once with the call to make instead. Nothing is reviewed, counted toward the Turn limit, or run: - `executeTool({ tool_name: "searchConversationEvents", arguments })` → "Call `tools.searchConversationEvents(arguments)` directly, with only the object from the executeTool arguments field." - `executeTool` for a name that is not a script tool → call it outside the script. - `searchTools` → call it directly before the script, then call each result as `tools.<tool_name>(args)`. The error is stored on the call record, so it shows in the `codemode` result even when the script swallows the rejection or never awaits the call. `Object.hasOwn(run.tools, name)` is still the only check that lets a call run, and the declarations in the tool description still come from `scriptTools`. The two declarations do show up in `ALL_TOOLS`, and their descriptions say how to make the call. No pi change is needed: this uses only the tools list we pass to `start()` and the outcomes we send back with `deliver()`. To measure whether the steering works, the `codemode` span gets two new signals: - `app.codemode.call.redirected_count`: dispatcher calls that the bridge redirected. - `app.codemode.error.kind:missing_tool`: a script that failed on pi's "tools.X does not exist" read. Before, these were all `script`. It is found the same way as `memory`, by matching pi's error text. If pi changes that text, these go back to `script`. Not in this PR: other `modelOnly` names (`spawnAgent`, `handoff`, ...) still get pi's generic miss error. There is no eval either. The failing shape needs the model to reach for `executeTool` on its own, and evals cannot script the model. <!-- junior-request-attribution:start --> via @thomasjiangcy. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0AHB7N2JCR%3A1794440124.103639 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0AHB7N2JCR%3A1794440124.103639) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0AHB7N2JCR%3A1794440124.103639/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[email protected]>
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.
Production traces since Code Mode shipped show many scripts that fail before their first call because they reach for tools a script cannot see:
tools.executeTool(...)andtools.searchTools(...). The description told the model to usesearchToolsresults inside scripts, but did not say thatsearchToolsandexecuteToolaremodelOnly.tools.mcp__<provider>__<tool>(...). MCP tools exist only behind thecallMcpTooldispatcher, and the description never mentioned it.callMcpToolcan also fall outside the declaration budget, so the model may not see it indeclare const tools.This changes only the tool description:
searchToolsdirectly before the script, and that a script cannot callsearchToolsorexecuteTool.callMcpToolis a script tool, a new line says to call MCP tools throughtools.callMcpTool({ tool_name, arguments }).The description still depends only on the script tool set, so it stays the same between Turns.
This PR does not add aliasing in the bridge. If the failures continue after this ships, that is the next step.
via @thomasjiangcy.
--
View Session [Sentry]