Skip to content

perf(mobile): open a session with parallel startup RPCs and a pre-warmed terminal engine - #19260

Merged
Jinwoo-H merged 1 commit into
mainfrom
mobile/session-startup-parallel
Sep 7, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
mobile/session-startup-parallel

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1218 $\color{#cf222e}{\Huge{\mathbf{−}}}$​53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1165
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​396 $\color{#cf222e}{\Huge{\mathbf{−}}}$​179 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​217

Why

After the relay session connects, the phone serialized a status.get protocol gate, then session.tabs.list and terminal.list, plus a second status.get from a capability probe, and only then booted the terminal engine. Each round trip is tens of milliseconds in-region and one to three seconds on a far cell, so that serialization was most of the remaining time to a visible terminal.

What

  • The protocol gate no longer holds children back. Routes mount as soon as the connection does, under the existing pending overlay, so their reads run alongside status.get. A blocked verdict still replaces the subtree. Startup writes (worktree.activate) sit in their own effect gated on !statusPending && compatVerified && compatVerdict.kind === 'ok', so a blocked desktop is never mutated. The third term is a tightening over main: a host that cannot answer status.get still fails open for navigation, but that fallback verdict no longer counts as a passing one, so it no longer receives the activation. A transient failure is unaffected, because the probe retries and a later reply flips the flag. Only a host that definitively rejects status.get loses the activation, and such a host already reports no capabilities, so the route was running in its most conservative mode regardless.
  • session.tabs.list and terminal.list are issued together with per-call error isolation; a session change mid-flight discards both results.
  • The second status.get is gone: tab reconciliation reads capabilities from the gate. The probe reports the whole status and retries only an unanswered request; an error reply settles. Cold-open status.get count 2 → 1, serialized round trips before first paint 3 → 1.
  • The terminal engine pre-warms during loading inside a container that reserves the tab-bar band, so the measured viewport equals the first pane's real frame. The pre-warm opens its engine before measuring: web-ready only reports that the xterm bundle loaded, and the WebView answers measure with null until a terminal exists, so it calls init and awaits awaitReady first. It also mounts at the user's saved text size, because cell size is what the frame height gets divided by. The tab bar's rendered height is unchanged from main (the explicit height added earlier was removed after a border-box review). A test drives the real refit hook on a single-terminal cold open and asserts zero terminal.updateViewport and zero resubscribes; measured against the unreserved box it sends exactly one.
  • One pre-existing react-doctor finding (effect-needs-cleanup on the startup file) is listed in the changed-code gate's suppression map; the map keys by file, and the effect's timers are all cleaned up.

Verification

  • mobile: tsc --noEmit, vitest run (520 files, 4238 tests), oxlint, oxfmt --check; check:code-quality:changed and check:react-doctor:changed clean. Re-run after rebase on main.
  • Automated review round: all three findings accepted and fixed with failing-first tests (pre-warm init ordering, and the fail-open-reads-as-verified seam across host-status-gates.ts and the foundation hook).
  • Independent adversarial review, two rounds plus a nit round. Round 1 found the pre-warm measured a frame without the tab bar (PTY two rows too tall, an extra round trip on exactly the optimized path), unbounded status polling on error replies, and a mutation firing before the verdict. Round 2 found the reservation constant one pixel off under border-box sizing and an unasserted zero-round-trip claim. All fixed and pinned by tests; re-pinning the explicit height fails four assertions.

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: c4bdc4c4-8f50-4d36-a567-07ea4b0d5a29

📥 Commits

Reviewing files that changed from the base of the PR and between a7b9a5f and f799992.

📒 Files selected for processing (2)
  • mobile/src/session/TerminalEnginePrewarm.test.ts
  • mobile/src/session/TerminalEnginePrewarm.tsx

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


📝 Walkthrough

Walkthrough

The change centralizes host status probing and capability extraction. Host routes now mount under a pending compatibility cover and unmount when blocked. Session reads start in parallel, while worktree activation waits for protocol verification. Terminal engines now prewarm during loading and pending states, measure the real frame once, and reserve tab-bar space when required. Tests cover status retries, startup ordering, route gating, prewarm geometry, and viewport refitting.

Merge Risk: ⚪ Minimal · up to f7999

Mobile session startup now parallelizes initial reads, gates activation on compatibility, and prewarms the terminal engine. The covered startup, gating, and viewport behaviors leave no concrete current-head merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the motivation, implementation, risks, and verification, but it omits most required template sections, including ELI5, What Changed, Linked Issue with an issue number, Visual … Complete the required template sections. Add an ELI5 summary, move or summarize the implementation under What Changed, provide a Linked Issue in the form Fixes #..., add Visual Proof or write N/A with the reason, complete the Testing ch…
Docstring Coverage ⚠️ Warning Docstring coverage is 39.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 22 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 summarizes the main changes: parallel startup RPCs and terminal engine pre-warming for mobile sessions.
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 motivation, implementation, risks, and verification, but it omits most required template sections, including ELI5, What Changed, Linked Issue with an issue number, Visual Proof or N/A, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Complete the required template sections. Add an ELI5 summary, move or summarize the implementation under What Changed, provide a Linked Issue in the form Fixes #..., add Visual Proof or write N/A with the reason, complete the Testing checkboxes and platform details, address 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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 74184455-4012-47fe-a305-145d8e79ab5a

📥 Commits

Reviewing files that changed from the base of the PR and between c3a7008 and 05269d9a94b5a9984eacd1ac4ef9c0e46344febf.

📒 Files selected for processing (22)
  • config/scripts/check-changed-code-quality.mjs
  • mobile/src/components/HostProtocolGate.test.ts
  • mobile/src/components/HostProtocolGate.tsx
  • mobile/src/components/codex-reset-credit-capability.test.ts
  • mobile/src/components/codex-reset-credit-capability.ts
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/TerminalEnginePrewarm.test.ts
  • mobile/src/session/TerminalEnginePrewarm.tsx
  • mobile/src/session/mobile-session-frame-styles.ts
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-session-startup-parallelism.test.ts
  • mobile/src/session/mobile-session-startup-source.test.ts
  • mobile/src/session/terminal-prewarm-frame-geometry.test.ts
  • mobile/src/session/terminal-prewarm-refit-debt.test.ts
  • mobile/src/session/use-mobile-session-foundation.ts
  • mobile/src/session/use-mobile-session-startup.ts
  • mobile/src/session/use-mobile-session-tab-reconciliation.ts
  • mobile/src/session/use-mobile-session-terminal-subscription-foundation.ts
  • mobile/src/transport/host-status-gates.ts
  • mobile/src/transport/runtime-status-probe.test.ts
  • mobile/src/transport/runtime-status-probe.ts
  • mobile/src/worktree/home-host-worktree-fetch.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 critical issues — a couple of points worth confirming before merge.

Reviewed changes — parallel session-startup RPCs, a shared single status.get, and a pre-warmed terminal engine with tab-bar geometry pinned by a suite of real-hook tests.

  • Routes mount under the pending overlay — HostProtocolGate stops holding children back, so session.tabs.list and terminal.list fly alongside status.get; a blocked verdict unmounts them.
  • Single shared status.get — host-status-gates moves to startRuntimeStatusProbe (fail-open on first miss, retry underneath); tab reconciliation reads capabilities from the gate instead of re-probing.
  • Startup writes gated on the verdict — worktree.activate moves to its own effect keyed on protocolVerified.
  • Terminal engine pre-warm — an inert TerminalWebView boots during loading, reserves the tab-bar band, and latches the first pane's viewport measurement.
  • Geometry + parity tests — frame-height, refit-debt, and route-parity assertions pin the tab-bar height and the zero-refit claim.

ℹ️ Pre-warm boots a terminal engine for every session, including terminal-free ones

The prewarm is mounted unconditionally in the showLoadingState branch, which is !terminalsLoaded && visibleTabs.length === 0 — true for every cold open before terminal.list/session.tabs.list return, including sessions that resolve to a browser, markdown, or file tab with no terminal. The comment in TerminalEnginePrewarm ("a session still resolving its tabs already knows it is heading for a terminal") is not accurate for that branch: at that point the route does not know whether a terminal exists. The cost is bounded (the prewarm unmounts once terminals load), but it means an extra WebView + xterm bundle load and its memory for every non-terminal session. Worth confirming that is an accepted tradeoff.

ℹ️ Nitpicks

  • The prewarm's bare TerminalWebView gets no textScale or terminalTheme, so measureFitDimensions runs at the default text scale; users with a persisted zoom still pay the terminal.updateViewport refit the prewarm is meant to avoid (the frame-height refit corrects it, so it is a perf gap, not a correctness bug). The refit-debt test only drives textScale: 1.
  • startRuntimeCapabilityProbe is now a thin wrapper over startRuntimeStatusProbe, so its ok:false handling silently changed from "retry" to "settle and stop". Its only remaining caller, useCodexResetCreditCapability, is not exercised against an ok:false response through the wrapper (the new test covers startRuntimeStatusProbe with an onUnavailable handler instead).

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

@Jinwoo-H
Jinwoo-H force-pushed the mobile/session-startup-parallel branch 2 times, most recently from 573d502 to a7b9a5f Compare September 7, 2026 09:07
@Jinwoo-H

Jinwoo-H commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai 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 — the delta since the prior pullfrog review: a compatVerified gate, a corrected pre-warm handoff, and tab-bar/reconnect geometry alignment.

  • Added compatVerified so fail-open is not a passing verdict — host-status-gates now sets compatVerified only when onStatus evaluated a real reply; use-mobile-session-foundation computes protocolVerified = !statusPending && compatVerified && compatVerdict.kind === 'ok'. This resolves both prior CodeRabbit findings and the fail-open flash: a transient status.get miss now keeps capabilities at null (checking) instead of false.
  • Made the pre-warm open the engine before handing it over — TerminalEnginePrewarm now calls init + awaitReady once the pane is laid out and web-ready, so the one-shot measureFitDimensions no longer answers null; it also accepts textScale and both call sites pass the saved value, resolving the default-text-size nitpick.
  • Aligned the tab-bar reservation and added a reconnect branch — MobileSessionActiveContent reads tabStripRows (the header's own list) instead of visibleTabs, and renders a reconnect-with-cache label instead of the pre-warm so cached scrollback is never replayed into a fresh WebView.

The new tests are real regression tests — the gate tests fail if fail-open claims verification, and the pre-warm tests fail against the pre-init code and against a default text size.

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: ea2d7a32-7f3e-4bbd-92c2-a54ce93638bd

📥 Commits

Reviewing files that changed from the base of the PR and between 05269d9a94b5a9984eacd1ac4ef9c0e46344febf and a7b9a5f.

📒 Files selected for processing (9)
  • mobile/src/components/HostProtocolGate.test.ts
  • mobile/src/session/MobileSessionActiveContent.tsx
  • mobile/src/session/TerminalEnginePrewarm.test.ts
  • mobile/src/session/TerminalEnginePrewarm.tsx
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-session-startup-source.test.ts
  • mobile/src/session/terminal-prewarm-frame-geometry.test.ts
  • mobile/src/session/use-mobile-session-foundation.ts
  • mobile/src/transport/host-status-gates.ts

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

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@Jinwoo-H have exceeded the limit for the number of chat messages per hour. Please wait 34 minutes and 42 seconds before sending another message.

@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 — a rebase onto main (which reverted #19258's cached-reconnect strip via #19265) required dropping the reconnect branch and realigning the tab-bar reservation from tabStripRows back to visibleTabs.

  • Dropped the reconnectViewState / tabStripRows plumbing from MobileSessionActiveContent — the reconnect-with-cache branch and the tabStripRows-based reservation are gone; the content reads visibleTabs again, matching the header's own visibleTabs.length > 0 mount condition.
  • Re-aligned the frame-geometry test — the "mounts the tab bar only once a tab is visible" assertion and the reservation complement now pin visibleTabs on both the header and the content, so the two cannot drift.
  • Re-derived the route-parity hashes/counts — the extraction-parity snapshots were recomputed after the branch removal.

The compatVerified gate, the pre-warm init/awaitReady + textScale handoff, and the shared single status.get probe are unchanged from the prior review. Header (visibleTabs.length > 0) and content (visibleTabs.length > 0 ? 0 : MOBILE_SESSION_TAB_BAR_HEIGHT) are consistent, so the reservation remains correct against the rebased base. The five touched test files pass (45 tests).

…med terminal engine

Startup RPCs now fan out in parallel and the xterm engine pre-warms inside the
real terminal frame while they are in flight, so the first pane inherits a warm
WebView and an already-measured viewport instead of paying a round trip for it.

The pre-warm opens its engine before measuring: web-ready only reports that the
bundle loaded, and the WebView answers a measure with null until a terminal
exists. It also pre-warms at the user's saved text size, because cell size is
what the frame height gets divided by.

Host writes such as worktree.activate wait for an evaluated status.get reply.
Navigation still fails open when a host cannot answer one, but that fallback no
longer reads as a passing compatibility verdict.
@Jinwoo-H
Jinwoo-H force-pushed the mobile/session-startup-parallel branch from a7b9a5f to f799992 Compare September 7, 2026 10:01

@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 — the delta since the prior pullfrog review: the pre-warm defers its frame-height read until the engine is ready, and a regression test pins the resize-during-startup case.

  • Deferred the height read to handoff — TerminalEnginePrewarm now reads frameHeightRef.current inside the awaitReady continuation instead of snapshotting it before engine.init, so a rotation or split-screen resize that lands while the engine is coming up is the height the one-shot measurement reports.
  • Added a failing-first resize regression test — TerminalEnginePrewarm.test.ts drives layout → web-ready → resize → engine-ready and asserts the measured height is the post-resize frame, which fails against the pre-change capture-then-init ordering.

The fix is correct: handleLayout keeps writing frameHeightRef.current on every non-zero layout even after the measuredRef latch fires, so the deferred read always sees the pane's final frame, and the unmount guard (engineRef.current !== engine) still drops stale handoffs.

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

@Jinwoo-H
Jinwoo-H merged commit c374132 into main Sep 7, 2026
29 checks passed
@Jinwoo-H
Jinwoo-H deleted the mobile/session-startup-parallel branch September 7, 2026 17:16
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
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.
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