Skip to content

fix(native): local connect pairs only with a matching CLI, switching drops the old connection - #49

Merged
rynfar merged 5 commits into
nativefrom
nw/w13-fixes
Nov 2, 2026
Merged

rynfar merged 5 commits into
nativefrom
nw/w13-fixes

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

An independent review of the one-click "Connect to T3 Code on this Mac" flow (#44) found a safety issue and several correctness gaps. The developer is about to use it against a live install, so this PR fixes them, safety first.

What changed

  • Version guard before t3 pair (P1 safety). t3 pair opens the server's SQLite auth store and runs its migrations, so a CLI newer than the running server could migrate a live database. The app now runs <t3> --version first and pairs only when it prints exactly the serverVersion in server-runtime.json. Otherwise it shows "The t3 CLI (vX) doesn't match the running T3 Code (vY). Create a pairing link in T3 Code → Settings → Sharing & access instead." and the paste flow stays available. It also refuses when either version is unknown.
  • Switching environments drops the old connection (P1). The terminal drawer (metadata driver, grants watcher, panes), the git store (status/terminal feeds, grants) and the usage page now follow a connection id. Any client change tears them down, including a switch that stays inside Online, so nothing keeps the old ClientHandle (and its supervisor) alive.
  • Discovered address change. When discovery finds the same environment id at a new origin, a saved local pairing moves to that origin (and reconnects) before connecting.
  • Reused PID. Discovery probes each live candidate's descriptor and moves on to the next when one doesn't answer, as discoverPairTarget does.
  • HTTP 426 from /ws now maps to the blocked/unsupported state instead of retrying forever.
  • Environment persistence off the UI thread. Saves send edits to the background writer, which re-reads environments.json and applies them, so two app instances keep each other's entries. The legacy migration goes through that writer too.
  • Relative T3CODE_HOME is resolved once against the launch directory. That absolute path goes to both discovery and --base-dir/T3CODE_HOME for the CLI.
  • Cancel/Disconnect cancel pairing. Each pairing has an attempt id. Cancel and Disconnect abort the task and ignore a late result.
  • CLI process tree. The CLI runs in its own process group, and the whole group is killed on timeout or cancel.

Evidence

  • Tests: version parsing and the exact-match comparison (local_server), discovery falling through a non-answering origin, the timeout and cancel tests killing the CLI's grandchild, a supervisor test for 426 → Unsupported with no auto-retry, the store merge/relocate tests.
  • Headless probe against the smoke server (fake relative T3CODE_HOME, T3_NATIVE_T3_BIN wrapper, scratch T3_NATIVE_HOME):
    • Mismatched wrapper (--version → v0.1.7-nightly…): Error: The t3 CLI (v0.1.7-nightly.20261102.4061) doesn't match the running T3 Code (v0.1.6). Create a pairing link…, and pair was never invoked.
    • Matching wrapper (--version → v0.1.6): paired with http://127.0.0.1:14658, status: Connected, shell snapshot. The CLI got --base-dir <absolute scratch home> from the relative T3CODE_HOME.
  • Live machine (read-only): ~/.t3/bin/t3 --version prints t3 v0.1.7-nightly.20261102.4061, and ~/.t3/userdata/server-runtime.json records serverVersion 0.1.7-nightly.20261102.4061. They match exactly, so on this machine the guard allows pairing.

Not verified in a real window: the environment switch teardown, Cancel during a local pairing, and the address-move reconnect are app wiring. They are covered by review and build only, not by a runtime pass.

Claude Opus 5.5, Claude Code (factory worker W13b).

…'s exact version

t3 pair opens and migrates the server's database, so a newer CLI could migrate a live
install. Discovery now probes each recorded server and skips one that does not answer,
a relative T3CODE_HOME is resolved once against the launch directory, and the CLI runs
in its own process group, killed on timeout or cancel.
…tead of retrying

HTTP 426 from /ws now maps to the unsupported state, not a transient failure.
…disk

Edits go to the background writer, which re-reads environments.json and applies them,
so a second app instance's entries survive. Adds relocate for a server's new address.
… stops pairing

The terminal drawer, git store and usage page now follow a connection id, so a switch
tears down the feeds that kept the old client open. Cancel and Disconnect abort the
pairing in flight (and t3 pair's process group); a late result is ignored. A saved
local pairing follows the server to its new address, and environment saves go to the
background writer as edits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant