Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(ssh): editing a connection no longer strands its remote server on an old version #21892

ClosedGooder24(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/21892/headopened View on GitHub

Problem

The SSH launcher records which server it manages under ~/.t3/ssh-launch/<state key>. The key is a hash of the connection's alias, host, user, and port. Editing any of those changes the key. The next launch then finds the server it had launched still running from the default home, adopts it as external, and stops managing it. App updates never replace an external server. Once the app updates, pairing runs through the newer runner against that older server, and the user sees Could not prepare the SSH environment … [ssh_http:401] … bootstrap-bearer-session on every reconnect.

What I saw on a real host: a server launched by 0.0.45 kept running after the connection's alias was changed. When the desktop moved to 0.1.0, the 0.1.0 CLI issued pairing credentials into statev2.sqlite, while the 0.0.45 server authenticated against state.sqlite. Every /oauth/token call returned invalid_credential. #21681 reports the same 401 with a hand-started older server. #17550 fixes the pairing side by pairing with the server's own CLI version. This PR covers the other side: a server T3 launched stays managed after a connection edit, so updates still replace it. The two change different scripts in tunnel.ts.

Change

When the default runtime file names a live server that another state directory recorded as managed, the launcher takes it over instead of adopting it as external. The new key records the PID, port, and managed, and the previous directory gives up its pid and managed files. The server keeps running when the previous key's run-t3.sh matches the current runner. When it differs, the existing update path replaces the server. A server nobody launched is still adopted as external, as before.

Scope and approval

This is a small, focused fix for an obvious bug: a server T3 launched should not stop being managed because the connection was renamed. The change is one branch in the launch script plus one test. It changes no contract, client, or documented behavior. docs/user/remote-access.md still holds: removing a connection stops a server T3 Code launched.

Verification

  • New test launch script > keeps managing its server after the connection's state key changes:
    • It launches under one state key, then launches under another key with the same runner. The server stays running and is now managed under the new key.
    • It then launches back under the first key with the other key's runner marked as outdated. The server is replaced.
    • Without the tunnel.ts change the test fails: the second launch returns serverKind: "external".
  • vp test run packages/ssh/src/tunnel.test.ts: 35/35 pass on Debian 13, where sh is dash.
  • tsc-rs --noEmit in packages/ssh, vp lint, and vp fmt --check on both files: clean.
  • On the affected host, the old runner (T3_ARCHIVE_VERSION='0.0.45') and the new one ('0.1.0') differ under cmp, so this change would have replaced the stale server. I recovered that host by hand before writing the fix. I did not run the patched launcher against it.
  • Not checked: a macOS remote. The script uses only POSIX sh, cat, and cmp, and cmp is already required.

Written by Claude Opus 5.5 in Claude Code, driven from T3 Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at ed54cbb

      Macroscope's review found this PR approvable — This is a small, focused SSH launcher bug fix that transfers management of an already-running server when a connection’s state key changes, while preserving runner replacement behavior. A regression test covers both reuse and update cases, with no product-default or static-analysis policy changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: bfc1e8a9-0114-4ca3-b012-572f2c33bd51
      📥 Commits

      Reviewing files that changed from the base of the PR and between 4ac8fa41625c5276bcd36dc18c60f68391c8fd3e and ed54cbb9eb6c5c800ef66d9f682f8728c8739513.

      📒 Files selected for processing: 2
      • packages/ssh/src/tunnel.test.ts
      • packages/ssh/src/tunnel.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

      📝 Walkthrough

      The SSH launcher now finds a managed server recorded under another state key, adopts it under the current key, and removes the previous directory’s PID and managed markers. A test covers state transfer and server replacement when the saved runner changes.

      Changes: SSH launcher state adoption

      Layer / File(s)Summary
      Find and adopt a managed server
      packages/ssh/src/tunnel.ts, packages/ssh/src/tunnel.test.ts
      The launcher finds another managed state directory with the default runtime PID, compares its saved runner with the current runner, and transfers the PID and managed markers to the current directory. The test checks state transfer and replacement when the runner changes.

      Priority: ⬇️ Low

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: 🔵 Low · up to ed54c

      In a rare stale-PID collision, the launcher could replace an independently started server. The change remains mergeable with owner awareness.

      Security architecture risk: 🟡 Moderate · up to ed54c

      The change restores updates after a connection is renamed, but stale process IDs and overlapping ownership transfers can give a connection authority to stop the wrong process or another connection’s server. Impact is bounded by the remote SSH account’s permissions.

      Retained concerns

      • Medium · reliability · inferred: The new lookup promotes another directory’s historical managed marker and matching PID into current stop/update authority without verifying process generation. After a managed server exits and its PID is reused, a different live process can be claimed as managed. A runner mismatch then signals that PID before checking readiness. Previously, a fresh connection key followed external adoption rather than acquiring this authority. This is a conditional failure-containment regression within the SSH account’s signaling permissions, not an established privilege-escalation path.
      • Medium · reliability · inferred: Ownership transfer is not atomic or serialized across connection keys. Interruption after writing the new managed record but before removing the old record leaves two owners; concurrent adopters can also select the same previous owner. The existing lock includes the alias and therefore does not protect this shared transition. Either surviving record can authorize stopping the shared server, defeating the transfer’s intended exclusive ownership and connection-level failure containment.
      Security review details

      Security Blast Radius

      • inferred — The newly expanded authority spans sibling connection records under the same remote home. Process termination remains constrained by the SSH account’s operating-system permissions; broader tenant, host, or credential authority was not established.

      Security Findings and Attack Paths

      • inferred — The supported failure path is stale lifecycle state, PID reuse, cross-key managed classification, and process signaling on runner mismatch or later stop. The mismatch path does not require a successful readiness response before signaling. An attacker who can already rewrite these account-local files is not shown to gain additional privileges through this change.

      Trust Boundaries and Controls

      • observed — Loopback-origin validation, PID-liveness checks, and zombie detection reject several invalid or dead-runtime cases. A default-runtime process without a matching managed sibling record still follows external adoption. These controls do not establish process-generation identity for the new managed transfer.

      Resilience and Maintainability Implications

      • inferred — Duplicate management records are consequential because the stop script treats any non-external PID record as stop authority. Recovery therefore needs to preserve exclusive ownership, not merely ensure that one launch returns successfully.

      Hardening Proposals

      • proposed — Bind management authority to a verifiable process-generation identity and perform ownership transfer under a shared remote lock with recoverable state. Validate stale-PID, interrupted-transfer, and concurrent-adopter behavior before relying on exclusive stop authority.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary SSH fix. It uses a conventional commit format and matches the reported behavior.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe pull request description covers all required sections. It clearly explains the problem, the implementation, scope justification, approval rationale, focused verification, observed results, unteste…
      Full details: Description check

      Explanation

      The pull request description covers all required sections. It clearly explains the problem, the implementation, scope justification, approval rationale, focused verification, observed results, untested environments, and agent attribution.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.