Skip to content

Code mode forces one wait round-trip per awaited bridge tool call #109288

Description

@steipete

Problem

Code mode (tools.codeMode) suspends to the model with a waiting result for every awaited bridge tool call (tools.search / tools.describe / tools.call). Each await therefore costs one wait tool round-trip: a guest block with N tool calls takes N+1 model turns. Only namespace bridge calls were auto-drained inline.

Live multi-provider bench (4 tasks over a 72-tool catalog with adversarial decoys, code mode enabled, defaults):

provider surface ok turns input tokens latency
openai gpt-5.4-mini direct tools 4/4 14 13.1k 20s
openai gpt-5.4-mini code mode 4/4 39 28.5k 94s
anthropic claude-sonnet-5 direct tools 4/4 10 (cached) 21s
anthropic claude-sonnet-5 code mode 4/4 30 (cached) 120s
google gemini-3-flash-preview direct tools 4/4 11 23.9k 19s
google gemini-3-flash-preview code mode 4/4 48 107.7k 115s

Turn counts track tool calls + 1 exactly, so code mode costs ~3x the turns and 2-4.5x the input tokens of direct tool exposure on the same tasks - the opposite of its design goal.

Secondary findings from the same live/stress pass:

  • The exec tool description always advertises API.list/API.read and the MCP namespace even when the run catalog has no MCP tools; weaker models waste exec turns probing the empty API surface (observed live with gpt-5.4-mini).
  • API.list("mcp/") (trailing slash) throws invalid API file path while API.list("mcp") works; observed a model hitting exactly this live.
  • Aborting an exec/wait call did not stop the guest: suspended snapshots for cancelled calls stayed parked in the process-global 64-slot active-run table until TTL (900s), and a running QuickJS worker kept spinning until its interrupt deadline (up to 60s).

Expected

Awaited bridge calls that resolve within the exec deadline should drain inline (like namespace calls already do), one shared wall-clock deadline should bound each exec/wait call, and abort should terminate the guest and drop suspended state.

Repro/measurement harness: multi-provider live bench driving the real Agent runtime with createCodeModeTools + applyCodeModeCatalog over a decoy-heavy catalog; A/B with 20 runs per arm on gpt-5.4-mini confirmed equal success rate (14/20 vs 15/20) with average turns dropping 7.9 -> 4.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.maintainerMaintainer-authored PR

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions