Skip to content

fix(codemode): Say how scripts reach catalog and MCP tools - #2578

Merged
thomasjiangcy merged 1 commit into
mainfrom
fix/codemode-catalog-mcp-steering
Nov 3, 2026
Merged

thomasjiangcy merged 1 commit into
mainfrom
fix/codemode-catalog-mcp-steering

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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(...) and tools.searchTools(...). The description told the model to use searchTools results inside scripts, but did not say that searchTools and executeTool are modelOnly.
  • tools.mcp__<provider>__<tool>(...). MCP tools exist only behind the callMcpTool dispatcher, and the description never mentioned it. callMcpTool can also fall outside the declaration budget, so the model may not see it in declare const tools.

This changes only the tool description:

  • The "N more tools" line now says to call searchTools directly before the script, and that a script cannot call searchTools or executeTool.
  • When callMcpTool is a script tool, a new line says to call MCP tools through tools.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]

@vercel

vercel Bot commented Nov 3, 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 3, 2026 3:08am UTC

Request Review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Event Log · Mobile
Conversation Event Log · Mobile
Changed
Conversation Share Details · Desktop
Conversation Share Details · Desktop
Changed
Conversation Sidebar Collapsed · Desktop
Conversation Sidebar Collapsed · Desktop
Changed
Show 1 more changed screenshot
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@thomasjiangcy
thomasjiangcy merged commit d595bfb into main Nov 3, 2026
65 of 67 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/codemode-catalog-mcp-steering branch November 3, 2026 03:17
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

1 active deployment
Preview – junior-docs — 7b3f8300 Deployed Nov 3, 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