Repository navigation
fix(mobile): stage-aware relay dial bound so a slow cell is not hung up on - #18518
Conversation
…up on A phone returning to foreground on 2026-09-03 logged "replacement session authentication timed out" five dials in a row while the desktop's relay control was live. The cell (production-gce-c27) had taken relay-auth but its assignment/reservation transactions were lock-contended (55P03 retries, 14–16s per accept); the phone's flat 12s migrateTo bound closed the socket 2–4s before the cell finished (cell logged host_data_reservation_already_bound), and because the timeout counted as a director-class failure the phone re-resolved the same cell and waited 12s again before logging — every retry landed in the same contended window. - MobileRelayE2eeLink reports onOpen once relay-auth is on the wire; MobileRelayRpcSession exposes a dial stage (opening → awaiting-hello → handshaking → confirming). - waitForAuthenticated keeps the caller's bound until the socket opens, then re-arms a per-stage budget (30s awaiting-hello, 12s handshaking, 35s confirming) so a reachable, slow cell is not treated as a black hole. - The timeout error carries the stalled stage and shows up in the "relay dial failed" log line; a stall past the open socket no longer triggers the director re-resolve round. Phone-local only: no wire change. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (12)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds relay dial-stage tracking across relay links and RPC sessions. Authentication waits now re-arm timers for each dial stage and report staged timeout errors. Endpoint supervision distinguishes socket-opening timeouts from relay-authentication stalls when deciding whether to re-resolve the director. Tests cover stage transitions, timeout cleanup, migration timing, retry behavior, and timeout logging. Merge Risk: ⚪ Minimal · up to Relay authentication now uses connection-stage timeout budgets and avoids unnecessary director re-resolution after a relay has opened but stalls. The covered timeout, cleanup, stage-transition, and retry behaviors indicate no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the incident, root cause, fix, scope, and test results, but it does not follow the repository template. It omits the required Linked Issue, Visual Proof or an explicit N/A explanation, checklist items, review notes, agent-skill boundary statement, and other template sections. Resolution Add the missing template sections. Include a linked issue after “Fixes #”, state “N/A” with a reason for visual proof if no visual change exists, complete the Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
ℹ️ No critical issues — the stage-aware re-arm logic is sound and well-covered by tests. One design consideration to confirm before merging, nothing blocking.
Reviewed changes
RelayDialStageTracker(new) — a four-stage dial tracker (opening → awaiting-hello → handshaking → confirming) plus a per-stage budget table, givingwaitForAuthenticateda way to tell "socket never opened" from "cell accepted the dial and is slow".waitForAuthenticatedre-arm — re-arms a per-stage budget on each stage advance (30s / 12s / 35s), keeps the caller's 12s bound foropeningand for sessions with no stage source, and reports the stalled stage inReplacementAuthenticationTimeoutError.MobileRelayE2eeLink.onOpen— fires oncerelay-authis on the wire, marking the boundary where the cell owns the wait.- Director-fallback gating — a timeout at a later stage no longer counts as a director-resolution failure, so the phone stops re-resolving the same cell and burning a second full dial.
- Tests — new
replacement-session-authenticationandmobile-endpoint-supervisor-stalled-cellsuites, plus stage-sequence,onOpen, andmigrateTo-wiring coverage. Each asserts exact outcomes (stage name, budget seconds, timer-count 0), so they would fall over without the feature.
ℹ️ Backgrounding or stop() doesn't promptly cancel an in-flight slow dial
The shouldAbort predicate that withdraws an in-flight dial when the app is backgrounded or stopped is only consulted after waitForAuthenticated resolves (stable-logical-rpc-client.ts:238). With the extended per-stage budgets, a dial stalled at awaiting-hello now keeps its socket open for the full 30s budget (up to ~42s including the 12s opening bound, longer if it progresses through later stages) before cancellation kicks in — where the prior flat 12s bound capped it. This is a plausible trade-off you've already weighed (iOS background suspension freezes the timers anyway), but worth confirming the socket doesn't outlive the app's background grace on Android.
Technical details
# Background/stop cancellation runs only post-authentication-wait
## Affected sites
- mobile/src/transport/stable-logical-rpc-client.ts:238 — `shouldAbort()` is checked only after `waitForAuthenticated` settles.
- mobile/src/transport/relay-dial-stage.ts:56-60 — `RELAY_DIAL_STAGE_BUDGET_MS` extends the wait to 30s/12s/35s per stage vs. the prior flat 12s.
- mobile/src/transport/mobile-relay-background-grace.ts:106-121 — `background()` does not close the in-flight replacement session (active path isn't `relay` yet, so `suspendRelay` returns early).
## Required outcome
- Confirm a backgrounded/stopped phone doesn't hold the socket (radio/battery) for the full stage budget before `migrateTo` aborts and closes `nextSession`.
## Open questions for the human
- Is the mutex (`operationInFlight`) + open socket being held through the full stage budget after background acceptable, or should cancellation be folded into the per-stage wait (e.g. abort on `!isActive()` between stage advances)?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Reconciles main's structured native Codex chat (#18074) and the stage-aware relay dial bound (#18518) with the hybrid operations layer: - native-chat controller keeps the operations/target/disconnect-retention seam and routes agent-session tabs through the structured hooks; the active-resolution and terminal-write hooks are extracted to stay under the line cap - image attachments keep the hosted attachImage/pasteImages path and add main's structured (paste-free) send - bare Codex launches take the structured path only on the native client; hosted adapter creates stay on the adapter - file taps resolve against the source session tab when a structured chat has no backing terminal - relay session advertises client capabilities after resume confirm - package downloader contract split out to break the import cycle the native code-quality audit now rejects Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…up on (stablyai#18518) A phone returning to foreground on 2026-09-03 logged "replacement session authentication timed out" five dials in a row while the desktop's relay control was live. The cell (production-gce-c27) had taken relay-auth but its assignment/reservation transactions were lock-contended (55P03 retries, 14–16s per accept); the phone's flat 12s migrateTo bound closed the socket 2–4s before the cell finished (cell logged host_data_reservation_already_bound), and because the timeout counted as a director-class failure the phone re-resolved the same cell and waited 12s again before logging — every retry landed in the same contended window. - MobileRelayE2eeLink reports onOpen once relay-auth is on the wire; MobileRelayRpcSession exposes a dial stage (opening → awaiting-hello → handshaking → confirming). - waitForAuthenticated keeps the caller's bound until the socket opens, then re-arms a per-stage budget (30s awaiting-hello, 12s handshaking, 35s confirming) so a reachable, slow cell is not treated as a black hole. - The timeout error carries the stalled stage and shows up in the "relay dial failed" log line; a stall past the open socket no longer triggers the director re-resolve round. Phone-local only: no wire change. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

Incident
2026-09-03 18:49–18:52Z, Samsung phone (mobile-rearch @ 22574ed) paired to macOS 1.4.197-adhoc over the cloud relay. After foreground return the host dot stayed grey and the phone logged
relay dial failed Error: replacement session authentication timed outfive times in a row (18:50:08, :32, :58, 18:51:23, :47). The desktop's relay control was healthy the whole time (host666077865f2e, one control 1006 at 18:41:54Z, sticky reassignment toproduction-gce-c27at 18:42:10Z, no drain/moved/4404).Root cause
The phone's dial stalled inside the cell's
acceptClientDB phase, beforeconn-openwas ever sent to the desktop.first frame handler failed host_data_reservation_already_boundat 18:50:06 and 18:51:51. That error is thrown byPendingHostDataReservation.bind, which runs only after the four serialized Postgres calls (resolveResume→assignments.resolve→reserveCredential→acquireActivity) return, and the reservation is released by the phone socket'sclose. So the cell finished its DB phase 2–4 s after the phone had already hung up at its flat 12 s bound.sqlLatencyMsMax1.1–2.1 s per 30 s sample,sqlFailuresDelta1–11 per sample, and a stream oforca_relay_postgres_transaction_retryevents with Postgres55P03(lock not available), on top of the fleet-wide 4401 storm adding reconnect load to the same assignment tables.pendingSpliceson c27 stayed 0–1, so the desktop never had an unansweredconn-open. The desktop was not involved.migrateTo/waitForAuthenticatedbound was a flat 12 s from dial start with no stage awareness:ConnectionStatestaysconnectinguntilrelay-hello, so a socket that opened and was accepted (cell working slowly) looked identical to a black-holed socket.Errorcounted as a director-class failure inisDirectorResolutionFailure, so the phone re-resolved the same cell and dialed again before logging. Every retry landed in the same contended window. The same pattern (3 timeouts, then success on attempt 4 at 18:46:43) shows it recovers as soon as the cell gets a fast window.Ruled out: stale cell/session, epoch mismatch, desktop splice gating, E2EE (never started). PR #18400 fixes a different trigger of the same symptom (desktop 4401 self-close → orphan → 4404); it does not cover this path and is still worth landing.
Fix (phone-side only, no wire change)
MobileRelayE2eeLinkgains anonOpenhook fired oncerelay-authis on the wire.MobileRelayRpcSessionexposes a dial stage:opening → awaiting-hello → handshaking → confirming.waitForAuthenticatedkeeps the caller's 12 s bound until the socket opens, then re-arms a per-stage budget on each advance (30 s awaiting-hello, 12 s handshaking, 35 s confirming). Budgets track the relay's own limits: 10 s host-attach deadline on top of the observed 14–16 s contended accept; 30 s resume-confirmation deadline with slack so the session's own RPC error wins.ReplacementAuthenticationTimeoutError) carries the stalled stage and lands in therelay dial failedlog line, e.g.timed out (awaiting-hello, 30s).Sessions that don't report stages (direct client, older fakes) keep the flat behavior.
Tests
replacement-session-authentication.test.ts(new): flat bound without stages; incident replay (stage advance after 11 s survives past 12 s; each later stage re-arms); stage-named timeout; opening-stage timeout; no timer leak after settle.stable-logical-rpc-client.test.ts:migrateTohonors the replacement's stages through the shipping wiring.mobile-relay-rpc-session.test.ts: stage sequence across open/hello/authenticated.mobile-relay-e2ee-link.test.ts:onOpenfires only afterrelay-authis written, not on a failed write.mobile-endpoint-supervisor-stalled-cell.test.ts(new): anawaiting-hellotimeout does not re-resolve the director and logs the stage; anopeningtimeout still does.Gates:
pnpm tc,cd mobile && npx vitest run src/transport(88 files / 657 passed),pnpm test src/main/runtime/relay(96 passed), oxlint on changed files,pnpm run check:code-quality:changed— all green. Mobile files formatted with oxfmt.