perf(mobile): reconnect environments immediately on resume #4878
main fromrefs/pull/4878/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubReturning 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-runtimetypecheck@t3tools/mobiletypecheck- 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

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
mobileApplicationActiveWakeupin app-state-wakeups.ts to classify resume events as eitherapplication-active-probe(short interruption, <10s) orapplication-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-activewakeup is split into two distinct kinds; any code relying onapplication-activealone will not receive mobile resume events.
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
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
🟡 Medium
During an
application-active-probehealth check,monitorConnectedLeaseswallows any subsequentWakeupsignal — includingapplication-active-reconnect— because the inner race loop at lines 432–460 consumes signals viaQueue.take(signals)and drops them on the floor for theWakeupcase. 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 propagatingWakeupsignals (or at leastapplication-active-reconnect) out of the inner loop so they interrupt the probe the same wayDisconnectRequestedandRetryRequesteddo.✅ Resolved in 029ac5bbae6229345d93712d8bef5d048d811e9e
[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.
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).🟠 High
authorizeBearercaches the environment descriptor indefinitely and reuses it on subsequent calls whenever theexpectedEnvironmentIdandhttpBaseUrlmatch. If that URL is later reassigned or reconfigured to route to a different environment,authorizeBearerskipsfetchDescriptorand therefore skips the environment-mismatch check — it returns anAuthorizedRemoteEnvironmentwith the old cachedenvironmentIdandlabelwhile 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
[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.
- packages/client-runtime/src/connection/supervisor.ts line 410Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -402,4 +406,4 @@402406 yield* logManagedRelayAccountChange;403407 return;404408 }405- if (next.reason === "application-active") {409+ if (next.reason === "application-active-reconnect") {
🟡 Medium
connection/supervisor.ts:409When
application-active-reconnectinterruptsmonitorConnectedLease, the resultingInterruptedoutcome does not resetfailureCount, so a fresh reconnection attempt after a long background resume can inherit an inflated retry count and enter a long backoff (up to 16s) instead of starting fresh. ThewaitForRetrySignalpath already resetsfailureCountandpendingRetryon application activation, but this connected-lease interruption path does not. Consider resetting the retry state when this wakeup interrupts a connected lease, matching thewaitForRetrySignalbehavior.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/client-runtime/src/connection/supervisor.ts around line 409: When `application-active-reconnect` interrupts `monitorConnectedLease`, the resulting `Interrupted` outcome does not reset `failureCount`, so a fresh reconnection attempt after a long background resume can inherit an inflated retry count and enter a long backoff (up to 16s) instead of starting fresh. The `waitForRetrySignal` path already resets `failureCount` and `pendingRetry` on application activation, but this connected-lease interruption path does not. Consider resetting the retry state when this wakeup interrupts a connected lease, matching the `waitForRetrySignal` behavior.[gpt-5.6-sol] RESPONDING ON BEHALF OF THEO
Fixed in d878362d8. Long-resume interrupts now carry an explicit retry-reset outcome from both connected-lease monitoring and connection establishment back to the supervisor loop. The loop clears failureCount and pendingRetry before reconnecting, so the replacement starts at attempt 1. Added focused tests for both interrupt locations.
- packages/client-runtime/src/connection/supervisor.ts line 381Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -374,3 +375,6 @@374375 case "ConnectRequested":375376 break;376377 case "Wakeup":378+ if (next.reason === "application-active-reconnect") {379+ return;380+ }
Resume skips retry ladder reset#
Medium Severity
application-active-reconnectnow aborts in-flight establishment, but onlywaitForRetrySignalclearsfailureCount. AnInterruptedoutcome justcontinues, so a long resume that lands during connect setup keeps the prior backoff rung. The next failure can wait up to 16s instead of restarting the ladder.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ef970927540083720af30212038c3d0b21ac8cc9. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (1)
[gpt-5.6-sol] RESPONDING ON BEHALF OF THEO
Fixed in d878362d8. Long-resume interrupts now carry an explicit retry-reset outcome from both connection establishment and connected-lease monitoring back to the supervisor loop. The loop clears failureCount and pendingRetry before reconnecting, so the replacement starts at attempt 1. Added focused tests for both interrupt locations.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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).
packages/client-runtime/src/connection/supervisor.ts line 666Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -663,4 +711,3 @@663711 lastFailure: error,664712 retryAt: (yield* Clock.currentTimeMillis) + delayMs,665713 });666- yield* waitForRetrySignal(delayMs);Resume skips retry reset offline#
Medium Severity
Foreground activation now resets the retry ladder from backoff, establishment, and connected-lease interrupts, but
waitForSignalin the offline and blocked paths still discards the wakeup and leavesfailureCountunchanged. On mobile resume the syncapplication-active-*wakeup often arrives before the async network refresh, so a long resume while offline consumes the reset signal and the later online reconnect keeps the elevated backoff.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7b02afac3fcd1c0c5d8392259146a87f15973742. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (2)
[gpt-5.6-sol] RESPONDING ON BEHALF OF THEO
Fixed in e27978741. Offline and blocked waits now preserve whether the consumed signal was an application activation and reset the shared retry ladder before the next attempt. The same reset helper is used by backoff, establishment, connected-lease, offline, and blocked paths. Added ordering coverage for activation arriving before the asynchronous network-online refresh, plus the blocked path.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.

Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
bf9ac669-73cb-4a31-9167-84407a0b91ffYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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