Skip to content
Source
Sign inSign up
pingdotgg/t3code

preview_* tools silently disappear from running agents after a server restart #7870

Closedthedouglenz(GitHub profile, opens in a new tab) opened this issue 3 comments

What happens

After the server restarts, agents in already-running threads lose their preview_* tools. The agent reports that the tools do not exist; nothing is logged and no error surfaces in the UI.

Why

McpSessionRegistry keeps issued credentials only in memory:

// apps/server/src/mcp/McpSessionRegistry.ts:98
const state = yield* SynchronizedRef.make<RegistryState>({ records: new Map() });

The acquireRelease finalizer only clears the module-level activeMcpSessionRegistry pointer, so the map simply dies with the process. A resumed provider session keeps presenting the bearer token it was issued before the restart, the auth middleware no longer has a record for that token hash, and every tool call is rejected.

This is reachable through ordinary use — anything that restarts the backend (an update, the desktop app restarting its server) while a thread has an active provider session.

Reproduce

  1. Start a thread with a provider that gets the t3-code MCP server attached.
  2. Restart the server.
  3. Ask the agent to use a preview_* tool.

The agent reports the tool does not exist rather than reporting an auth failure.

One thing worth knowing before fixing it

issueActiveMcpCredential revokes the thread's existing credentials before issuing new ones:

activeMcpSessionRegistry
  .revokeThread(request.threadId)
  .pipe(Effect.andThen(activeMcpSessionRegistry.issue(request)))

That matters if the fix is "re-issue on resume": a resumed session that is still using its old credential can have it revoked out from under it while the new config is in flight. Persisting credentials and reloading them on boot sidesteps that, but it needs the liveness writes to coalesce or every turn writes a row.

Context

Found downstream in a fork (thedouglenz/trellis), where the same registry serves an additional toolkit and the symptom was more obvious. Happy to leave this as a report — I know large PRs are not what you are looking for.

  1. Observed from the other side of this on OpenCode server 2.0.29: after a service restart under heavy load, the restarted server logged an authentication failure while terminating an MCP session belonging to one of the thread-scoped t3-code-* servers. Log fields, with the connection UUID shortened:

    timestamp=2026-10-15T03:02:21.898Z message="mcp http authentication rejected" status=401 method=DELETE server=t3-code-4c2f11b8-…
    timestamp=2026-10-15T03:02:21.899Z message="failed to terminate MCP session" server=t3-code-4c2f11b8-… error="Failed to terminate session: Unauthorized"

    At 03:04:33.614Z the same named server logged mcp connected, tools=83, and the associated session ultimately reports outcome: succeeded.

    This establishes a cleanup-path authentication failure after a restart, consistent with the in-memory McpSessionRegistry analysis above, but I have not confirmed the disappearing-preview_* symptom or that the rejected token was absent from the restarted registry.

  2. This no longer reproduces on current main (71ba6b374c), so I'm closing it as fixed.

    The fix is de34391427 (#2829, the new orchestrator). The revokeThread-then-issue path in issueActiveMcpCredential is no longer used. ProviderSessionManager.prepareMcpSession now resolves the thread's stored credential against the registry. After a restart the registry has no record of it, so the thread gets a fresh credential, and every adapter reads it when it starts its provider process. Neither the registry nor the old in-memory session config survives the restart, and no provider process does either, so nothing is left presenting a pre-restart token.

    What I ran, on a dev server with a fresh database:

    1. OpenCode, idle restart. An OpenCode thread (anthropic/claude-sonnet-5-5) called preview_status, and it returned normally. I stopped the server with SIGTERM (its opencode serve child exited with it) and started it again on the same database. The same thread called preview_status again: same result.
    2. Claude, mid-turn restart. A Claude thread called preview_status. Its next turn ran sleep 40 and then preview_status. I restarted the server during the sleep. After boot, the interrupted turn resumed and preview_status returned normally.
    3. Server trace. It shows one fresh McpSessionRegistry.issue per thread after each restart, and no /mcp authentication rejections.

    @satyalyadav, about the 401 on DELETE: that is the old provider session trying to end its MCP session with the old server's token while the server restarts. It fails without consequence, which matches the reconnect with 83 tools you saw two minutes later. If tools ever go missing after a restart on a current build, please open a new issue with the provider, the version, and the server log around the restart.

  3. juliusmarminge closed this

  4. An ACP-specific follow-up to the restart credential lifecycle described here, checked on v0.1.8 (bf469bb19669671d0df2efda74ed73867a7137c0).

    Reported reproduction in our setup:

    1. Use an ACP agent that retains its native turn across client reconnects and only rebinds MCP while idle.
    2. Restart T3 during that turn and reload the same native session through the stdio MCP bridge.

    Expected: reconnect to that session without replacing its MCP configuration. Reported result: the agent rejects the changed configuration while busy; T3 creates a replacement session and loses attachment to the original turn.

    Source checks confirm that the registry starts empty and generates a new random credential when issued. acpMcpContext embeds it in T3_ACP_MCP_AUTHORIZATION; session/load receives that changed MCP list. The initial-load failure path starts a runtime without the original session ID.

    A source-function test confirms token loss and changed lists on this tag and main fc2b5de20cb572d2333e03284466e3c804d25c84. The complete ACP restart sequence was not independently rerun.

    Could credentials persist per thread across restarts, or could loading preserve the agent's MCP configuration?

    Written by Hermes Agent (GPT-6.1 Sol), reviewed by a human before posting.

Sign in to join this conversation.