Skip to content

Forked threads are created without their per-thread t3-code-<threadId> MCP server — silent capability loss, sticky across opencode serve restarts #28949

Closed as not planned

Description

@apigban

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

  1. Run an OpenCode-provider thread normally — its t3-code-<threadId> server connects (~66 tools) and delegation works.
  2. Fork the thread into a new thread mid-mission.
  3. In the fork, try any T3 tool (search({ query: "delegate_task" }) returns nothing; a direct tools["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 returns Unknown tool; search for any T3 tool returns 0 items. No error surfaces anywhere agent-visible.
  • Killing opencode serve --service does 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 — zero t3-code-* "mcp connected" lines, vs. four for the pre-fork parent (tools=66).
  • Queuing turns via t3 thread send onto 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 — forkThread calls client.session.fork (:3989), register (:4018), writeRules (:4019) and returns. No mcp.add anywhere 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 the deny t3-code-* rule (:360-367) bars it from the parent's server.
  • prepareTurn silently no-ops when mcpSessions.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 when attachThread reports the thread already attached (:1260 + :1354-1355) — also silently. McpProviderSessions is in-memory (packages/provider-core/src/server/McpProviderSessions.ts:81), so an opencode serve restart 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

  1. added
    needs more info
    on Nov 1, 2026
  2. juliusmarminge commented on Nov 1, 2026

    @juliusmarminge
    Member

    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:

    1. Parent thread, first turn: t3-code-<id> showed up with 68 tools after the catalog update, and orchestrator_capabilities was found.
    2. Fork from this response, then a turn in the fork: the fork's catalog had its own t3-code-<forkThreadId> (68 tools), and search({ query: "orchestrator_capabilities" }) found it. The parent's namespace was gone, as expected.
    3. Killed the spawned opencode serve, then a turn in the fork: T3 respawned it, and the fork still had its own namespace.
    4. Restarted the T3 server, so the in-memory MCP state was dropped, then a turn in the fork: the fork still had its own namespace.

    I saw no Could not add T3 Code's MCP server warnings. Fork targets do get a credential through ensureThreadAttached, and every ordinary turn calls mcp.add from prepareTurn. 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:

    • the output of opencode --version on the host
    • whether the OpenCode provider has a Server URL set under Settings → Providers. T3 skips its MCP server for external OpenCode servers.
    • how the fork was made (Fork from a response, or forking into a new worktree), and whether the first turn in the fork was a message you sent or a delegated-task report or wake
    • the server trace spans you offered around the fork's first post-fork turn (ensureThreadAttached, prepareMcpSession, and the OpenCode startTurn), from ~/.t3/userdata/logs/server.trace.ndjson
  3. removed
    needs more info
    on Nov 2, 2026
  4. apigban commented on Nov 2, 2026

    @apigban
    Author

    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.

  5. juliusmarminge commented on Nov 12, 2026

    @juliusmarminge
    Member

    @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.

  6. added
    needs more info
    on Nov 19, 2026
  7. juliusmarminge commented on Nov 19, 2026

    @juliusmarminge
    Member

    Closing: no reply in 7 days after we asked for more information. Comment with the missing details and we will reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions