Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(connect): refresh authorization without disconnecting #9582

Mergedmaria-rcksmerged 4 commits intomain fromrefs/pull/9582/headmerged by maria-rcks View on GitHub

maria-rckscommented

Relay DPoP renewal previously discarded an otherwise healthy websocket once per token lifetime, causing visible hourly disconnects.

This now fully prepares and synchronizes a replacement websocket in its own child scope while the old connection remains authoritative. Once the replacement is ready, the supervisor publishes its matching HTTP authorization and RPC session, increments generation, then releases the old scope. Transient setup failures retry without changing public connection state, and the old lease is never retained past authorization expiry.

Verified with 57 focused connection tests, client-runtime typecheck, targeted lint, and formatting checks.

Implemented by gpt-5.6-sol in the Codex harness.


Note

Medium Risk Changes core relay connection lifecycle, authorization handoff, and observable generation/backoff behavior; mistakes could cause stale sessions, leaks, or unexpected disconnects, though coverage is strong in supervisor tests.

Overview Relay DPoP renewal no longer tears down the live websocket when the access token nears expiry. Instead, EnvironmentSupervisor prepares a replacement connection in a child scope (with progress hidden from public connecting state), keeps the current session authoritative until the replacement is ready, then atomically swaps session/prepared, bumps generation, and closes the old scope.

Replacement setup races completion against authorization expiry and a 15s establishment timeout, retries transient prepare failures while staying connected, and stops without handoff if the active token expires first—leading to reconnect/backoff rather than holding an expired lease.

Generation semantics change: supervisor generation advances only when a new active session is published (including handoff), not on every reconnect attempt; failed or interrupted attempts report the prior generation.

Tests were expanded to cover deferred handoff, timed-out replacement cleanup, and release when refresh cannot complete before expiry.

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

Note

Prepare replacement authorization in background and swap without disconnecting

Changes EnvironmentSupervisor connection lifecycle so a connected supervisor prepares a new DPoP lease in the background while keeping the active session.

  • connection.prepareReplacement races candidate connections against the active authorization expiry and the establishment timeout, retries transient failures with backoff, and closes unsuccessful candidates
  • connection.runAttempt installs a ready replacement atomically by updating the prepared connection, session, and generation before closing the previous scope; failed or timed-out replacements leave the active lease in place
  • connection.forkScopedTracedConnection forks a closeable child scope so candidate attempts can be independently interrupted or cleaned up
  • connection.waitForAuthorizationDeadline now accepts a caller-provided skew, allowing both refresh-window and exact-expiry waits
  • Supervisor retry coordinator now assigns the generation returned by each attempt outcome rather than precomputing the next generation
  • Behavioral Change: connection.establishConnection and connection.establishTracedConnection now suppress progress reporting for replacement candidates via a new flag; normal establishment paths are unchanged. Failed or interrupted attempt outcomes in connection.failureFromExit now carry the caller-supplied generation.
Macroscope summarized 94ddaec.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The production connection supervisor now performs concurrent DPoP authorization refreshes and session handoffs with new retry, timeout, and resource-lifecycle behavior. Because this materially changes an existing authorization-sensitive runtime path, human review is warranted.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3ee01d04af8f00ffc136f54f3db542402fc9fb26. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. maria-rcks merged this39abb9d

    5. maria-rcks closed this

Sign in to join this conversation.