Skip to content

fix(agents): cross-machine launches always deliver their first message - #257

Merged
jayleaton merged 1 commit into
mainfrom
fix/agent-launch-studio-20261116
Nov 16, 2026
Merged

jayleaton merged 1 commit into
mainfrom
fix/agent-launch-studio-20261116

Conversation

@jayleaton

Copy link
Copy Markdown
Owner

An agent on one machine launching a chat on another (t3_create_and_start_thread) could create the chat and drop its opening message, and t3_thread_launch with an agent profileId failed on a project with no default model. Seen on Studio-01 on 2026-11-16 at about 05:50Z.

Summary

 GatewayRuntimePort.sendMessage(thread, text)
-  shell = subscribeShell(env)  # every chat on the machine, under a 20s timeout
-  thread = shell.find(id)      # read only to copy model and modes
-  startThreadTurn(..., thread.modelSelection, thread.runtimeMode, thread.interactionMode)
+  startThreadTurn(...)         # the server already falls back to the thread's own model and modes

 GatewayRuntimePort.createThread → orchestration.launchThread
+  createdBy: "agent", creationSource: "mcp"   # was always stamped user / web

 t3_thread_launch (no caller thread: linked environment or client)
-  model = input ?? replay ?? caller ?? projectDefault ?? fail("no default model")
+  model = input ?? replay ?? agentProfileModel ?? caller ?? projectDefault ?? fail(...)

Root causes

  1. Dropped message. On Studio, launchThread committed in 19 ms (05:50:16Z). The relaying app's sendMessage then had to fetch a shell snapshot of all 1,858 chats under a 20s Effect.timeout, and that read never reached Studio before the deadline. The call returned partial with "Operation timed out after '20s'". A retry with the same key ran the same snapshot read and returned the same partial. With the read removed, the send is a single idempotent dispatch, and a retry replays it with the recorded command id.
  2. Wrong labels. The WS launchThread handler hard-coded createdBy:"user", and the gateway port left creationSource unset, so it defaulted to web. Every gateway-launched child on Studio has user/web. The launch input now carries an optional createdBy (user | agent). The parent link was already stored correctly (parentThreadId plus parentEnvironmentId). t3_thread_read from a non-linked caller hides a parent on another machine by design, which is why it showed null.
  3. No default model. A caller-less launch (a linked environment's session, or a client) only fell back to the project default. It never used the agent's model, even though thread creation then replaces the placeholder with the agent's own model. MacBook worked because its project has a resolvable default. A launch from inside a thread works because it borrows the caller's model as the placeholder.

Not changed: t3_get_pending_questions timing out against the MacBook comes from the same 20s shell-snapshot read through the relaying app. That tool lists chats, so it needs the snapshot and can't just skip it. Making relayed shell reads faster is separate work.

Evidence

Each fix's test fails on f274490be1 and passes on this branch:

  • packages/client-runtime/src/gateway/runtimePort.test.ts "routes V2 reads and message commands…" (extended)
    • Before: AssertionError: expected 3 to be 2: sendMessage read the shell snapshot.
    • After: passes. The send does no snapshot read, and the launch carries createdBy:"agent" and creationSource:"mcp".
  • apps/server/src/mcp/toolkits/project/handlers.test.ts "a client launches an agent on its own model when the project has no default" (new)
    • Before: OrchestratorMcpFailure: Pass modelSelection: the project has no default model…. This is the error from the report.
    • After: passes and launches on the agent's model.
  • vp run check:changed: format, lint, knip, typecheck (37 packages) and tests (8 files) all pass.

Not tested end to end: a real two-machine relay was not reproduced in dev.

Merge Danger

Door: two-way. The new createdBy launch field is optional, and older servers ignore it.

Blast Radius: agents. This covers the gateway relay's sendMessage and createThread, startThreadTurn (its mode inputs are now optional, and a bootstrap launch falls back to the thread's), and caller-less t3_thread_launch with a profileId.

Opus 5.5 via Claude Code (Ada)

🤖 Generated with Claude Code

t3_create_and_start_thread sent its opening message through the relaying
app's sendMessage, which first read a full shell snapshot of the target
environment under a 20s timeout only to copy the thread's model and modes.
On a large environment that read timed out after the chat was created, so
the message was dropped and every retry hit the same read. sendMessage now
dispatches straight away and the server applies the thread's own model and
modes. Gateway launches also say they came from an agent over MCP instead
of being stamped user/web.

t3_thread_launch with a profileId and no caller thread (a linked
environment or a client) fell back to the project's default model and
failed when there was none, although the agent supplies its own. The
agent's model now comes before the project default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: f274490 · PR result: 68fb4c7 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@jayleaton
jayleaton marked this pull request as ready for review November 16, 2026 06:10
@jayleaton
jayleaton merged commit 5d0e480 into main Nov 16, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant