Skip to content

perf(runtime): withhold unchanged mobile snapshots from the graph payload - #12245

Merged
brennanb2025 merged 3 commits into
mainfrom
neil/graph-sync-payload-partition
Aug 4, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
neil/graph-sync-payload-partition

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Builds on merged #12207. This PR now targets main; the partition below relies on the reference-identical unchanged snapshots introduced there.

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):

Payload structuredClone
Before, every sync 374 KB 5.08 ms
After, unchanged republish 3.4 KB 0.02 ms
After, one worktree changed 5.3 KB 0.04 ms

Electron 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 unchangedMobileSessionWorktrees list. Main seeds nextWorktrees from that list so its prune treats withheld worktrees as live rather than removed.

The IPC call itself stays unconditional. syncWindowGraph is not a one-way publish: its return value is the only channel carrying agentOrchestrationByPaneKey to the renderer (sync-runtime-graph.ts holds the sole caller of setRuntimeAgentOrchestrationByPaneKey, 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

  1. A publication that throws must not count as delivered. The last-sent memo advances only after main acknowledges, so a failed publication is resent in full instead of being withheld forever as "already sent".
  2. A worktree main drops on its own (removeWorktreeMetadataAndHistory) would otherwise never come back, because the renderer believes it is already delivered. Main now returns those in mobileSessionResyncWorktrees, 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 oxlint on every changed file
  • pnpm run typecheck:web
  • pnpm run typecheck:node
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/runtime/ — 58 files / 564 tests pass
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/ — 213 files pass; 6 failures in orca-runtime-files.test.ts and rpc/methods/ai-vault.test.ts are 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 stashed
  • All out-of-directory importers of sync-runtime-graph — 9 files / 780 tests pass
  • Added tests, and verified each fails without the change

pnpm test (the wrapper) cannot run in this environment — windows-native-registry fails to rebuild — so vitest was invoked directly.

New tests

src/renderer/src/runtime/sync-runtime-graph-payload-partition.test.ts

  • withholds every unchanged worktree from a republish
  • publishes only the worktree whose snapshot changed
  • republishes a changed worktree whose publication threw before it was acknowledged
  • resends everything when the first publication throws
  • republishes worktrees main reports it dropped after acknowledging them
  • drops a removed worktree from both the payload and the withheld list

src/main/runtime/graph-sync-payload-partition.test.ts

  • keeps a withheld worktree alive instead of pruning it as removed
  • still prunes a worktree the renderer omits from both lists
  • asks for a republish of a withheld worktree it dropped, and accepts the resend
  • leaves the legacy full-payload contract untouched when no list is sent

Negative controls: reverting the ack gate fails 3 of the renderer tests; reverting the nextWorktrees seed 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:

  • Return-value starvation — audited every field of RuntimeSyncWindowGraphResult and 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.
  • Prune correctness — the withheld list is folded into nextWorktrees before the prune loop, and a test asserts a worktree omitted from both lists is still pruned and still emits its removed frame.
  • Ack ordering — the memo commit sits after await, inside try, so a rejection leaves it untouched.
  • Accept-gate interaction — a resync clears acceptedRendererMobileSnapshotByWorktree, otherwise a republish at the same (epoch, version) is discarded and the worktree never recovers.
  • Version-skew — renderer and main ship in one build, so there is no mixed-version path; a renderer reload resets the module memo and forces a full resend. The new fields are optional, and a caller that sends neither (src/main/index.ts headless 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. unchangedMobileSessionWorktrees carries 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. mobileSessionResyncWorktrees only 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

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 raw snapshot.tabs even when retirement fencing removed tabs before storage. Every later withheld publication could therefore request another full resync. Metadata now uses fencedSnapshot.tabs; a negative control proves two consecutive withheld publications no longer resync.

Statistical benchmark

Identical SHA-256-verified uncommitted harness at baseline 3658165119, #12207 at 27d470c2ac, and the combined stack at 5081a12ac2. 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 are median / p95 [bootstrap 95% CI for median].

Metric Baseline #12207 Combined through #12245
Direct snapshot build 1.382 / 2.053 ms [1.341, 1.421] 0.135 / 0.189 ms [0.1348, 0.1360] 0.138 / 0.218 ms [0.1373, 0.1399]
Scheduled publication, excluding the deliberate 16 ms coalescing delay 2.913 / 3.929 ms [2.860, 2.967] 1.581 / 1.851 ms [1.575, 1.588] 0.277 / 0.379 ms [0.2758, 0.2792]
structuredClone 1.369 / 1.873 ms [1.363, 1.381] 1.329 / 1.436 ms [1.327, 1.332] 0.0466 / 0.0529 ms [0.0465, 0.0468]
Payload bytes 933,388 933,386 49,631

The 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, and raw/*.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

@brennanb2025
brennanb2025 marked this pull request as ready for review August 3, 2026 18:41
@brennanb2025
brennanb2025 changed the base branch from neil/oom-remote-session-partition to main August 3, 2026 19:10
OrcaWin and others added 3 commits August 3, 2026 12:13
…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.
@brennanb2025
brennanb2025 force-pushed the neil/graph-sync-payload-partition branch from 5081a12 to b3f79d6 Compare August 3, 2026 19:14
@coderabbitai

coderabbitai Bot commented Aug 3, 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: Pro Plus

Run ID: 7758f671-0ec9-48c8-b0db-7eaf90219bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 34291f0 and b3f79d6.

📒 Files selected for processing (5)
  • src/main/runtime/graph-sync-payload-partition.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/runtime/sync-runtime-graph-payload-partition.test.ts
  • src/renderer/src/runtime/sync-runtime-graph.ts
  • src/shared/runtime-types.ts

📝 Walkthrough

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes withholding unchanged mobile snapshots from the graph payload.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and notes sections with detailed validation results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 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.

@brennanb2025
brennanb2025 merged commit ce8b778 into main Aug 4, 2026
42 checks passed
@brennanb2025

Copy link
Copy Markdown
Contributor

Post-merge Electron validation — 2026-08-03

pr-12245-electron-merged.png

  • Target: squash merge ce8b778, verified through the worktree-scoped merged dev identity.
  • Visible check: the full Orca surface remained rendered and usable after two real unchanged graph publications; the page reported 0 console errors.
  • Backing payload captured immediately before the real syncWindowGraph IPC: 0 changed snapshots and 4/4 worktrees withheld as unchanged. The partitioned graph was 1,981 bytes versus 48,655 bytes with the full snapshots, a 95.9% reduction.
  • Batched structuredClone measurement on that live payload: median 0.003 ms partitioned versus 0.049 ms full; p95 0.005 ms versus 0.064 ms.
  • Independent post-merge review returned CLEAN. Integrated checks passed: 13 partition tests, 13 terminal-retirement tests, node/web typechecks, diff-check, lint/format/max-lines gates, and adjacent headless/SSH coverage.

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.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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.

2 participants