Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(mobile): reconnect environments immediately on resume #4878

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/4878/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Returning to T3 Code Mobile after using another app could leave every suspended environment waiting on a socket probe and retry backoff, making multi-environment reconnects feel sequential.

This change gives mobile resume an explicit fast path:

  • brief interruptions immediately probe existing sessions and refresh shell/thread subscriptions
  • meaningful background suspensions replace stale session leases so environments reconnect in parallel
  • foreground activation interrupts any in-flight probe or retry delay and resets the retry ladder
  • a reconnect request received during an active probe is retained and honored after the probe finishes

The branch is rebased onto current main, including #4882. That PR improves mobile action/feed responsiveness but does not overlap the connection runtime. After comparing #4885, this PR adopts its useful retry-backoff reset while keeping the existing in-memory token catalog and relay synchronization model; migrating persisted tokens or widening the relay critical section would add failure surface without improving the normal foreground path.

Verification

  • 58 focused client-runtime/mobile tests
  • @t3tools/client-runtime typecheck
  • @t3tools/mobile typecheck
  • targeted client-runtime lint
  • iOS Simulator: two connected environments plus five offline environments, backgrounded for 11 seconds, then resumed from the app icon; connected environments stayed available while only the offline environments retried

iOS resume verification

Watch the full verification clip (the middle background interval is accelerated).

Made with GPT-5.6 Sol in the Codex harness through T3 Code.

Note

Reconnect mobile environments immediately on resume after long background suspension

  • Adds mobileApplicationActiveWakeup in app-state-wakeups.ts to classify resume events as either application-active-probe (short interruption, <10s) or application-active-reconnect (long suspension, ≥10s).
  • On application-active-reconnect, the connection supervisor resets the retry backoff ladder and immediately replaces the session rather than probing the existing one.
  • On application-active-probe, the supervisor runs a liveness probe with a 3s timeout (vs 15s normally); shell and thread state resubscribe on probe but not on reconnect.
  • Bearer descriptor caching (10s TTL) and a 3s DPoP socket ticket timeout are added to the authorization service to reduce reconnect latency.
  • Behavioral Change: application-active wakeup is split into two distinct kinds; any code relying on application-active alone will not receive mobile resume events.
Macroscope summarized e279787.

Note

Medium Risk Changes core connection supervisor behavior, mobile wakeup semantics, and remote auth caching/timeouts; broad test coverage but affects reconnect and token paths for all mobile environments.

Overview Mobile resume no longer treats every foreground return like a single application-active probe. Short background gaps emit application-active-probe (3s health check, shell/thread resubscribe). ≥10s in background emits application-active-reconnect, which replaces the session immediately and resets the retry ladder instead of waiting on probes or backoff.

The connection supervisor honors application-active-reconnect during setup, while connected, and during an in-flight probe (probe is interrupted). Foreground activation also resets backoff when offline, blocked, or waiting to retry.

Remote authorization caches validated bearer descriptors for 10s (fewer descriptor fetches; fresh websocket tickets each connect). Cached DPoP endpoint use now uses a 3s websocket-ticket timeout and refreshes after the first transient socket failure (replacing a two-failure threshold).

Shell and thread sync only resubscribe on probe-style wakeups, not on reconnect (new session already drives sync).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e27978741cbcf507fc96cc0fe909da8210b6420c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: bf9ac669-73cb-4a31-9167-84407a0b91ff

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/62e242f9409872aff99e13cf4e34b44e753ec248/packages/client-runtime/src/connection/supervisor.ts#L445

      During an application-active-probe health check, monitorConnectedLease swallows any subsequent Wakeup signal — including application-active-reconnect — because the inner race loop at lines 432–460 consumes signals via Queue.take(signals) and drops them on the floor for the Wakeup case. A long-background resume arriving while the probe is still in progress is silently discarded, so the stale lease is never replaced and the supervisor stays blocked on the earlier probe instead of reconnecting immediately. Consider propagating Wakeup signals (or at least application-active-reconnect) out of the inner loop so they interrupt the probe the same way DisconnectRequested and RetryRequested do.

      ✅ Resolved in 029ac5bbae6229345d93712d8bef5d048d811e9e

    4. [gpt-5.6-sol] RESPONDING ON BEHALF OF THEO


      Fixed in 029ac5bba. A reconnect or relay credential wakeup now interrupts the in-flight probe and returns to the supervisor loop immediately. I added a regression test that starts a stalled mobile probe, delivers the long-resume reconnect signal, and verifies generation 2 connects without waiting for the probe timeout.

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

      Approvability

      Verdict: Needs human review

      This PR introduces meaningful runtime behavior changes to mobile connection handling, including new wakeup types that control session replacement vs probing, modified retry ladder logic, and changed authorization caching strategy. While well-tested, the scope of connection infrastructure changes warrants human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/370fef8ee9de80c617794e516bd62d4e53aeda05/packages/client-runtime/src/authorization/service.ts#L77

      authorizeBearer caches the environment descriptor indefinitely and reuses it on subsequent calls whenever the expectedEnvironmentId and httpBaseUrl match. If that URL is later reassigned or reconfigured to route to a different environment, authorizeBearer skips fetchDescriptor and therefore skips the environment-mismatch check — it returns an AuthorizedRemoteEnvironment with the old cached environmentId and label while obtaining a WebSocket ticket from the new endpoint. The previous implementation fetched the descriptor on every call, so this cache bypasses the mismatch detection. Consider invalidating the cached descriptor after a TTL or adding a mechanism to detect endpoint reassignment.

      ✅ Resolved in e75ef86d0367c7c7be81294a649ede8a90132b89

    7. [gpt-5.6-sol] RESPONDING ON BEHALF OF THEO


      Fixed in e75ef86d0. Bearer descriptors now expire after the same 10-second interval that separates a short mobile interruption from a full reconnect. Once expired, authorization fetches the descriptor again and repeats the environment-ID mismatch guard. I added a regression test that reassigns the same URL after expiry and verifies authorization is blocked before a websocket ticket is requested.

    8. Cursor Bugbot has reviewed your changes using high 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 7b02afac3fcd1c0c5d8392259146a87f15973742. Configure [here](https://www.cursor.com/dashboard/bugbot).

Sign in to join this conversation.