Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(client-runtime): decide learned routes and session reuse in one place #20445

Mergedjuliusmarmingemerged 3 commits intomain fromrefs/pull/20445/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

What changed

  • Learned routes and plain HTTP. mergeLearnedRoutes in packages/client-runtime/src/connection/routes.ts only learns a plain-HTTP address outside the tailnet when the paired credential it borrows was itself paired over plain HTTP to a LAN or public address. Relay credentials are unchanged.
  • SSH session reuse. The SSH route's bearer token is saved in the connection catalog (SshConnectionRegistration carries it, storageDocument stores it, and removing the route drops it). The resolver's SSH broker passes the saved token to SshEnvironmentGateway.prepare and saves the token that comes back. The desktop gateway (prepareDesktopSshEnvironment in apps/web/src/connection/platform.ts) brings up the tunnel, checks the host's environment id, then checks the saved session through the existing fetchSshSessionState IPC. It reuses the session if it is valid and holds every standard client scope. Otherwise it pairs again through the add-environment path.
  • Docs. docs/user/remote-access.md describes one session per desktop per SSH route and how to revoke unused ones, including the CLI. docs/internals/remote.md notes the plain-HTTP rule for learned routes.

The server and packages/ssh are unchanged.

Behavior changes

  • A token paired over HTTPS, loopback, or the tailnet no longer gets copied to a learned plain-HTTP LAN or public address. Tailnet plain-HTTP addresses are still learned.
  • SSH reconnects and app restarts reuse one host session per desktop instead of creating a new 30-day session on every connect. Adding an environment and its first connect share that session.
  • If the saved session is revoked, expired, or missing a standard scope, the next connect pairs once and saves the new token. Errors from the session check (network, 5xx) fail the attempt so the supervisor retries. They never pair.
  • If a saved SSH route now reaches a different environment, the connect fails before pairing or sending the saved token.
  • Older catalogs have no saved SSH token, so each desktop pairs once on its first connect after updating.

Testing

  • tsc-rs --noEmit in packages/client-runtime and apps/web: both pass.
  • vp test run src/connection in packages/client-runtime: 9 files, 176 tests passed.
  • vp test run --project unit src/connection/platform.test.ts in apps/web: 18 tests passed.
  • The full suite was not run locally. CI covers it.

🤖 Generated with Claude Code

Closes #20288


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

    2. juliusmarminge added labelsmacroscope-review

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

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR changes production connection and authentication behavior by persisting/reusing SSH bearer sessions and restricting how credentials are propagated to learned HTTP routes. The cross-component, security-sensitive runtime impact warrants human review beyond a routine refactor.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. 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: Team
      • Run ID: b4debc49-9da6-4ae7-92f4-7f7a75e696c8
      📥 Commits

      Reviewing files that changed from the base of the PR and between f6e4fd48cf3221e6a2adf7a69a57e94ef5a7fc5e and 0b6daa5b19646c581c81e71d5278129322046556.

      📒 Files selected for processing: 1
      • apps/web/src/connection/platform.ts

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

      📝 Walkthrough

      SSH registrations now persist paired bearer credentials. Reconnection reuses a saved token when the host accepts it with standard scopes, or pairs again otherwise. Learned plain-HTTP routes use rules based on the saved route for the shared credential.

      Changes: SSH credential reuse and learned routes

      Layer / File(s)Summary
      Persist paired SSH credentials
      packages/client-runtime/src/connection/catalog.ts, packages/client-runtime/src/connection/onboarding.ts, packages/client-runtime/src/connection/onboarding.test.ts, packages/client-runtime/src/platform/storageDocument.ts, packages/client-runtime/src/platform/storageDocument.test.ts, packages/client-runtime/src/connection/registry.test.ts
      SSH registrations now include the paired bearer credential. Catalog storage saves it with the SSH profile and removes it when the environment is removed. Registration and storage tests cover the credential.
      Reuse credentials during SSH preparation
      packages/client-runtime/src/platform/capabilities.ts, packages/client-runtime/src/connection/resolver.ts, packages/client-runtime/src/connection/resolver.test.ts, apps/web/src/connection/platform.ts, apps/web/src/connection/platform.test.ts, docs/user/remote-access.md
      The SSH broker passes a saved token to preparation and stores a changed returned token. Desktop preparation checks the environment ID and session scopes before reuse, and pairs again when needed. Tests cover reuse, re-pairing, and environment mismatch. The remote-access guide describes session reuse and revocation.
      Restrict learned plain-HTTP routes
      packages/client-runtime/src/connection/routes.ts, packages/client-runtime/src/connection/routes.test.ts, docs/internals/remote.md
      Learned plain-HTTP endpoints are accepted only when the insecure-route setting is enabled and the endpoint is tailnet or the shared credential’s saved route qualifies. Tests and remote architecture documentation describe the route behavior.

      Generated router metadata

      Layer / File(s)Summary
      Mark generated route tree
      apps/web/src/routeTree.gen.ts
      The file now identifies TanStack Router as its generator and warns that manual edits are overwritten.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant SSHBroker
        participant CredentialStore
        participant SshEnvironmentGateway
        participant SSHHost
        SSHBroker->>CredentialStore: Read saved bearer credential
        SSHBroker->>SshEnvironmentGateway: Prepare with saved token
        SshEnvironmentGateway->>SSHHost: Check environment and token session
        SSHHost-->>SshEnvironmentGateway: Return authentication and scopes
        SshEnvironmentGateway-->>SSHBroker: Return reused or newly paired token
        SSHBroker->>CredentialStore: Save changed bearer credential

      Suggested reviewers: maria-rcks

      Merge Risk: ⚪ Minimal · up to 0b6da

      The change reuses saved SSH sessions and restricts learned plain-HTTP routes. No concrete merge-blocking risk was identified in the supplied material.

      Pre-merge checks: Passed 2 · Failed 2
      Failed Failed checks: 2 warnings
      Check nameStatusExplanationResolution
      Description checkWarningThe description explains the changes, behavior, testing, and linked issue. It does not use the required Problem, Change, Scope and approval, and Verification headings. It also does not document mainta…Add the required sections: Problem, Change, Scope and approval, and Verification. Include the triaged issue or explicit maintainer approval with its approval comment, or explain why this focused change qualifies for an exemption. Preserve t…
      Out of Scope Changes checkWarning[Issue #20288] The learned-route changes in packages/client-runtime/src/connection/routes.ts and routes.test.ts change plain-HTTP credential propagation. They do not address stale SSH sessions. `d…Remove the learned-route implementation, its tests, and its documentation from this PR, and remove the unrelated generated header change. Alternatively, link the learned-route work to a separate active issue and split it into a separate pul…
      Passed Passed checks: 2 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly identifies both primary changes: learned-route decisions and SSH session reuse. It is concise, specific, and uses a valid conventional commit format.
      Linked Issues checkPassed[Issue #20288] The PR stores the SSH bearer token in the connection catalog and credential store. resolver.ts passes the saved token to ssh.prepare and saves a replacement token. platform.ts che…
      Full details: Linked Issues check

      Explanation

      [Issue #20288] The PR stores the SSH bearer token in the connection catalog and credential store. resolver.ts passes the saved token to ssh.prepare and saves a replacement token. platform.ts checks the environment ID before token use, reuses a session only when it is authenticated and has all AuthStandardClientScopes, and pairs again when the session is invalid or incomplete. The reported tests cover reuse, re-pairing, and environment mismatch behavior.

      Full details: Description check

      Explanation

      The description explains the changes, behavior, testing, and linked issue. It does not use the required Problem, Change, Scope and approval, and Verification headings. It also does not document maintainer approval or explain why the change qualifies without prior approval.

      Resolution

      Add the required sections: Problem, Change, Scope and approval, and Verification. Include the triaged issue or explicit maintainer approval with its approval comment, or explain why this focused change qualifies for an exemption. Preserve the existing test commands and results under Verification.

      Full details: Out of Scope Changes check

      Explanation

      [Issue #20288] The learned-route changes in packages/client-runtime/src/connection/routes.ts and routes.test.ts change plain-HTTP credential propagation. They do not address stale SSH sessions. docs/internals/remote.md documents that unrelated behavior. The generated header change in apps/web/src/routeTree.gen.ts also has no connection to SSH session reuse. The SSH documentation and related SSH tests remain in scope.

      Resolution

      Remove the learned-route implementation, its tests, and its documentation from this PR, and remove the unrelated generated header change. Alternatively, link the learned-route work to a separate active issue and split it into a separate pull request.

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Usage-based review receipt

      Note

      This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

      Comment `@coderabbitai help` to get the list of available commands.
    5. @@ -252,9 +251,14 @@
      252251 ];
      253252 }
      254253 if (url === null || !reported.has(normalized(url)) || known.has(normalized(url))) return [];
      254+ if (sendsTokenInClear(saved, route, tailscaleOrigins.has(normalized(url)))) return [];
      255255 known.add(normalized(url));
      256256 return [withNetwork(route, tailscaleOrigins.has(normalized(url)))];
      257257 });
      258258 let next: ReadonlyArray<ConnectionRoute> = kept;
      259259 for (const url of reported.values()) {
      260260 if (known.has(url.origin)) continue;
      261+ if (
      262+ url.protocol === "http:" &&
      263+ sharedCredential !== undefined &&
      264+ !tailscaleOrigins.has(url.origin) &&
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium connection/routes.ts:264

      A reported *.ts.net or Tailscale IPv6 endpoint without kind: "tailnet" is dropped for an HTTPS-paired credential, and a saved learned route without profile.network is filtered out by usableRoutes. Both checks rely only on explicit tailnet markers, so they reject hosts that connectionRouteKind recognizes as tailnet; include isTailnetHost recognition in both checks.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @packages/client-runtime/src/connection/routes.ts around line 264:
      
      A reported `*.ts.net` or Tailscale IPv6 endpoint without `kind: "tailnet"` is dropped for an HTTPS-paired credential, and a saved learned route without `profile.network` is filtered out by `usableRoutes`. Both checks rely only on explicit tailnet markers, so they reject hosts that `connectionRouteKind` recognizes as tailnet; include `isTailnetHost` recognition in both checks.
    6. juliusmarminge merged thisc9b8f21

    7. juliusmarminge closed this

Sign in to join this conversation.