SSH remote: client kills its own managed server on every reconnect (default-runtime adoption check) #15986
Summary#
When the desktop app connects to a remote host over SSH, every reconnect after the first SIGTERMs the healthy server that the client itself launched, then starts a new one. Every provider session (Claude, etc.) on the remote dies on each reconnect.
On my Mac host this caused 22 server restarts in ~18h on v0.0.45. Each one followed a tunnel reconnect (laptop sleep, Wi-Fi blip, app restart).
Root cause#
This is in REMOTE_LAUNCH_SCRIPT in packages/ssh/src/tunnel.ts (lines from v0.0.45; the logic is unchanged on main @ cf3e714b0):
- The client starts the managed server with
--base-dir "$HOME/.t3"(L705) and writesmanagedto$MANAGED_FILE. - Because of that base dir, the managed server writes its own pid and port to
~/.t3/userdata/server-runtime.json. That is the same file the script treats as the "default runtime" (DEFAULT_RUNTIME_FILE, L550). - On the next launch,
resolve_default_runtime_portfinds that file. The pid is alive and the origin is localhost, so it passes. - The port answers
wait_ready, andREMOTE_MANAGED = managed(L646). The script assumes an external service has appeared and killsPID_TO_STOP, then marks the stateexternal. But that pid is the client's own managed server, the same pid as in$PID_FILE. - The
externalbranch re-probes the port. It just killed that server, so the probe fails, the state is cleared, and a fresh server is spawned (L695-709).
tunnel.test.ts (around L300-312) asserts the kill-then-adopt ordering. It does not cover the case where the runtime file belongs to the managed server itself.
Evidence (remote host)#
~/.t3/ssh-launch/<hash>/pid==server-runtime.json.pid, andmanaged=managed.server.logshows a newListening on http://127.0.0.1:377322 times with no error before any of them.server.trace.ndjson:ProviderServicefinalizer (runStopAll→stopSessions) at 10:16:58, last span 10:17:00.ssh-launchfiles rewritten and new server up at 10:17:07. This is a clean SIGTERM followed by an immediate relaunch.
Suggested fix#
Only adopt or kill when the default runtime is not the managed server. For example, skip the kill branch when DEFAULT_RUNTIME_PID = REMOTE_PID and treat it as reuse. Alternatively, have the server record whether it is service-managed in server-runtime.json and check that.
Workaround#
Run t3 service install on the remote host and remove ~/.t3/ssh-launch/<hash>/{pid,managed}. The client then adopts the service as external and never kills it.
Environment: desktop client → remote macOS (Darwin 24.5, arm64) over Tailscale SSH, t3 0.0.45 release archive.
Confirming on Linux with a systemd user service already on the host. Fresh evidence from
t3 triage.Setup. Host: Linux x64 (kernel 7.0.0),
t3code.service(systemd user unit) on127.0.0.1:3773with base dir~/.t3. Client: desktop app on another machine with an SSH environment to this host over Tailscale. Version 0.0.46-nightly.20261010.2948 on both ends.packages/ssh/src/tunnel.tshasn't changed onmainsince 2026-10-06, so this is still live.What happened. The SSH launcher's managed server (
t3 serve --port 3774 --base-dir ~/.t3,managed) restarted 16 times between 2026-10-09 21:04 and 2026-10-11 00:06 UTC. Every restart was a cleanRelay client stopped→shutdown reconciliation→Listening on http://127.0.0.1:3774, with no errors. The user's Claude thread runs on that server, so each restart closed its agent session. In the provider event log, everyquery.closelands 1–3 s after a server stop:managed server stop thread query.close15:38:54 15:38:55 16:29:02 16:29:03 16:34:55 16:34:58 17:19:28 17:19:30 17:42:02 17:42:05 23:49:59 23:50:02 00:05:57 00:05:58 What this adds to the report.
- An installed service doesn't prevent the loop. The service was running on 3773 the whole time. The managed server's startup overwrites
server-runtime.jsonwith its own pid/port, which hides the service from the launcher. The launcher then adopts and kills its own server as described above, instead of adopting the service. - Shutdown erases the service's runtime record. When the managed server stops, it clears
~/.t3/userdata/server-runtime.jsonwithout checking whose record it is (apps/server/src/server.ts, thelayerRuntimeStaterelease). After the final stop the file was gone even though the service was still running. That breaks discovery for the launcher and for CLI commands that read the file, until the service restarts. (#9045 proposes the ownership check.) - Two servers on one base dir both ran a relay tunnel. Both servers started a
cloudflaredfor the same managed tunnel ID while sharing one database. The service's relay log at one point showedoriginService=http://127.0.0.1:3774. Related to #14115.
Workaround that worked here. Remove the SSH environment in the desktop app (its disconnect runs the stop script and clears
pid/port/managed), runsystemctl --user restart t3code.serviceto rewriteserver-runtime.json, and connect through T3 Connect instead. If you keep SSH, the alternative is writingexternalto~/.t3/ssh-launch/<key>/managedand the service port toport.Open fixes: #17684 (newest, mergeable), #13341 and #13521 for the launcher, and #9045 for the runtime-file cleanup on shutdown. This case is the pid-match path #17684 covers.
Related: #16477, #14115, #17039.
Investigated and drafted by Claude Code (Claude Opus 5.5) via
t3 triage.- An installed service doesn't prevent the loop. The service was running on 3773 the whole time. The managed server's startup overwrites
Confirming on macOS 27.0.1 (Mac mini M4 host, reached from a MacBook Pro over SSH via Tailscale), T3 Code Nightly
0.0.46-nightly.20261010.2935.~/.t3/ssh-launch/<key>/pid==server-runtime.jsonpid (both9404),managed=managed.server.loghas 73 clean restarts (V2 orchestration shutdown reconciliation completed→Listening on), with no crash reports. Overnight and idle restarts come about every 15–16 min, matching laptop DarkWakes.- Each restart is followed within about 2 s by a new SSH session from the laptop. For example, the server started at 10:30:16 and the SSH login arrived at 10:30:18. The host never slept, its Wi-Fi was stable, and no update was installed at those times.
- Running agents are lost. Some shutdowns log
terminalizedRuns: 2, stoppedSessions: 2, and the subagents I had resumed were cancelled at 09:57 and 10:30 today. - The desktop app's own backend on the host uses the same
--base-dir ~/.t3(see #14115). macOS also flagged T3 for about 8.6 GB of disk writes in about 6 h, andstatev2.sqliteis about 2 GB.
Still live on
0.0.46-nightly.20261013.3066(both ends). Linux x64 remote over Tailscale SSH, Claude Code 2.1.296, linger on, agent scopes on (app-t3code-agents.slice).27 server relaunches on 2026-10-13 (18 between 13:39 and 20:08 WEST). Each one cost running Claude sessions and their background subagents mid-task. The journal shows both kill paths:
- Stale-tunnel finalizer →
REMOTE_STOP_SCRIPT(16:58, 18:28, 19:29): a ~0.1 s SSH command containsV2 orchestration shutdown reconciliation completed, then a ~5 s launch command logsListening on, then a ~0.9 s pairing command. Same runner version each time, so this isn'tRUNNER_CHANGED. #17919 covers it. - Default-runtime self-kill (20:08, on a 3053→3066 update): one 14 s launch command kills and relaunches.
__ssh-helper runtime-port ~/.t3/userdata/server-runtime.jsonprints the same pid asssh-launch/<key>/pid, withmanaged=managed. #17684 covers it.
Agent scopes don't preserve agents across this:
claudeexits when the server's stdio pipe closes. Expected: reconnecting reattaches to a healthy managed server, and stopping the server is reserved for an explicit Disconnect/Remove. Can #17684 and #17919 be reviewed together? Each fixes only half of the reconnect kill.- Stale-tunnel finalizer →
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Same here on v0.0.45, macOS host reached from a MacBook over SSH: 25 server restarts between 2026-10-05 16:08 and 2026-10-06 08:30 UTC. Each one starts within 10 s of an incoming SSH login from the laptop, mostly sleep/wake overnight. On the host,
~/.t3/ssh-launch/<key>/managedreadsmanagedandpidmatches thepidin~/.t3/userdata/server-runtime.json, so the default-runtime check adopts and kills the client's own server, exactly as described above.Two consequences not mentioned yet:
Session stopped,graceful), and the next turn resumes with "Background agent … didn't finish before the previous session ended". In one evening that killed five running subagents (a builder, a code reviewer, and the same review agent twice), each mid-task, with nothing in the UI at the time.The phone itself never caused a restart: none of its 37 turns changed the model or effort, and switching devices mid-session without a laptop reconnect left the session alive. So the trigger is purely the laptop's SSH launch.