Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(ssh): pair reused servers with their own CLI version #17550

Closedvoltcrash(GitHub profile, opens in a new tab)wants to merge 0 commits intomain fromrefs/pull/17550/headopened View on GitHub

SSH reconnect can reuse an older remote server while the desktop-pinned CLI mints a pairing grant the server cannot decode. Read the running server version through the existing HTTP forward and use that release CLI to issue the grant. Discovery failures stop pairing; development Node-script runners keep their configured runner.

Keep the pairing runner in pair-t3.sh so version selection cannot rewrite the launch runner or trigger a later restart. Fixes #16984.

Verification:

  • Focused tunnel suite: 39 passed (34 current-main cases plus 5 retained PR cases, reduced from 9 additions). The original PR had 29 cases before main added coverage. The archive regression fails against exact main on the desktop-version credential instead of the running-server-version credential.
  • SSH package typecheck, targeted lint, formatting and whitespace checks pass.
  • Current-head production-manager before/after proof: main returns HTTP 500 and overwrites the launch runner; ac23054c56 pairs twice with HTTP 200, preserving launch-script bytes and the server PID. This uses a controlled SSH command adapter with real HTTP, generated shell execution and verified Linux release binaries.
  • Independent full-diff Codex and Claude reviews: one round, no actionable findings on ac23054c56.
  • Linux x64 release proof, both archives checked against their release SHA256SUMS: October 7 CLI → unchanged October 4 server returns HTTP 500 access_token_issuance_failed; matching October 4 CLI → same server PID returns HTTP 200, and /api/auth/session confirms authentication. This used an isolated temporary home and direct loopback HTTP; it is separate from the SSH manager selection tests. The temporary server and state were cleaned up.

Pairing requires an available release archive matching the reported version; source/fork servers without a matching published archive fail rather than fall back to the desktop CLI. The first pairing may download that archive.

The remaining human gate is authentication-sensitive maintainer review, as required by Macroscope. Electron reconnect, real SSH/Tailscale transport and remote active-agent preservation were not exercised end to end. macOS, Windows, iOS and Android were not verified on this headless Linux machine. This is a backend pairing change; screenshots are not applicable.

Credit to @voltcrash for the original fix in #17550. The takeover preserves contributor commits and merges current main without rewriting history.

Implementation/integration: Codex gpt-6.1-sol (high) in T3 Code; tests: Codex gpt-6-astra (high); adversarial reviews: Codex gpt-6-sol (high) and Claude claude-opus-5-5 (high).

Modernized against upstream 15fe28327278. Preserved upstream’s diagnostic-tail test and private script helpers, and retained the HostProcess/FileSystem services required by the pairing fixture. All 13 selected tests and five affected package typechecks passed. vp run check:changed upstream/main --concurrency 1 passed. Existing runtime evidence above remains historical; no new live provider or SSH session was run.

Modernized with GPT-6.1 Sol in the Codex harness.

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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Note

      Reviews paused

      It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

      • Last reviewed commit: 115982f603343966a88941921db420a47bf877df
      • Latest commit, not reviewed: 9cd00d9da07d19ab22ea3202a816c03295faf61f

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to trigger a single review.

      Use the checkboxes below for quick actions:

      • Resume reviews
      • Trigger review

      No actionable comments were generated in the recent review.

      Walkthrough

      SSH pairing selects an archive runner using the running remote server’s version and writes its script to a separate file. Node-script runners bypass version discovery. Tests cover repeated pairing and discovery failures.

      Changes: SSH pairing runner selection

      Layer / File(s)Summary
      Resolve and use the pairing runner
      packages/ssh/src/tunnel.ts, packages/ssh/src/tunnel.test.ts
      Before issuing a pairing token, archive runners are resolved from the remote server’s environment descriptor. Discovery or version validation failures produce SshPairingError. Node-script runners bypass discovery. Pairing writes to pair-t3.sh; tests cover repeated pairing and discovery failures.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant PairingManager
        participant RemoteServer
        participant PairingTokenAPI
        PairingManager->>RemoteServer: Request environment descriptor for archive runner
        RemoteServer-->>PairingManager: Return server version
        PairingManager->>PairingTokenAPI: Issue token with resolved runner

      Possibly related issues

      • pingdotgg/t3code#24095 — The issue reports pairing failure when a newer client uses the wrong CLI for an older adopted server. This change selects the archive runner version reported by the running server; the separate launcher-state problem remains outside this change.

      Suggested reviewers: tris203

      Merge Risk: Minimal · previous review 11598

      Pairing selects a matching CLI for reused release servers. No actionable merge-blocking issue was identified.

      Security architecture risk: Low · up to ac230

      The change preserves the server’s launch configuration while selecting a compatible pairing release. Version validation and existing access controls limit the additional authority, but recovery after interrupted pairing has not been established across older releases.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • observed — The selected pairing CLI executes as the SSH account, uses its runtime cache, and creates pairing state under that account’s $HOME/.t3. These privileges and persistence locations predate the PR; the introduced authority is selection of the archive version used for pairing.

      Security Findings and Attack Paths

      • inferred — A service controlling the forwarded descriptor can request a different published release version. The reviewed flow constrains this to directory-safe version syntax and the configured release source. No vulnerable selectable release or resulting privilege escalation was established, so this authority change is not retained as a vulnerability finding.

      Trust Boundaries and Controls

      • observed — SSH associates descriptor access with the selected host and remote loopback port, but the response has no additional binding to a process or environment identity. Exact-version validation and shell quoting constrain its use; newly downloaded archives are checked against SHA256SUMS from the configured release source. Existing ready-cache entries are reused.

      Resilience and Maintainability Implications

      • observed — Discovery fails before pairing execution, and launch-state isolation improves failure containment. After issuance starts, the wrapper checks command output and credential shape but contains no compensating revoke transaction. Whether an interrupted release CLI can leave a committed, unreceived grant remains unverified; that wrapper limitation predates this PR.
      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: pairing reused SSH servers with their own CLI version.
      Description checkPassedThe description explains the problem, implementation, scope, limitations, linked issue, and detailed verification results. It does not use the template headings exactly, and maintainer approval remain…
      Linked Issues checkPassedIssue #16984 is closed and supplies historical context only. No active directly linked issue adds coding requirements. The reviewed changes still implement the stated historical fix: tunnel.ts disco…
      Out of Scope Changes checkPassedThe reviewed changes stay within SSH pairing recovery. Production code changes version discovery, pairing-runner selection, and pairing-script isolation in packages/ssh/src/tunnel.ts. Test changes c…
      Full details: Description check

      Explanation

      The description explains the problem, implementation, scope, limitations, linked issue, and detailed verification results. It does not use the template headings exactly, and maintainer approval remains pending, but the required information is mostly present.

      Full details: Linked Issues check

      Explanation

      Issue #16984 is closed and supplies historical context only. No active directly linked issue adds coding requirements. The reviewed changes still implement the stated historical fix: tunnel.ts discovers the running server version through the forwarded HTTP endpoint, selects that release for archive pairing, preserves the configured Node-script runner, and keeps pairing in pair-t3.sh. Focused tests cover successful reuse and discovery failures.

      Full details: Out of Scope Changes check

      Explanation

      The reviewed changes stay within SSH pairing recovery. Production code changes version discovery, pairing-runner selection, and pairing-script isolation in packages/ssh/src/tunnel.ts. Test changes cover runner preservation, repeated pairing, version discovery, and failure behavior. No unrelated UI, provider, protocol, or server-lifecycle changes are shown.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between ac23054c565db5f2e76ad62c112d453ddf61bf5d and 115982f603343966a88941921db420a47bf877df.

      Files selected for processing: 2

      • packages/ssh/src/tunnel.test.ts
      • packages/ssh/src/tunnel.ts

      Limit details: You’ve used all 10 included reviews currently available.

    3. juliusmarminge added labelsmacroscope-review

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 9cd00d9

      Macroscope's review found this PR approvable — SSH pairing now uses the running server’s CLI version and keeps its pairing script separate from the server launcher. Version validation, bounded discovery through the existing SSH tunnel, and existing archive verification limit the change’s exposure.

      Notes:

      • All code in this push has already been reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. juliusmarminge assignedjuliusmarminge

    6. Taking over this one as maintainer for batch ssh-relay-remote-09. I will resolve current-main conflicts, reduce the tests to the pairing regression and failure behavior, independently rebuild the fix, and run both adversarial reviews. Additive commits will stay on this PR; no merge.

    7. Here's a real-world case for this batch. The desktop was 0.1.0 and the server was 0.0.45, on Ubuntu 24.04.

      • The 0.1.0 runner minted the grant into statev2.sqlite. The 0.0.45 server reads state.sqlite, so every /oauth/token returned invalid_credential and every reconnect failed with [ssh_http:401]. This PR fixes that side.
      • Nobody started that server by hand. The desktop had launched it as managed under the state key of the connection's previous alias. After the alias changed, the new key adopted it as external, so even with this PR it would have stayed on 0.0.45 forever. #21892 covers that part: the launcher takes over a server that another state key recorded as managed, so the existing runner-changed update replaces it. It changes the launch script, not the pairing script.

      Full diagnosis, evidence, and recovery steps: https://github.com/pingdotgg/t3code/issues/21681#issuecomment-6275544874

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

    8. tanstack-source added labelsbug

    9. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Closing. This PR has been open for more than 3 weeks, and main has moved a long way since then. If the change still matters, open a fresh PR from current main.

Sign in to join this conversation.