Repository navigation
perf(runtime): withhold unchanged mobile snapshots from the graph payload - #12245
Conversation
…load Every graph sync structured-cloned all 222 worktree snapshots to main even when none had changed: 374 KB and ~5 ms per clone, paid twice because Electron clones on serialize and again on deserialize. That transport cost — not the renderer rebuild — is the bulk of a publication. The renderer now sends only the snapshots main has not acknowledged and names the rest in unchangedMobileSessionWorktrees. Detection is object identity, not a deep compare: an unchanged worktree already returns its cached snapshot object. Main seeds nextWorktrees from that list so its prune keeps withheld worktrees live instead of removing them. The call itself is unconditional. syncWindowGraph is not a one-way publish — its return value is the only channel carrying agentOrchestrationByPaneKey to the renderer, and the handler adopts pre-allocated handles, merges detached leaves, refreshes writable flags, and drains graph-sync callbacks on every sync. Skipping it would starve all of that. Two failure modes are closed explicitly. The memo advances only after main acknowledges, so a publication that throws is resent in full rather than silently withheld forever. And a worktree main dropped on its own — worktree metadata removal — comes back in mobileSessionResyncWorktrees, which also clears the accepted-revision record so the republish is not rejected as a no-op. Unchanged republish at 222 worktrees / 787 tabs: 374 KB to 3.4 KB, 5.08 ms to 0.02 ms per clone. One changed worktree: 5.3 KB.
5081a12 to
b3f79d6
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe renderer now tracks acknowledged mobile session snapshots and publishes only changed worktrees. It sends unchanged worktree IDs separately. Main preserves those snapshots, validates accepted publication metadata and tab identities, and reports worktrees that require republishing. Worktree deletion clears accepted snapshot state. Tests cover partitioning, retries, resynchronization, stale-tab pruning, retirement fences, and legacy behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
Post-merge Electron validation — 2026-08-03
Validation gap: the offered Windows remote was not discoverable from either validation surface. The merged dev profile reported 0 hosts and no runtime environments; the installed runtime exposed one Linux SSH workspace and no Windows host. Windows packaging CI passed, but this run does not claim live Windows-remote validation. No mobile emulator run was warranted because the merged diff contains no mobile/ or mobile UI changes. |
…load (stablyai#12245) * perf(runtime): withhold unchanged mobile snapshots from the graph payload Every graph sync structured-cloned all 222 worktree snapshots to main even when none had changed: 374 KB and ~5 ms per clone, paid twice because Electron clones on serialize and again on deserialize. That transport cost — not the renderer rebuild — is the bulk of a publication. The renderer now sends only the snapshots main has not acknowledged and names the rest in unchangedMobileSessionWorktrees. Detection is object identity, not a deep compare: an unchanged worktree already returns its cached snapshot object. Main seeds nextWorktrees from that list so its prune keeps withheld worktrees live instead of removing them. The call itself is unconditional. syncWindowGraph is not a one-way publish — its return value is the only channel carrying agentOrchestrationByPaneKey to the renderer, and the handler adopts pre-allocated handles, merges detached leaves, refreshes writable flags, and drains graph-sync callbacks on every sync. Skipping it would starve all of that. Two failure modes are closed explicitly. The memo advances only after main acknowledges, so a publication that throws is resent in full rather than silently withheld forever. And a worktree main dropped on its own — worktree metadata removal — comes back in mobileSessionResyncWorktrees, which also clears the accepted-revision record so the republish is not rejected as a no-op. Unchanged republish at 222 worktrees / 787 tabs: 374 KB to 3.4 KB, 5.08 ms to 0.02 ms per clone. One changed worktree: 5.3 KB. * fix(runtime): resync stale withheld mobile snapshots * fix(runtime): align accepted mobile snapshot membership --------- Co-authored-by: Brennan Benson <[email protected]>

Summary
Every renderer graph sync structured-cloned all of the user's worktree mobile-session snapshots to the main process, whether or not any had changed.
Measured on a synthetic profile matching the reported crash telemetry (222 worktrees, 787 tabs, 787 terminal layouts):
structuredCloneElectron clones on serialize and again on deserialize, so the real cost is roughly double the figure above. This transport cost — not the renderer-side rebuild, which is ~1 ms after #12207 — is the bulk of a publication.
The renderer now sends only snapshots main has not acknowledged, and names the rest in a new
unchangedMobileSessionWorktreeslist. Main seedsnextWorktreesfrom that list so its prune treats withheld worktrees as live rather than removed.The IPC call itself stays unconditional.
syncWindowGraphis not a one-way publish: its return value is the only channel carryingagentOrchestrationByPaneKeyto the renderer (sync-runtime-graph.tsholds the sole caller ofsetRuntimeAgentOrchestrationByPaneKey, and no event channel exists), and the handler adopts pre-allocated handles, merges detached leaves, refreshes writable flags, and drains graph-sync callbacks on every sync. Skipping the call when the graph looks unchanged would starve all of that — the renderer cannot know what main has to deliver. Only the payload shrinks.Two failure modes this design creates, both closed explicitly
removeWorktreeMetadataAndHistory) would otherwise never come back, because the renderer believes it is already delivered. Main now returns those inmobileSessionResyncWorktrees, which also clears the accepted-revision record so the republish is not rejected by the accept gate as a no-op.Screenshots
No visual change.
Testing
pnpm exec oxlinton every changed filepnpm run typecheck:webpnpm run typecheck:nodepnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/— 58 files / 564 tests passpnpm exec vitest run --config config/vitest.config.ts src/main/runtime/— 213 files pass; 6 failures inorca-runtime-files.test.tsandrpc/methods/ai-vault.test.tsare pre-existing Windows path-separator assertions (expected [ '\ctor\codex\home\sessions' ] to include '/ctor/codex/home/sessions'), reproduced identically on the base commit with this change stashedsync-runtime-graph— 9 files / 780 tests passpnpm test(the wrapper) cannot run in this environment —windows-native-registryfails to rebuild — so vitest was invoked directly.New tests
src/renderer/src/runtime/sync-runtime-graph-payload-partition.test.tssrc/main/runtime/graph-sync-payload-partition.test.tsNegative controls: reverting the ack gate fails 3 of the renderer tests; reverting the
nextWorktreesseed fails 2 of the main tests.AI Review Report
Reviewed the renderer/main contract for staleness risk, since a false "unchanged" silently publishes stale tabs to paired clients.
Checked and resolved:
RuntimeSyncWindowGraphResultand every side effect in the main handler before concluding the call must stay unconditional. This is why the PR shrinks the payload rather than skipping the sync.nextWorktreesbefore the prune loop, and a test asserts a worktree omitted from both lists is still pruned and still emits its removed frame.await, insidetry, so a rejection leaves it untouched.acceptedRendererMobileSnapshotByWorktree, otherwise a republish at the same(epoch, version)is discarded and the worktree never recovers.src/main/index.tsheadless sync) keeps its exact previous behavior, covered by a test.Cross-platform: no platform-dependent behavior added — no paths, shell invocation, shortcuts, or labels. The change is plain data structures over existing IPC, identical on macOS, Linux, and Windows.
Security Audit
No new IPC surface: two optional fields on an existing authenticated channel.
unchangedMobileSessionWorktreescarries worktree ids that main already holds, and it can only ever retain an existing entry — it cannot inject, mutate, or resurrect snapshot content, so a malformed list cannot forge tabs. Unknown ids fall through to the resync path rather than creating state.mobileSessionResyncWorktreesonly deletes renderer-local memo entries, whose worst case is a redundant full republish. No input parsing, command execution, path handling, auth, secrets, or dependency changes.Notes
main; this follow-up now targetsmaindirectly and relies on its reference-identical unchanged snapshots.Final merge-readiness review — 2026-08-03
Reviewed exact stacked range
27d470c2ac645cbcd4cf75c087ce6b3dc771a49d...5081a12ac2f044725939fa7eb63f22a461611658. The final independent review returned CLEAN. GitHub reports a clean merge state and 42 completed checks with zero failures, including Windows packaging. The final focused run covered 18 files and passed 1,158 tests with one skip; typecheck, lint, format, max-lines, diff/reference cleanliness, and negative controls also passed.Meaningful fixes found during review
6e369e6c37: withheld publications skipped same-revision preservation reconciliation. Removed serve/SSH tabs could remain stale, while headless hydration could mask a renderer snapshot dropped by main. The fix tracks accepted renderer membership and requests targeted resyncs; regressions cover both paths.5081a12ac2: accepted membership metadata used rawsnapshot.tabseven when retirement fencing removed tabs before storage. Every later withheld publication could therefore request another full resync. Metadata now usesfencedSnapshot.tabs; a negative control proves two consecutive withheld publications no longer resync.Statistical benchmark
Identical SHA-256-verified uncommitted harness at baseline
3658165119, #12207 at27d470c2ac, and the combined stack at5081a12ac2. Each target used three independently started, rotated rounds with 50 warmups and 150 measured samples per round: 450 measured samples per target per metric. Values aremedian / p95 [bootstrap 95% CI for median].structuredCloneThe combined stack reduces median scheduled-publication time 90.5% and payload size 94.7% versus baseline. Compared with #12207 alone, this PR reduces scheduled time 82.5%, clone time 96.5%, and payload 94.7%. Its 0.003 ms direct-build bookkeeping overhead is dwarfed by the transport reduction.
Every measured iteration changed exactly one status. Baseline and #12207 published all 222 snapshots; the combined stack published the changed worktree and withheld the other 221. Payload content preserved the changed status, and there were zero measured publication failures.
Raw local artifacts remain uncommitted in the dedicated benchmark worktree under
.benchmarks/mobile-session-publication/(report.md,summary.json,execution.json, andraw/*.json). Absolute wall times should be treated cautiously because an unrelated two-day-old Node/Vite repro remained at approximately one logical CPU throughout; rotated commit order, independent processes, warmups, and confidence intervals reduce but cannot eliminate that host-load noise. The relative effects are large and consistent.Validation gaps and merge order
main.low spec windowsenvironment was unavailable:remote_runtime_unavailable: Could not connect to the remote Orca runtime.Windows packaging CI passed.$electron,$perf, and$orca-mobile-emulator-qawere unavailable. This is not a visual change, so no screenshots were fabricated and no prohibited OS-level UI automation was substituted.