Repository navigation
fix(mobile): reset reconnect attempts only after the E2EE handshake completes - #11465
Conversation
…ompletes ws.onopen zeroed reconnectAttempt before the handshake, so any endpoint that accepted the socket but never authenticated pinned the counter at 0-1: no escalation gate could fire, backoff never grew, and every screen showed "Connecting…" forever (issue #10119). Reset the counter on e2ee_authenticated instead, and make classifyConnection apply the warning/unreachable gates during connecting/handshaking so an escalated verdict latches through redials.
📝 WalkthroughWalkthroughConnection health classification now preserves warning and unreachable labels while dialing, including connecting and handshaking states. The RPC client keeps reconnect attempts through WebSocket opens and resets them only after completed E2EE authentication. New mocked and real-socket tests cover stalled cellular connections, delayed handshakes, label persistence, recovery, and retry progression. Existing authorization retry tests now use 1-second timer advances to match handshake backoff timing. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
Greptile SummaryThis PR fixes a mobile client stuck-at-"Connecting…" regression on cellular (#10119) by moving
Confidence Score: 5/5The two source changes are minimal and surgically scoped: one line moved in rpc-client.ts and a handful of lines restructured in connection-health.ts. All existing assertions pass; the only test changes are timer advances that now match the new backoff growth. Both changes are correctly reasoned and well-bounded. The counter reset moving from ws.onopen to setState('connected') closes the 0↔1 oscillation exactly as described. The connection-health restructuring correctly applies the escalation gates to all dialing states while preserving the 'Connecting…' vs 'Reconnecting…' label distinction. The notifyForeground deliberate reset, the auth-retry budget, and the trickle cap are all untouched and confirmed by the existing test suite. New coverage is thorough: fake-timer behavioral assertions, a real-socket guard, and unit cases for the gate logic. No regressions were found. Files Needing Attention: No files require special attention. The core logic changes in rpc-client.ts and connection-health.ts are each fewer than 10 lines and are fully covered by the new and updated tests.
|
| Filename | Overview |
|---|---|
| mobile/src/transport/rpc-client.ts | Core fix: removes reconnectAttempt reset from ws.onopen and moves it to the setState('connected') branch; comment clarifies the rationale. No regressions to notifyForeground or auth-retry budget paths. |
| mobile/src/transport/connection-health.ts | Drops the early-return for connecting/handshaking states; applies warning/unreachable gates uniformly; final fallback correctly returns 'Reconnecting…' vs 'Connecting…' by inspecting the state value. |
| mobile/src/transport/cellular-connecting-label-stall.test.ts | New deterministic fake-timer suite covering four carrier behaviors (blackhole, refused, open-then-silent, slow-handshake). Asserts label latching, backoff growth, socket count bounding, and counter reset semantics. |
| mobile/src/transport/cellular-handshake-stall-real-socket.test.ts | Opt-in real-socket/real-timer guard (ORCA_MOBILE_LIVE_REPRO=1) against mock drift. Correctly skips in default runs with a sentinel test to avoid vitest file-with-zero-tests failure. |
| mobile/src/transport/connection-health.test.ts | Adds five unit cases covering gate behavior during connecting/handshaking: warning verdict, unreachable verdict, stale heuristic, and below-gate 'Connecting…' preservation. |
| mobile/src/transport/rpc-client.test.ts | Timer advances between auth-retry cycles updated from 500ms to 1000ms to reflect that failed handshakes now grow the backoff index; assertions are unchanged. |
| mobile/src/transport/rpc-client-unauthorized-close.test.ts | Same 500ms→1000ms timing fix as rpc-client.test.ts for both the pure 4001-close path and the mixed e2ee_error/4001 budget test. |
Sequence Diagram
sequenceDiagram
participant App
participant rpc as rpc-client.ts
participant ws as WebSocket
participant health as connection-health.ts
App->>rpc: connect(endpoint, token, serverKey)
rpc->>ws: new WebSocket(endpoint)
rpc->>rpc: setState('connecting')
note over rpc: reconnectAttempt unchanged (was reset here before fix)
ws-->>rpc: onopen
rpc->>rpc: setState('handshaking')
rpc->>ws: send(e2ee_hello)
alt Handshake succeeds
ws-->>rpc: e2ee_ready
rpc->>ws: sendEncrypted(e2ee_auth)
ws-->>rpc: e2ee_authenticated
rpc->>rpc: setState('connected')
note over rpc: reconnectAttempt = 0 (moved here from onopen)
rpc->>rpc: "authRejectionCount = 0"
else Handshake stalls / timeout (5s)
rpc->>ws: close()
ws-->>rpc: onclose
rpc->>rpc: setState('reconnecting')
rpc->>rpc: scheduleReconnect — reconnectAttempt++
note over rpc: counter NOT reset (was reset pre-fix)
end
App->>health: classifyConnection(state, reconnectAttempts, lastConnectedAt)
alt "state = connected"
health-->>App: normal / Connected
else "state = connecting or handshaking or reconnecting"
alt "reconnectAttempts >= 12"
health-->>App: unreachable / Can't reach desktop
else "reconnectAttempts >= 3"
health-->>App: warning / Can't connect
else
health-->>App: normal / Connecting… or Reconnecting…
end
end
Reviews (1): Last reviewed commit: "fix(mobile): reset reconnect attempts on..." | Re-trigger Greptile
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6a50109d-fb79-4a48-814a-8d9b219a6823
📒 Files selected for processing (7)
mobile/src/transport/cellular-connecting-label-stall.test.tsmobile/src/transport/cellular-handshake-stall-real-socket.test.tsmobile/src/transport/connection-health.test.tsmobile/src/transport/connection-health.tsmobile/src/transport/rpc-client-unauthorized-close.test.tsmobile/src/transport/rpc-client.test.tsmobile/src/transport/rpc-client.ts
Completes the 0.0.37 release attempted on 2026-08-03 (run 30791649691 failed on the version assertion). Ships the post-0.0.36 transport fixes: relay session recovery when the LAN endpoint is unreachable (#12344, #11368, #11465, #11690) and honest worktree-catalog failure states (#12235) — the released-app defect class verified live tonight. Co-authored-by: OrcaWin <[email protected]>
…ompletes (stablyai#11465) ws.onopen zeroed reconnectAttempt before the handshake, so any endpoint that accepted the socket but never authenticated pinned the counter at 0-1: no escalation gate could fire, backoff never grew, and every screen showed "Connecting…" forever (issue stablyai#10119). Reset the counter on e2ee_authenticated instead, and make classifyConnection apply the warning/unreachable gates during connecting/handshaking so an escalated verdict latches through redials.
Completes the 0.0.37 release attempted on 2026-08-03 (run 30791649691 failed on the version assertion). Ships the post-0.0.36 transport fixes: relay session recovery when the LAN endpoint is unreachable (stablyai#12344, stablyai#11368, stablyai#11465, stablyai#11690) and honest worktree-catalog failure states (stablyai#12235) — the released-app defect class verified live tonight. Co-authored-by: OrcaWin <[email protected]>
Summary
Fixes #10119 — mobile client stuck at "Connecting…" over cellular.
ws.onopenresetreconnectAttemptto 0 before the E2EE handshake completed. A WebSocket upgrade succeeding is not a healthy session — that requirese2ee_authenticated, two round trips later under a 5s budget. So for any endpoint that accepts the socket but never finishes the handshake (high-RTT/lossy cellular link, relay with no desktop attached), the counter oscillated 0↔1 forever:connection-health.ts(>= 3→ "Can't connect",>= 12→ "Can't reach desktop" + re-pair affordance) could ever fire, andVerified live on an iOS 26.5 simulator against a stalling fake desktop:
attemptwas 0 on everyconnecting → handshakingtransition andmsSinceLastClosenever left 502–512ms.Two changes:
rpc-client.ts— resetreconnectAttempton the'connected'transition (e2ee_authenticated), not inws.onopen. Failed handshakes now count, so gates fire and backoff grows to the 90s trickle.connection-health.ts— apply the same warning/unreachable gates whileconnecting/handshaking. Every redial re-entersconnecting, which previously flipped an escalated verdict back to "Connecting…" for the whole dial window (12s of every blackhole cycle), so the failure never latched — the reported symptom.Existing-test timing updates: consecutive failed handshakes now grow the backoff, so the auth-retry tests (#5200 scenarios) advance 1000ms instead of 500ms between rejection cycles. The auth-retry budget semantics themselves are unchanged (all existing assertions pass).
Relationship to #10385 (coordination note — an agent is working that issue separately)
This PR does NOT cover #10385 (iOS shows falsely connected after RPC stalls; Force Reconnect can't recover). That defect lives in the post-handshake
'connected'state (half-open socket liveness / force-reconnect path). This PR only changes pre-handshake failure accounting and label gating; it does not touchnotifyForeground's connected-path, the activity probe, or any close/reconnect plumbing. Lines touched inrpc-client.ts: thews.onopenhandler (removed the reset), thesetState('connected')branch (added the reset), and one interface comment — no expected overlap with a #10385 fix.Screenshots
No visual change — no new UI, copy, or components. The fix changes when the existing connection labels/verdicts ("Can't connect", "Can't reach desktop", re-pair affordance) are shown: they now actually appear during a failure loop and latch instead of reverting to "Connecting…" on every redial.
Testing
pnpm lint(mobile oxlint clean; pre-commit also ran the react-doctor oxlint config)pnpm typecheck(mobiletsc --noEmitclean)pnpm test(full mobile suite: 357 files, 2618 passed / 3 skipped)pnpm build— N/A formobile/(no build script; Mobile Checks runs typecheck/test/lint/format, all clean locally includingoxfmt --check)Non-vacuity proof (measured against parent
24a2accc3c): with the two source files reverted to parent, 8/8 new assertions fail —cellular-connecting-label-stall.test.ts(5 failures: max attempts pinned at 1, no escalated label ever, label reverts each dial, counter not reset semantics) and the newclassifyConnectiondialing cases (3 failures). The opt-in real-socket test (ORCA_MOBILE_LIVE_REPRO=1, realwsserver answeringe2ee_hello1s past the budget, real timers) also fails on parent withexpected 1 to be greater than or equal to 3. With the fix restored, everything is green.New coverage:
cellular-connecting-label-stall.test.ts— deterministic fake-timer walk of four carrier behaviors (handshake 1s too slow, accept-then-silent, blackholed LAN address, RST contrast), sampling what every screen would render every 250ms for up to 15 simulated minutes. Asserts gates fire, labels latch, backoff grows (socket count bounded), and the counter resets only on a completed handshake.cellular-handshake-stall-real-socket.test.ts— real-socket/real-timer guard against mock drift, opt-in viaORCA_MOBILE_LIVE_REPRO=1(same pattern asrpc-client-live-recovery.test.ts) since it needs ~22s wall clock.connection-health.test.ts— unit cases for the gates duringconnecting/handshaking, including the stale heuristic and the below-gate "Connecting…" behavior.AI Review Report
Reviewed the full state machine for regressions before writing the fix:
auth-failedafter 3; only their spacing grows (500ms → 1000ms for cycle 2). Existing tests updated for timing only, assertions unchanged.notifyForegroundkeeps its own explicitreconnectAttempt = 0(deliberate user signal) — untouched, covered by existing tests.GIVE_UP_AFTER_ATTEMPTSand slows to the 90s trickle instead of dialing every ~5.6s forever;waitForConnected's fail-fast at the cap becomes reachable for these loops (intended escalation).mobile-relay-rpc-session.tshardcodesgetReconnectAttempt: () => 0(its retry counter lives in the reconnect controller) — unchanged here, see Notes.connection-health.tsonly imports the pre-existing shared Tailscale-hint helper). macOS/Linux/Windows desktop builds are not in the blast radius.Security Audit
No new input handling, command execution, path handling, or IPC. The E2EE handshake protocol, token handling, and 4001 close-code mapping are unchanged — the fix only moves when a failure counter resets and which pre-existing label is chosen. Endpoint redaction in logs is untouched. No dependency changes. The auth-failure latch cannot be reached later or bypassed earlier than before (verified by the unchanged #5200 test assertions).
Notes
WARNING_ATTEMPTS = 3calibration deliberately unchanged) — but it now latches instead of reverting to "Connecting…" for 12s of every later cycle.getReconnectAttempt() === 0, so relay-path failure loops still can't escalate the label; its retry counter lives inmobile-relay-reconnect-controller.tsand would need threading through.