Repository navigation
feat(mobile): time relay dial stages so diagnostics say where a slow connect went - #19245
Conversation
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe change adds structured timing metadata for relay dial stages and connection-state dwell periods. It uses monotonic clocks, records timing through transport loggers, validates persisted timing entries, and preserves timing data through buffer eviction and redaction. Diagnostics reports now summarize the latest relay dial stages and aggregate connection-state dwell durations. Tests cover timing capture, failure handling, persistence validation, redaction, and report formatting. Merge Risk: ⚪ Minimal · up to This change adds relay dialing and connection-state timing details to diagnostics while preserving connection behavior if diagnostic logging fails. No current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, scope, and verification, but it omits several required template sections, including ELI5, Linked Issue, Visual Proof, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. The required issue link is also missing. Resolution Complete the required template sections. Add an issue link after "Fixes #"; provide an ELI5 summary; add "N/A" with a reason under Visual Proof if there is no UI or interaction change; complete the 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: aa80aead-34fa-4575-b9f8-065ca45a3a42
📥 Commits
Reviewing files that changed from the base of the PR and between 3145060 and c55889d91d06649efc24e4ca83a34c49716e42e3.
📒 Files selected for processing (17)
mobile/src/diagnostics/connection-diagnostics-report.test.tsmobile/src/diagnostics/connection-diagnostics-report.tsmobile/src/diagnostics/connection-log-timing-summary.tsmobile/src/transport/connection-log-buffer.test.tsmobile/src/transport/connection-state-dwell-log.test.tsmobile/src/transport/direct-connection-log.tsmobile/src/transport/direct-rpc-client.tsmobile/src/transport/mobile-relay-rpc-session.tsmobile/src/transport/monotonic-clock.tsmobile/src/transport/persisted-connection-log-store.test.tsmobile/src/transport/persisted-connection-log-store.tsmobile/src/transport/relay-dial-stage-log.tsmobile/src/transport/relay-dial-stage-timings.test.tsmobile/src/transport/relay-dial-stage.tsmobile/src/transport/rpc-client-connection-state.tsmobile/src/transport/rpc-client-log-redaction.test.tsmobile/src/transport/types.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline.
Reviewed changes
- Monotonic clock — new
monotonic-clock.tsprovidesperformance.now()-backedmonotonicNowMsand a clampedelapsedMsso phase durations can never go negative. - Relay dial stage timings —
RelayDialStageTrackernow returns the timing of each stage left; a newRelayDialStageLogemits them through the existingonLogsink, isolated in a try/catch so a throwing sink can't break a dial. - Connection-state dwell —
RpcClientConnectionStatereports dwell via anonStateDwellcallback, andDirectConnectionLog.stateDwellemits aconnection-statetiming (sub-100ms transitions skipped). - Report lines — new
connection-log-timing-summary.tsrenders the latest dial's per-stage breakdown plus connection-state dwell totals after "Last connected". - Load-time validation —
persisted-connection-log-store.tsvalidatestimingagainst the closed enum tables and drops malformed entries. - Tests — new suites cover tracker timing and idempotence, sink-throwing isolation, redaction-through-buffer, and report output.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
799f7b9 to
fd7388c
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior review, the PR was force-pushed and rebased onto a newer main and gained two fix commits.
- Negative duration rejected on load —
isConnectionLogTimingnow also requiresms >= 0, closing the one open nit from the prior review (0still survives as legitimate, negative values dropped). - Rebase onto
main(#19236) — the relay session now publishesconnectedat E2EE authentication viapublishAuthenticated, ahead of the resume confirm; this PR adds onlydialStageLog.enter('confirming')anddialStageLog.settle(true)to that structure, so the dial ends atconnectedand the post-connect confirm is no longer charged as dial latency. - Test updates — the dial-drive helpers answer the confirm and the concurrent capability advisory by method rather than send order, and the hydration test covers negative and zero
mscases.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reverted the
#19236rebase —mobile-relay-rpc-session.tsis back to the serial confirm flow (onAuthenticated→confirmResume()awaits the resume confirm and the capability advisory before publishingconnected), matching the currentmain. This restores theconfirmingdial stage to spanning the real confirm round trip, so the report'sconfirmingduration is meaningful again rather than a ~0ms artifact. - Test helpers reverted in step —
relay-dial-stage-timings.test.tsreturns torequestIdAtand the serialdriveToConnected, consistent with the serial flow.
The negative-duration load validation (ms >= 0) and its tests are unchanged and intact from the prior head.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…connect went A 10s connect was unattributable from a shared report. Relay dial stages carried no timestamps, so nothing could tell "the cell never answered relay-hello" from "the E2EE handshake was slow", and the per-state dweltMs the client already computed went only to console.log — invisible without a debug build. RelayDialStageTracker now stamps each stage entry from a monotonic clock (performance.now where present, wall clock otherwise) and returns the duration of the stage it just left. The session logs one entry per stage, and settles the in-flight stage on connect, failure, or close, so a dial that dies mid-way still names the stage it never finished. dweltMs joins the same buffer as a structured field instead of console. Durations ride the existing per-host log buffer and its cap, so memory is unchanged and no new storage appears. The report derives two lines from them: the latest dial's stage breakdown (a reconnect loop must not average away the attempt being reported) and total dwell per connection state. Both are numbers and closed-enum names, and the entries still pass through the existing redaction.
…g names to their enums Review follow-ups on the dial-stage timing work. The stage timing emitted on the confirm's success path ran inside the try that calls fail(), so an onLog sink that threw would have turned a good connect into a failed session. The same hazard existed on the direct path, where the dwell emit sits in publish() ahead of the listener loop and the connect waiters. Both sink calls are now isolated: a broken sink loses a log line and nothing else. The persisted-log validator accepted any string as a timing name, and the report echoes that name unredacted. Names are now checked against the closed enum for their kind, backed by Record<Union, true> tables so adding a stage or a state breaks the build rather than silently widening what a corrupted store can inject. Entry volume: every reconnect cycle walks four connection states, so logging each one would roughly double what a slow-connect report holds against the unchanged 200-entry per-host cap. Transitions under 100ms are therefore not buffered. They cannot be where a slow connect spent its time, and console still shows all of them. States that flap slowly, which is the case support cares about, still land in the log. RpcClientConnectionState takes an optional clock so dwell thresholds are testable without sleeping.
…he log A persisted timing only had to be finite to survive hydration, so a corrupted `ms: -1` reached the diagnostics report, where the dial summary sums the stage durations and a negative would subtract from the total. Producers clamp at 0 (`elapsedMs`), so anything below it is corruption. 0 itself still hydrates: a stage the dial passes through instantly is real.
…so the dial log fits
fd7388c to
fa280ff
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: bc4ba477-70e2-4b4a-ac64-3bc77d0bb855
📥 Commits
Reviewing files that changed from the base of the PR and between c55889d91d06649efc24e4ca83a34c49716e42e3 and fa280ff.
📒 Files selected for processing (5)
mobile/src/transport/mobile-relay-rpc-session.tsmobile/src/transport/persisted-connection-log-store.test.tsmobile/src/transport/persisted-connection-log-store.tsmobile/src/transport/relay-dial-stage-timings.test.tsmobile/src/transport/relay-session-liveness-profile.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Liveness profile extracted — moved the relay session's probe budget constants and timeout log line out of
mobile-relay-rpc-session.tsintocreateRelaySessionLivenessWatchdogin the newrelay-session-liveness-profile.ts. Behavior-preserving: sametransport, probe/urgent/idle timings,shouldIdleProbe, and++logSequenceevaluation (still only runs when a timeout is logged vianextLogId). - Rebased onto authenticated-first
main— the session now publishesconnectedat E2EE authentication with the resume confirm and capability advisory riding concurrently (currentmainstructure). Theconfirmingstage still spans the real confirm round trip:dialStageLog.enter('confirming')fires at authentication butdialStageLog.settle(true)fires only on thepairing.getEndpointsanswer. - Test helper adapted —
driveToConnectednow waits onconnected, answers the resume confirm and capability advisory in send order, and awaitswhenResumeConfirmed().
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 50e334b2-bd6b-4cb4-82d4-726a360a5fd4
📒 Files selected for processing (2)
mobile/src/transport/mobile-relay-rpc-session-liveness.test.tsmobile/src/transport/relay-session-liveness-profile.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/src/transport/relay-session-liveness-profile.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior review, one fix commit landed.
- Liveness-timeout log line isolated —
createRelaySessionLivenessWatchdog'sonTimeoutnow wraps itsonLogcall in a try/catch. The watchdog callsterminateright afteronTimeoutreturns, so a throwing sink previously aborted that flow and left a dead relay stuck onconnected; nowterminatealways runs. - Regression test added —
mobile-relay-rpc-session-liveness.test.tsproves the session still disconnects and closes the link when the log sink throws on the timeout line, which fails on the pre-fix code.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Test tightened against a vacuous pass — the
still terminates a dead relay when the log sink throwstest now captures the throwing sink asvi.fn<ConnectionLogSink>and assertstoHaveBeenCalledWith({ code: 'liveness-timeout' }). Previously the test proved only that the session came down, so it would have passed even if the timeout line was never emitted; now it fails if the sink is unused. No production change.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…aller, verified re-land (#19348) * Revert "feat(mobile): time relay dial stages so diagnostics say where a slow connect went (#19245)" This reverts commit 83b1558. * Revert "perf(mobile): race the direct and relay dials from t=0 on every reconnect (#19308)" This reverts commit ceafdca. * Revert "feat(mobile): draw the last known tab strip while a session reconnects (mobile pass) (#19281)" This reverts commit 643571d. * Revert "perf(mobile): open a session with parallel startup RPCs and a pre-warmed terminal engine (#19260)" This reverts commit c374132. * Revert "perf(mobile): cut the relay reconnect critical path and admit dead sockets faster (mobile pass) (#19280)" This reverts commit e628090. * chore: keep the react-doctor suppression for the startup timers The pattern it covers (a variable number of timers cleared through one cleanup) predates #19260 and is unchanged by the revert; dropping the entry only re-exposed a pre-existing finding to the changed-code gate.

Why
When a phone takes ten seconds to connect, the shareable diagnostics report could not say where the time went: relay dial stages had no timestamps and the connection-state dwell time went only to the console. Support was left guessing between the relay, the cell, and the desktop.
What
monotonic-clock.ts:performance.now()where available, elseDate.now(); every duration clamped to non-negative.ConnectionLogEntry.timing(optional):{ kind: 'relay-dial-stage' | 'connection-state', name, ms, complete }.complete: falserecords a stage that never finished.nameis a closed enum for its kind; the persisted store validates it on load and drops malformed entries, and the enum tables are typed so adding a stage or state breaks the build rather than widening what a corrupted store can inject.MIN_LOGGED_DWELL_MS) so the fixed-size log keeps its history span; the console line still shows every transition.Verification
mobile:tsc --noEmit,vitest run(518 files, 4219 tests),oxlint,oxfmt --check;check:code-quality:changed0 across 17 files.Not for merge until the owner gives the go.