Repository navigation
Description
Summary
Forking a thread creates the new thread's OpenCode session without registering its per-thread t3-code-<threadId> MCP server. The fork's tool catalog is snapshotted before the server ever exists, so the agent silently loses every T3 capability (delegate, watch, orchestration) — no error surfaces anywhere. The loss is sticky: opencode serve restarts re-attach sessions against in-memory per-thread state without healing it. Only the pre-fork thread keeps working.
Full diagnosis with source citations (main @ fa31b66), repro, and evidence: reproduced today on a headless Linux ssh-launch deployment; independently confirmed by reading the adapter/orchestration source.
Area
packages/provider-opencode (v2 adapter), apps/server orchestration-v2
Environment
- T3 Code server:
0.1.6(latest stable), headless Linux, OpenCode provider spawned by T3 (opencode serve --service) - OpenCode 2 harness, Code Mode (
execute/search) - Thread forked mid-mission via T3's fork into a new thread
Steps to reproduce
- Run an OpenCode-provider thread normally — its
t3-code-<threadId>server connects (~66 tools) and delegation works. - Fork the thread into a new thread mid-mission.
- In the fork, try any T3 tool (
search({ query: "delegate_task" })returns nothing; a directtools["t3-code-<forkThreadId>"].orchestrator_capabilities(...)fails).
Expected behavior
The fork's native OpenCode session is registered with its own t3-code-<forkThreadId> MCP server — before or at session creation — so its catalog carries the namespace like any non-forked thread. Any failure to register should be visible (instructions should not claim tools that don't exist; a warning should exist server-side).
Actual behavior
- The fork's catalog never contains
t3-code-<forkThreadId>. Every call returnsUnknown tool;searchfor any T3 tool returns 0 items. No error surfaces anywhere agent-visible. - Killing
opencode serve --servicedoes not help: T3 respawns it and sessions re-attach against T3's in-memory per-thread state; the fork stays injection-free. After the restart, OpenCode's log reconnects only static-config MCP servers — zerot3-code-*"mcp connected" lines, vs. four for the pre-fork parent (tools=66). - Queuing turns via
t3 thread sendonto the fork does not recover it either. - Workaround that does work: continue on the original (pre-fork) thread, whose session still carries its injection.
Source reading (main @ fa31b66)
packages/provider-opencode/src/server/v2/adapter.ts:3964-4041—forkThreadcallsclient.session.fork(:3989),register(:4018),writeRules(:4019) and returns. Nomcp.addanywhere in the fork path; the comment at :4016 says forks "skip initial resume".resumeThread(:3445-3476) likewise never registers.- Injection exists only in
prepareTurn(:3016-3078), reached only from the ordinary prompt path (:3586); wake/continuation turns return before it (:3519). Per [Bug] OpenCode threads start with no T3 MCP tools on their first turn #22945, OpenCode 2 snapshots the session's tool catalog at session creation — so a fork's catalog is built before its own server is ever registered, and thedeny t3-code-*rule (:360-367) bars it from the parent's server. prepareTurnsilently no-ops whenmcpSessions.read(threadId)is undefined (:3021, :3025-3028, :3041) — no warning, and the orchestration system-prompt segment is just omitted (:3064-3069). A thread that ends up here looks exactly like our repro: no namespace, no error, instructions quiet about it.- Credential preparation for the fork happens in
ProviderSessionManager.ensureThreadAttached(apps/server/src/orchestration-v2/ProviderSessionManager.ts:1355), but it is skipped whenattachThreadreports the thread already attached (:1260 + :1354-1355) — also silently.McpProviderSessionsis in-memory (packages/provider-core/src/server/McpProviderSessions.ts:81), so anopencode serverestart cannot heal it.
Open question for triage
No Could not add T3 Code's MCP server warning was ever logged server-side across the incident (event-stream reconnects at 03:58/09:27×2/09:57, backend respawn at 09:48/09:57), so the failed-add path (:3056-3060) was never taken. That leaves two candidates consistent with the code: (a) mcpSessions.read(forkThreadId) kept returning undefined (credential never prepared — attach short-circuit or an un-prepared fork attach), or (b) the fork's turns after the fork were wake/queued turns that never reached prepareTurn (:3519). Server trace spans around the fork's first post-fork turn (prepareTurn, ensureThreadAttached, prepareMcpSession) would discriminate; happy to capture them.
Fix direction
Register the fork's t3-code-<forkThreadId> server at fork time — same shape as #22944 does for first-turn sessions in openSession, applied to forkThread (and ideally resumeThread) before/alongside client.session.fork. Per-thread isolation (distinct names + mcpRules deny/allow) is unchanged. Secondarily, make the wanted === undefined branch in prepareTurn observable (log once per thread), and consider re-running prepareMcpSession when an already-attached thread turns with no credential.
Version
T3 Code server 0.1.6 (latest stable; nightlies through v0.1.7-nightly.20261101.4048 contain no change here — #22944 is unmerged).
Activity
juliusmarminge commentedon Nov 1, 2026
I tried this on main at
fa31b66(the commit the report cites), using a dev server on a fresh database with OpenCode 2.2.5 spawned by T3 and Claude Sonnet 5.5 through OpenCode. I couldn't reproduce it:t3-code-<id>showed up with 68 tools after the catalog update, andorchestrator_capabilitieswas found.t3-code-<forkThreadId>(68 tools), andsearch({ query: "orchestrator_capabilities" })found it. The parent's namespace was gone, as expected.opencode serve, then a turn in the fork: T3 respawned it, and the fork still had its own namespace.I saw no
Could not add T3 Code's MCP serverwarnings. Fork targets do get a credential throughensureThreadAttached, and every ordinary turn callsmcp.addfromprepareTurn. The only gap I saw was the first-turn catalog lag already tracked in https://git.cafe/pingdotgg/t3code/issues/22945: one search right after a catalog change came back empty, and a retry in the same turn found the tool.To narrow this down, could you share:
opencode --versionon the hostensureThreadAttached,prepareMcpSession, and the OpenCodestartTurn), from~/.t3/userdata/logs/server.trace.ndjsonapigban commentedon Nov 2, 2026
Workaround documented downstream: the affected deployment now keeps a recovery runbook — docs/agents/t3-threads.md in apigban/project-atlas — built from the incident that produced this report (continue the mission on the pre-fork thread via
t3 thread send <original-thread-id>; restarts and self-send verified NOT to work). Full diagnosis memo: docs/research/2026-11-01-t3-fork-loses-thread-mcp.md. Upgrade when this is fixed is tracked downstream as well.juliusmarminge commentedon Nov 12, 2026
@apigban Could you attach the server trace spans (ensureThreadAttached, prepareMcpSession and the OpenCode startTurn) for the fork's first turn after the fork, from ~/.t3/userdata/logs/server.trace.ndjson? Please include the output of
opencode --version, whether a Server URL is set for OpenCode under Settings → Providers, and whether that first turn was a message you typed or a delegated-task report or wake.juliusmarminge commentedon Nov 19, 2026
Closing: no reply in 7 days after we asked for more information. Comment with the missing details and we will reopen.