Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(connect): refresh HTTP credentials without reconnecting #9594

Mergedjuliusmarmingemerged 8 commits intomain fromrefs/pull/9594/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Relay HTTP requests used the DPoP token captured when the WebSocket opened. #9582 renewed it by preparing a replacement socket. That still tied HTTP credentials to the transport lifecycle and left the misleading permissions denial described in #8326.

PR diffs, session probes, shell snapshots, and thread history now resolve current credentials and the endpoint before each request. Renewal is shared per environment, bounded, and tied to the signed-in account. Credential rejection gets one retry with a fresh proof, including HTTP 200 authenticated:false from session probes. Permission, network, and Cloudflare 530 failures do not trigger an authentication retry.

HTTP renewal no longer replaces a healthy socket. Expired-but-connected sessions stay visible in connection management without extending credential validity. Logout and environment removal cannot resurrect cached credentials; persisted tokens cannot cross accounts. Cookie, bearer, and signed-asset paths retain their existing behavior.

Before/after evidence

This is a nonvisual credential-lifecycle change, so screenshots are not applicable. The baseline run used 82f64cd8. The relevant runtime, auth/session code, tests, and dependencies are unchanged at the current review base 4ade3651, so that evidence remains valid. Head tests were rerun at 010646ec.

CaseBaseHead
Renewal succeedsReplacement socket becomes ready, old socket closes, generation advancesHTTP uses the renewed credential; socket and generation stay unchanged
Renewal fails through expiryHealthy socket closes and supervisor enters backoffHTTP request fails; the same socket remains connected

The baseline supervisor tests exercise replacement handoff and expiry teardown. The head regression advances through expiry, renews through the real authorization service, reads the session successfully, then simulates a later renewal timeout. Only one WebSocket ticket is issued; the socket stays open at generation 1.

Verification

  • Baseline: 51 existing tests passed across supervisor and SessionStore.
  • Current head: 200 tests passed across 16 focused suites, including retry/proof handling, concurrent renewal, logout/removal races, account-bound persistence, expired-session visibility, and web/mobile settings and storage.
  • Current-head CI passes: Check, including typecheck and the desktop build; Test; all three server shards; Rust; and Release Smoke. The Ubuntu mirror blocker is resolved.
  • Fresh whole-PR audit found no concrete defects or unnecessary tests. All three earlier review findings remain fixed and their threads are resolved.
  • The 30-file credential-refresh patch is unchanged from the previous preparation. The update only incorporates changes already landed on main. One PR, no stack, no new tests or scope expansion.

Review checks: Bugbot and Macroscope Effect Service Conventions pass. Macroscope Correctness and Approvability are skipped, as are the native static-analysis and preview jobs. CodeRabbit automatic reviews are disabled. The existing Approvability note calls for human review of the authentication changes; it is not an automated approval. No required approvals or active change requests are outstanding.

The first HTTP request near expiry can wait for renewal. This does not repair a separate upstream tunnel outage returning HTTP 530.

Implemented with vega-alpha via the Codex harness.


Note

High Risk Changes authentication, DPoP renewal, and session listing semantics across client runtime and server; regressions could break remote access or leave stale credentials visible.

Overview Relay HTTP no longer relies on the DPoP token captured at WebSocket connect, and the connection supervisor stops tearing down healthy relay sockets when that credential expires. Instead, PR diffs, session probes, shell/thread snapshots, and similar calls go through executeAuthenticatedEnvironmentHttpRequest, which asks authorizeDpopHttp for current credentials and endpoint, signs a fresh proof per request, and retries once after invalid_credential (including session probes that return authenticated: false).

RemoteEnvironmentAuthorization now owns relay bootstrap (clerk token, device id), per-environment token cache with optional accountId, shared in-flight renewal with timeouts, and cleanup on logout or account change. authorizeDpop no longer takes a caller-supplied bootstrap; the resolver only delegates. Persisted tokens use putRemoteDpopTokenInCatalog so writes are ignored if the relay environment was removed.

On the server, SessionStore / listActive keep unrevoked, still-connected sessions visible after DB expiry until the last socket disconnects (and emit clientRemoved then). Web and mobile CloudSession expose identity for account-aware renewal. Docs describe HTTP renewal vs transport retry separately.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 010646ec28e7e126f5d35d09e05f809205b413f0. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Refresh DPoP HTTP credentials at request time and stop replacing active relay connections on auth expiry

  • Adds executeAuthenticatedEnvironmentHttpRequest in environmentHttpAuth.ts as a shared helper for relay HTTP requests. It resolves current DPoP authorization, builds headers at request time, and retries once after a 401, passing the rejected token to the renewal call.
  • Removes the supervisor's proactive relay-replacement loop in supervisor.ts. An active relay session now stays connected until socket closure or lease failure; DPoP expiry no longer triggers connection teardown or generation changes.
  • Moves relay bootstrapping into RemoteEnvironmentAuthorization in service.ts, which now exposes authorizeDpopHttp for HTTP-only authorization and internally manages token caching, shared renewals (30s timeout), account-aware cache validation, and rejected-token cleanup that preserves replacement tokens.
  • Updates SessionStore in SessionStore.ts to retain expired connected sessions in loadActiveSession and listActive until their final socket disconnects, and to emit clientRemoved on that final disconnect.
  • Migrates all relay HTTP callers (pull-request diff, session state, shell snapshot, thread snapshot) to the shared helper, passing an optional RemoteEnvironmentAuthorization from each loader layer.
  • Behavioral Change: expired-but-connected relay sessions now remain listed and active; RemoteDpopAccessToken gains an optional account field (schema-compatible); authorizeDpop no longer accepts a caller-supplied bootstrap and authorizeDpopHttp is a new method on RemoteEnvironmentAuthorization; putRemoteDpopTokenInCatalog ignores tokens without a registered relay target.
Macroscope summarized 010646e.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.8 KiB13.6 KiB−163 B (−1.2%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB+1 B (+0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.7 KiB6.6 KiB−164 B (−2.4%)7.8 KiB✅
      CodexLive turn WebSocket decoded58.5 KiB57.1 KiB−1.4 KiB (−2.4%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB−6 B (−0.0%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB+1 B (+0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB−7 B (−0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.9 KiB57.9 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: 4ade365 · PR result: 010646e · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR changes production authentication and connection lifecycle across the client runtime, web/mobile integration, and server session listings, including request-time DPoP renewal, account-bound persistence, retries, and removal of proactive socket replacement. The cross-cutting implementation includes authentication-sensitive code and substantial supervisor refactoring, so its runtime effects warrant human review.

      No code changes detected at 010646e. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged this363cde4

    5. juliusmarminge closed this

Sign in to join this conversation.