Skip to content

feat(mobile): time relay dial stages so diagnostics say where a slow connect went - #19245

Merged
Jinwoo-H merged 6 commits into
mainfrom
mobile/relay-dial-stage-timings
Sep 7, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
mobile/relay-dial-stage-timings

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​514 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​512
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​351 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​304

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, else Date.now(); every duration clamped to non-negative.
  • ConnectionLogEntry.timing (optional): { kind: 'relay-dial-stage' | 'connection-state', name, ms, complete }. complete: false records a stage that never finished. name is 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.
  • Diagnostics report: two lines after "Last connected", the latest dial's per-stage breakdown with total and the connection-state dwell summary. Only enum names and durations, so the existing redaction rules apply unchanged.
  • Transport behaviour is unchanged: two synchronous insertions, no new await or timer on any path. Both sink calls are isolated so a throwing log sink can never fail a good connect; tests cover a sink that throws on every stage.
  • Transitions under 100 ms are not buffered (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:changed 0 across 17 files.
  • Independent adversarial review: transport diff confirmed limited to timing capture; settle idempotence and mid-dial failure recording verified; redaction and old-entry loading verified. Nit round added the sink isolation and enum validation.

Not for merge until the owner gives the go.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: d96cc0e2-05a7-473f-941d-2a26afbf2c28

📥 Commits

Reviewing files that changed from the base of the PR and between d38ce70 and 5070df4.

📒 Files selected for processing (1)
  • mobile/src/transport/mobile-relay-rpc-session-liveness.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/transport/mobile-relay-rpc-session-liveness.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The 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 5070d

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… 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 upstrea…
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: timing relay dial stages so diagnostics identify slow connection phases.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • mobile/src/diagnostics/connection-diagnostics-report.ts
  • mobile/src/diagnostics/connection-log-timing-summary.ts
  • mobile/src/transport/connection-log-buffer.test.ts
  • mobile/src/transport/connection-state-dwell-log.test.ts
  • mobile/src/transport/direct-connection-log.ts
  • mobile/src/transport/direct-rpc-client.ts
  • mobile/src/transport/mobile-relay-rpc-session.ts
  • mobile/src/transport/monotonic-clock.ts
  • mobile/src/transport/persisted-connection-log-store.test.ts
  • mobile/src/transport/persisted-connection-log-store.ts
  • mobile/src/transport/relay-dial-stage-log.ts
  • mobile/src/transport/relay-dial-stage-timings.test.ts
  • mobile/src/transport/relay-dial-stage.ts
  • mobile/src/transport/rpc-client-connection-state.ts
  • mobile/src/transport/rpc-client-log-redaction.test.ts
  • mobile/src/transport/types.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Monotonic clock — new monotonic-clock.ts provides performance.now()-backed monotonicNowMs and a clamped elapsedMs so phase durations can never go negative.
  • Relay dial stage timings — RelayDialStageTracker now returns the timing of each stage left; a new RelayDialStageLog emits them through the existing onLog sink, isolated in a try/catch so a throwing sink can't break a dial.
  • Connection-state dwell — RpcClientConnectionState reports dwell via an onStateDwell callback, and DirectConnectionLog.stateDwell emits a connection-state timing (sub-100ms transitions skipped).
  • Report lines — new connection-log-timing-summary.ts renders the latest dial's per-stage breakdown plus connection-state dwell totals after "Last connected".
  • Load-time validation — persisted-connection-log-store.ts validates timing against 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H force-pushed the mobile/relay-dial-stage-timings branch 2 times, most recently from 799f7b9 to fd7388c Compare September 7, 2026 09:09

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — isConnectionLogTiming now also requires ms >= 0, closing the one open nit from the prior review (0 still survives as legitimate, negative values dropped).
  • Rebase onto main (#19236) — the relay session now publishes connected at E2EE authentication via publishAuthenticated, ahead of the resume confirm; this PR adds only dialStageLog.enter('confirming') and dialStageLog.settle(true) to that structure, so the dial ends at connected and 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 ms cases.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Reverted the #19236 rebase — mobile-relay-rpc-session.ts is back to the serial confirm flow (onAuthenticated → confirmResume() awaits the resume confirm and the capability advisory before publishing connected), matching the current main. This restores the confirming dial stage to spanning the real confirm round trip, so the report's confirming duration is meaningful again rather than a ~0ms artifact.
  • Test helpers reverted in step — relay-dial-stage-timings.test.ts returns to requestIdAt and the serial driveToConnected, consistent with the serial flow.

The negative-duration load validation (ms >= 0) and its tests are unchanged and intact from the prior head.

Pullfrog  | View workflow run | Using 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.
@Jinwoo-H
Jinwoo-H force-pushed the mobile/relay-dial-stage-timings branch from fd7388c to fa280ff Compare September 7, 2026 17:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • mobile/src/transport/persisted-connection-log-store.test.ts
  • mobile/src/transport/persisted-connection-log-store.ts
  • mobile/src/transport/relay-dial-stage-timings.test.ts
  • mobile/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.ts into createRelaySessionLivenessWatchdog in the new relay-session-liveness-profile.ts. Behavior-preserving: same transport, probe/urgent/idle timings, shouldIdleProbe, and ++logSequence evaluation (still only runs when a timeout is logged via nextLogId).
  • Rebased onto authenticated-first main — the session now publishes connected at E2EE authentication with the resume confirm and capability advisory riding concurrently (current main structure). The confirming stage still spans the real confirm round trip: dialStageLog.enter('confirming') fires at authentication but dialStageLog.settle(true) fires only on the pairing.getEndpoints answer.
  • Test helper adapted — driveToConnected now waits on connected, answers the resume confirm and capability advisory in send order, and awaits whenResumeConfirmed().

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 50e334b2-bd6b-4cb4-82d4-726a360a5fd4

📥 Commits

Reviewing files that changed from the base of the PR and between fa280ff and d38ce70.

📒 Files selected for processing (2)
  • mobile/src/transport/mobile-relay-rpc-session-liveness.test.ts
  • mobile/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Since the prior review, one fix commit landed.

  • Liveness-timeout log line isolated — createRelaySessionLivenessWatchdog's onTimeout now wraps its onLog call in a try/catch. The watchdog calls terminate right after onTimeout returns, so a throwing sink previously aborted that flow and left a dead relay stuck on connected; now terminate always runs.
  • Regression test added — mobile-relay-rpc-session-liveness.test.ts proves the session still disconnects and closes the link when the log sink throws on the timeout line, which fails on the pre-fix code.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Test tightened against a vacuous pass — the still terminates a dead relay when the log sink throws test now captures the throwing sink as vi.fn<ConnectionLogSink> and asserts toHaveBeenCalledWith({ 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 83b1558 into main Sep 7, 2026
22 checks passed
@Jinwoo-H
Jinwoo-H deleted the mobile/relay-dial-stage-timings branch September 7, 2026 17:52
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant