Repository navigation
Agent status changes no longer rebuild the workspace's tab list each time - #46246
Conversation
…nt flush, skip it with no listener
…nly for listeners or client reads
…ries new content at a seen version
Perf scan: PR #46246 (session-tabs status deferred store)Head Verdict: cleanI found no regression. Total snapshot stores are less than or equal to base on every path. The new per-worktree state has a fixed upper bound. No gate was removed, and the change adds no idle wakeups (under load with no listener it removes timers). FindingsNone introduced or amplified by the PR. Hot-path traces1. Status/title touch (the touched hot path)Trigger:
Rate at the reference fleet: more than 1 status/s per agent, 100+ agents, plus title spinners.
Owner and thread: the runtime singleton on Electron main. The new contract test ( 2. Paying an owed bump (
|
| State | Listeners | Base sends | Head sends | Base stores | Head stores | Coalescer timers |
|---|---|---|---|---|---|---|
| Steady idle, no status changes | 0 (terminal-only user) or 1 (structured chats) | 0 | 0 | 0 | 0 | 0 in both: idle wakeups/s on main are 0 before and after |
| Load, no listener (terminal-only fleet: 100+ agents at more than 1 status/s, title spinners) | 0 | 0 | 0 | one per touch, ≥100/s, on main | 0 | base armed a 50 ms timer per touched worktree, up to 20/s per worktree; head arms none |
| Load, 200 streaming chats | 1 desktop subscribeAll + k mobile/remote |
one frame per touched worktree per flush window (≤20/s per worktree, 4/s at max wait); each frame projected once and delivered to every matching listener | same frame count; version bumps by +1 per frame instead of +N | one per touch | one per worktree per flush window | unchanged |
Frames per window are bounded by touched worktrees, not by the fleet.
Regression classes touched
| Class | Disposition |
|---|---|
| Update published when nothing changed | Matched (version bump with no content change). Disproved as a regression: base also bumped once per touch. Head bumps less often and only to invalidate status rows that the stored snapshot doesn't carry. Clients drop same-version re-emits. |
| One change published as a whole snapshot | Matched. The behavior predates this PR (see pre-existing #1). Head does not increase the count. |
| Hidden or unheard owners keep working | Matched and improved: the store and the coalescer no longer run with no listener. |
| New idle wakeups | Matched: no new timer or subscription. 0 before and after at idle, and fewer under load. |
| Per-entity state outlives the entity | Matched (new per-worktree maps). Disproved: delete/clear overrides drop the entries, and their keys are a subset of the map's. |
| No-op store write returns new identities | Matched (pay store). The pay creates a new identity only when owed, at most once per owe, compared with once per touch in base. |
| Fixed-cadence poll | No matching code. The heartbeat is unchanged and gated on listeners. |
| Expensive code past a gate | No gate was removed. |
Six questions
- Unused work paid before the skip gate: reviewed. Base stored on every touch with no consumer. Head defers the store until a consumer projects it, and gates the coalescer on listeners.
- Ownership multiplying work: reviewed. One owe per worktree, one pay per owe, one frame per worktree per window, fanned out to listeners as in base.
- Thread and storage layer: Electron main, in-memory only (no SQLite or fs on this path). Per-touch cost drops from O(tabs) to O(1).
- Growth and progress: reviewed. The maps are bounded by stored workspaces (see above). Owes always lead to a scheduled flush when a listener exists, so frames always move forward.
- Execution host: not applicable. This is in-process logic, the same on all platforms and on remote runtimes (which run the same runtime class).
- Obsolete work stopping: reviewed. Superseded queued frames are dropped, not re-projected. Owe and mark entries are dropped on delete/clear.
Pre-existing amplification (not a regression of this PR)
- Whole-workspace projection per status flush.
notifyMobileSessionTabsChangedNowprojects the full workspace snapshot for one status-row change:titleStructuredConversationTabs, favicon inlining, bot-home pins and sender associations.subscribeAllthen runsisDeepStrictEqualon the whole projected snapshot for each change (session-tabs-inventory.tspublishChange). Cost is O(tabs) per touched worktree per flush window, per listener. The count is unchanged by this PR. structuredConversationTabNameper agent-session tab per projection. It runsgetWorkspaceSessionForWorktree(...).unifiedTabs[...].find(...)for each tab, so each projection costs O(tabs × unifiedTabs) per workspace. It runs on every flush projection above. Unchanged by this PR.- Dropped queued desktop frames. A queued desktop frame is dropped whenever the source changes before its microtask, and the successor flush re-projects. Base dropped on every touch-store. Head drops on every owe, so the rate is the same.
Evidence
- Reproduced:
vitest run status-session-tabs-store.performance.test.ts pty-title-mobile-fanout.performance.test.tspassed at head, 2/2. - Source-proven: every store count above comes from reading the code. No runtime timing or heap measurement was taken.
- Not measured (one-time cost): the concentrated census pay at fleet N.
Residual gaps
- The per-store cost (µs) at fleet tab counts was not timed.
- The (re)subscribe-time pay burst was not profiled on a 1,900-workspace profile.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Review statusProblem. Each time an agent's status or a terminal title changed, Orca's main process immediately rebuilt that workspace's whole tab list for phones and remote windows, even when nobody was connected. With many chats streaming in one workspace this was a large, fast-growing source of memory churn. User-facing change. None visible. Phones and remote windows get the same updates, built once per update window (50-250 ms) instead of once per status change; with nothing connected, nothing is built until a client asks. Verified
Benchmark: head=1a1939115aa6fe9df629fc0d966ca14977ba40fe gate=PASS name=session-tabs-store-alloc-200-streaming base=753a25b9f28 base_store_alloc=112.5,118.9MB/30s head_store_alloc=29.5,29.9MB/30s base_total=48.5,54.6MB/s head_total=50.9,52.1MB/s profile=1900-workspaces listeners=desktop-renderer(session.tabs) host=linux Fixed during review (earlier audits on intermediate heads)
Deferred (not blocking, P2)
|
Perf scan (3): PR #46246, session-tabs status deferred storeHead Verdict: cleanNo perf finding is introduced or amplified. On every path I traced, head does no more snapshot stores, frames or timers than base:
FindingsNone (no P0 or P1). Surface 1: hot-path (
|
| Base | Head | |
|---|---|---|
Map lookup + heartbeat observeWorktreeRefresh |
yes | yes (unchanged) |
storeMobileSessionSnapshot |
every touch. The store runs reconcileChatTabIdentities, preserveTerminalRetirementProofs, stampMobileSnapshotVersion, the reverse-index set (reindex skipped because tabs keeps its identity), the saved-title tabs.some and labelChanges.seed (early return once seeded). O(tabs), plus a new snapshot object |
none on the non-immediate path. oweVersion does one Set.add and one Map.set: O(1) |
Coalescer schedule (clear + arm a 50 ms timer, 250 ms max wait) |
every touch, even with 0 listeners. The flush then returned at notifyMobileSessionTabsChangedNow's size === 0 check |
only when mobileSessionTabListeners.size > 0 (line 74) |
Consumers. None on this path. It is a write-side owe. Consumers appear at the projection (surface 3).
Bound at fleet scale. Per-touch cost drops from O(tabs) to O(1). The walk is independent of the number of workspaces: the touch addresses one workspace by key. The adjusted contract pty-title-mobile-fanout.performance.test.ts now includes a listener and the flush inside the measured window, and still asserts 0 reads of other workspaces' tabs at N=200 and 2,000. That makes it stricter than on base.
Immediate path and key-spelling mismatch. These still take the unchanged base branch (store, then notify or schedule).
Grade. An improvement over base, not a finding.
Surface 2: publish (line 75, scheduleMobileSessionTabsChanged)
What changed. The call is now behind a listener gate on the status path. With a listener, the schedule and coalescer behavior match base: one pending sequence per workspace, a trailing 50 ms timer re-armed per touch, and a synchronous fire once 250 ms of max wait has passed. Each fire runs one notifyMobileSessionTabsChangedNow, which makes one whole-workspace projection, one delivery pass, and one frame per matching listener.
Listener census. Entries in mobileSessionTabListeners come only from onMobileSessionTabsChanged, which has two RPC callers:
| Listener | Source | Present when |
|---|---|---|
| Local desktop renderer | session.tabs.subscribeAll (local-structured-session-tabs-sync/subscription.ts) |
the renderer is ready and structured chats are in use (use-local-structured-session-tabs-sync.ts). A terminal-only user has none. |
| Web client | subscribeAll (web-session-tabs-sync/.../global-session-subscription.ts) |
a web client is connected |
| Paired mobile app | session.tabs.subscribe (session-tabs.ts:251) per open workspace, or subscribeAll |
a phone is connected |
| Desktop attached to a remote runtime | subscribeAll on the remote host |
a remote host is attached |
Non-mobile listeners take the queued microtask delivery path (mobile-session-tabs-delivery.ts:106-120). Mobile-only deliveries are synchronous.
Send rate.
| State | Listeners | Base frames/s | Head frames/s | Base stores/s | Head stores/s | Base timer wakeups/s | Head timer wakeups/s |
|---|---|---|---|---|---|---|---|
| Steady idle (no status, title or heartbeat events) | 0 or 1 desktop renderer | 0 | 0 | 0 | 0 | 0 | 0 |
| Load, terminal-only fleet (100+ agents, more than 1 status/s each; spinners) | 0 | 0 | 0 | 1 per touch (several hundred/s) | 0 | ≤20/s per touched workspace (≤min(touch rate, 20); 4/s under a continuous stream) | 0 |
| Load, 200 streaming chats, desktop renderer subscribed (+k mobile/remote) | 1 + k | ≤min(touch rate, 20/s) per touched workspace, 4/s at max wait; ≤200 workspaces | same | 1 per touch | 1 per flush per workspace (≤ frames) | same as frames | same as frames |
- Frames per window. These are bounded by the number of workspaces touched in that window, not by fleet size.
- Frames per flush. Each listener whose worktree filter matches gets one frame per flush, as on base.
- Dedupe.
subscribeAllrunsisDeepStrictEqualagainst the last published state before emitting. The frame carries a bumpedsnapshotVersion, so a status-only flush still emits. That is the same on base, which bumped once per touch.
Late subscribe. onMobileSessionTabsChanged calls flushAll() before adding the listener. With no prior listener nothing is pending, so the drain is a no-op. The subscribe census then projects every stored snapshot and pays the owed bumps (surface 3).
Queued-frame drop. A queued desktop frame is dropped when deliverySource changes before its microtask runs. On head, a new owe or a non-paying store changes the source. On base, any touch-store changed it.
- An owe cannot land inside the microtask gap unless it is synchronous within the same task. That case also dropped on base.
- Each owe made while a listener exists schedules a successor flush, so progress is preserved without a retry loop.
- A pay keeps its delivery mark, so a frame never invalidates itself.
Grade. The send rate with listeners equals base. The no-listener timer churn is gone. There are no new idle wakeups.
Surface 3: version-bump (line 104, settleOwedMobileSessionSnapshotVersion)
Trigger. Every toMobileSessionTabsResult call, via prune-mobile-session-tab-group-layout.ts:92. The callers are:
- the coalesced or immediate flush (listener-gated)
- the subscribe census (
notifyMobileSessionTabSnapshots,collectMobileSessionTabsFrames) - single-workspace get and subscribe RPCs
- tab activation (
perform-mobile-session-pty-records-refresh.ts:168) - headless close and group moves
- browser-tab reconcile
- mobile terminal surface lookups (
mobile-terminal-surface.ts:79,105). These are reached from terminal create and close, and from graph-sync callbacks while a create waits under its timeout.
None of these runs on a timer or per PTY chunk.
Work per event.
- Nothing owed. One
Map.getidentity check, plus oneSet.deletewhen the projected object is the stored one. O(1). - Bump owed. One
storeMobileSessionSnapshot. This is the same function and cost base ran on every touch. - No double pay. The owe is deleted before
pay()runs (mobile-session-snapshots-by-worktree.ts:48-50), so a re-entrant projection cannot pay twice. The store does not project, so the pay cannot recurse.
Bound. Pays ≤ owes ≤ touches, and base stored once per touch. So total stores on head are ≤ base on every path:
- Plain owe: 1 pay against N base stores.
- Owe, then a structural store at a higher version: the owe is cleared, so 1 store against 2.
- Owe, then an inventory-only store (the version is kept): 1 store + 1 pay against 2.
- Main-layout no-op return: 1 against 1.
Concentration (one-time, not a finding).
- Where owes build up. With no listener, owes accumulate across workspaces whose status changed since their last store. That is at most the stored-snapshot count: about 1,900 at the reference fleet, and about 19k at 10x.
- Where they are paid. The next census pays all of them in one RPC, one O(tabs) store per workspace. That RPC already makes one O(tabs) projection per workspace (favicon inlining, titles, senders), so its cost at most roughly doubles, once per (re)subscribe.
- Why it is not a regression. Base had already paid at least that many stores earlier, one per touch. Owes do not accumulate while a listener exists, because each flush pays its own.
- Not timed.
Rest of the diff
These are the earlier scan's conclusions, re-checked.
-
mobile-session-snapshots-by-worktree.ts: confirmed.owedVersionsanddeliveryMarksare written only byoweVersion. That runs only aftermobileSessionTabsByWorktree.get(worktreeId)returns a snapshot whoseworktreematches, so both sets of keys are a subset of the map's keys.- The
deleteandclearoverrides drop both. A non-payingsetdrops the mark. - Bound: stored workspaces × (key ref + number), at most a few hundred KB at 1,900 and at most about 2 MB at 19k. It does not grow with time or with the number of touches.
- Iterating with
values()while a pay callsseton an existing key neither reorders nor revisits entries.
-
session-tabs-change-publication.ts,sourcechanged todeliverySource: confirmed. The lookup is O(1), read once at enqueue and once at dequeue. -
prune-mobile-session-tab-group-layout.ts: confirmed. It wraps the projection with the O(1) settle described in surface 3. -
Tests: confirmed.
- The new
status-session-tabs-store.performance.test.tschecks N=20 and N=200 touches over 2 workspaces: 0 stores with no listener, and 2 stores (one per workspace) with a listener. It hardcodes the expected counts. On base the touch path stores 2N in both cases, so the test fails on base (source-proven; I did not run it on base). - Head run, reproduced: both perf contracts pass (2/2).
- The new
-
Corrections to the earlier scan.
- Thread. It named only Electron main. The same runtime class also runs in the headless backend on remote hosts, where the listeners are attached desktops. The counts are identical there.
- Grading line. Its closing line reported
surfaces=none. This report grades the three detector surfaces explicitly. - Base timer rate. Its "up to 20/s per worktree" for base timers holds only when touches arrive more than 50 ms apart. Under a continuous stream the trailing re-arm plus the 250 ms max wait gives 4 fires/s, with a clear-and-arm per touch.
No conclusion changes.
Regression classes touched
| Class | Disposition |
|---|---|
| Update published when nothing changed | Matched: +1 at line 104. Disproved: one bump per owe, and an owe is made only by a status/title touch whose projected rows (status, titles) the stored snapshot doesn't carry. Base bumped once per touch. |
| New wakeups in steady idle | Matched (coalescer schedule). Disproved: no new timer, poll or IPC; 0/s idle before and after. Under load with no listener, wakeups drop to 0. |
| Hidden or unheard owners keep working | Matched and improved: the store and coalescer no longer run with no listener. |
| No-op store write returns new identities | Matched (pay store). A pay creates a new identity at most once per owe, against once per touch on base. |
| Per-entity state outlives the entity | Matched (two new keyed collections). Disproved: they are cleared on delete/clear and their keys are a subset of the snapshot map's. |
| One change published as a whole snapshot | Matched, pre-existing: a whole-workspace projection per flush. The count is unchanged. |
| Expensive code past a gate | No gate was removed or loosened. A listener gate was added. |
Six questions
- Unused work paid before the skip gate. Reviewed. Base stored on every touch with no consumer. Head stores only when a projection reads the snapshot.
- Ownership multiplying work. Reviewed. One owe per workspace, one pay per owe, one projection per flush, frames fanned out per listener as on base.
- Thread and storage layer. The runtime main thread (Electron main or the headless backend). All of it is in memory: no SQLite, fs or subprocess on these paths.
- Growth and progress. Reviewed. The collections are bounded by stored snapshots. With a listener, each owe schedules a flush; with none, the census pays.
- Execution host. Not applicable beyond point 3. This is in-process logic with identical behavior on mac, linux, windows and remote hosts.
- Obsolete work stopping. Reviewed. Superseded queued frames are dropped and never re-projected. Owe and mark entries are released on delete and clear. Unsubscribing the last listener stops scheduling.
Pre-existing amplification (not a regression of this PR)
- Whole-workspace projection per status flush. Each flush projects the entire workspace (favicons, titles, senders), and
subscribeAllthen deep-compares it: O(tabs) per touched workspace per flush window, per listener. The count is unchanged. - Per-tab title lookup.
structuredConversationTabNameruns aunifiedTabs.findper agent-session tab, so each projection is O(tabs × unifiedTabs). Unchanged.
Evidence
- Reproduced: the two perf contracts pass at head.
- Source-proven: every store, frame and timer count above.
- Not measured: wall time per store at fleet tab counts, and the one-time census pay at 1,900 workspaces. No timing, CPU or heap claims are made.
…tabs-status-deferred-store # Conflicts: # src/main/runtime/session-lifecycle/projection/prune-mobile-session-tab-group-layout.ts
ELI5
When an agent's status changes (thinking, running a tool, done), Orca rebuilt a full copy of that workspace's tab list right away, every single time, even when no phone or remote window was connected to look at it. With many chats streaming this created a lot of short-lived garbage and a memory spike. Now Orca just notes "this workspace needs a newer version" and builds the copy once, only when someone is actually listening.
What Changed
immediate) refreshes are unchanged.Why
Measured on Linux with ~1,900 workspaces and 200 streaming chats in one workspace, these eager re-stores were the single largest source of main-process allocation (~130 MB per 30 s), which is what drives main's post-burst memory spike. Deferring to the flush that already exists keeps one code path for version stamping instead of adding a second cache.
Linked Issue
N/A (internal perf work).
Visual Proof
N/A: no UI change; phones and remote windows receive the same frames, just built once per flush window.
Testing
I manually tested these changes locally (Linux: A/B of built apps on a ~1,900-workspace profile, below)
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
New perf contract
status-session-tabs-store.performance.test.ts: N and 10N status refreshes across two workspaces store 0 times with no listener and exactly once per workspace (one version bump) with a listener. Reverting the change fails it (40 stores instead of 0).pty-title-mobile-fanout.performance.test.tsnow subscribes a listener and waits for the flush, since the bump lands there.Linux A/B on a ~1,900-workspace profile, exact builds of main and this PR (main, PR, PR, main). Fake Codex chats in one workspace, all streaming, with a 30 s allocation profile of the main process:
Performance
Less work: status bursts cost one snapshot store per workspace per flush window instead of one per status change, and none until a client reads when nobody listens. Measured: snapshot-store allocation in main -75% at 200 streaming chats (see Testing). The deferred store moves to the first read; it is at most one store per owed bump, so total stores never exceed main's.
Risk
The riskiest part is version ordering for clients: a client must never see changed content at a version it already has. Every projection pays the owed bump first, any other store that advances the version clears it, and queued frames still drop when a newer status arrives (paying a bump does not count as a change). If something went wrong a paired phone or remote window could miss a status update until the next change. Plain revert backs it out.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)