Skip to content

fix(codemode): Redirect catalog dispatcher calls from scripts - #3229

Merged
thomasjiangcy merged 2 commits into
mainfrom
fix/codemode-dispatcher-redirect
Nov 12, 2026
Merged

thomasjiangcy merged 2 commits into
mainfrom
fix/codemode-dispatcher-redirect

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

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.

via @thomasjiangcy.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 12, 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 12, 2026 4:29am UTC

Request Review

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Show 5 more changed screenshots
Conversation Question Picks And Text · Desktop
Conversation Question Picks And Text · Desktop
Changed
Conversation Question Stepper · Desktop
Conversation Question Stepper · Desktop
Changed
Push Notifications Tip · Desktop
Push Notifications Tip · Desktop
Changed
Push Notifications Tip On · Desktop
Push Notifications Tip On · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@thomasjiangcy
thomasjiangcy merged commit db8eabf into main Nov 12, 2026
45 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/codemode-dispatcher-redirect branch November 12, 2026 04:52
thomasjiangcy pushed a commit that referenced this pull request Nov 12, 2026
Follow-up to #3229. That PR kept its own list of the tools to redirect
(`executeTool`, `searchTools`) in `codemode/redirect.ts`. Tool exposure
already decides which tools a script cannot call, so the list was a
second copy of that rule. It also drifts: a new `modelOnly` tool would
get pi's misleading hint again until someone added it by hand.

Now `createPiAgentTools` passes every model tool that is not a script
tool to the bridge as `modelOnlyTools`. That is the `modelOnly` registry
tools plus `searchTools`, `executeTool`, and `codemode`. The VM declares
each one, and a call to one fails with a redirect. `redirect.ts` owns
only the text: the two specific messages for `executeTool` and
`searchTools`, and "X does not run in a script. Call it directly,
outside the script." for the rest. So `spawnAgent`, `handoff`, and the
other loop-control tools are covered too.

`Object.hasOwn(run.tools, name)` is still the only check that lets a
call run. Names that no tool has still get pi's error, labeled
`missing_tool`.

The `codemode` tool test now calls `tools.executeTool` through the real
`createPiAgentTools` wiring, so dropping the derived list fails a test.

<!-- 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>

This branch was successfully deployed

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

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant