Skip to content

Agent status changes no longer rebuild the workspace's tab list each time - #46246

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/session-tabs-status-deferred-store
Nov 21, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/session-tabs-status-deferred-store

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79

What Changed

  • Before: every non-urgent session-tabs refresh (agent status rows, terminal titles, favicons) re-ran the full snapshot store for the workspace (identity reconciliation, ordering, retirement proofs, a walk of every tab), then coalesced the outgoing frame. With nothing subscribed the store still ran.
  • After: a non-urgent refresh only marks the workspace's snapshot as owing one version bump. If a client is subscribed, the existing 50 ms / 250 ms coalesced flush pays the bump once (one store per workspace per window) and sends the frame. With no subscriber nothing is stored; the owed bump is paid the next time a frame for that workspace is built for any client (subscribe census, list, or a later change), so clients still always see a newer version for newer content. Any normal store that already advances the version clears the debt. Urgent (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.ts now 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:

    • Snapshot-store allocation in main: 112 / 119 MB per 30 s on main vs 30 / 30 MB on this PR at 200 chats (about -75%). At 20 chats: 2.0 / 2.2 MB vs 1.3 / 1.4 MB.
    • The status-refresh entry point itself: 120 MB vs 0.3 MB per 30 s.
    • Total main allocation (49-55 MB/s) and peak main RSS after the burst moved by less than run-to-run noise, because the desktop window always listens. So the saving here is "once per flush instead of once per update"; the "nothing when no one listens" part applies to headless hosts.

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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: PR #46246 (session-tabs status deferred store)

Head 1a1939115aa6fe9df629fc0d966ca14977ba40fe, base 753a25b9f28. Diff: 6 files, +155/-3. Production files: mobile-session-membership.ts, mobile-session-snapshots-by-worktree.ts, session-tabs-change-publication.ts, prune-mobile-session-tab-group-layout.ts. Two perf-contract tests (one new, one adjusted).

Verdict: clean

I 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).

Findings

None introduced or amplified by the PR.

Hot-path traces

1. Status/title touch (the touched hot path)

Trigger: touchMobileSessionTabsForWorktree without immediate, called from:

  • hook status row mutations (hook-status-session-tabs-republish.ts:43)
  • the PTY title/foreground fanout (pty-backed-session-publication.ts:203)
  • the stale-lease heartbeat (runtime-identity-state.ts:275; spaced 50 ms, only with listeners)
  • favicon inlining, title-authority changes, sender-scope refresh

Rate at the reference fleet: more than 1 status/s per agent, 100+ agents, plus title spinners.

Base Head
Work per touch storeMobileSessionSnapshot (reconcileChatTabIdentities + retirement proofs + stamp + Map set + saved-title tabs.some + labelChanges.seed, O(tabs)), then scheduleMobileSessionTabsChanged, which arms the 50 ms/250 ms coalescer even with zero listeners oweVersion: one Set.add and one Map.set, O(1). The coalescer is scheduled only if mobileSessionTabListeners.size > 0 (mobile-session-membership.ts:71-77)
Stores per worktree, with a listener one per touch one per flush window (at most 20/s trailing; 4/s at the 250 ms max wait under a steady stream)
Stores per worktree, no listener one per touch 0 until a projection reads that snapshot, then exactly 1

Owner and thread: the runtime singleton on Electron main.

The new contract test (status-session-tabs-store.performance.test.ts) passed locally. At N=20 and N=200 touches over 2 worktrees it checks 0 stores with no listener and 2 stores (one per worktree) with a listener. From the code, base does 2N stores in both cases, so the test fails on base.

2. Paying an owed bump (settleOwedMobileSessionSnapshotVersion, called from toMobileSessionTabsResult)

  • Every projection now runs an identity check, then owedVersions.delete. This is O(1) and adds no work when nothing is owed.

  • It stores only when get(worktree) === snapshot and a bump is owed. The owed flag is deleted before pay() runs, so a store can't re-enter and pay twice. One owe pays at most one store.

  • The store does not call back into a projection: stamp, ReverseIndexedMap.set (sameRefs on tabs identity skips the reindex) and the saved-title override never project.

  • Projection callers:

    • coalesced flush: one per worktree per window, listeners only
    • notifyMobileSessionTabSnapshots / collectMobileSessionTabsFrames: subscribe census, all stored worktrees
    • single-worktree subscribe/get RPCs
    • tab activation (perform-mobile-session-pty-records-refresh.ts:168)
    • headless close and group moves
    • mobile terminal surface reads

    Each of these is user- or client-driven or flush-driven. None runs on a timer.

3. Delivery source (deliverySource, session-tabs-change-publication.ts:74)

  • Read once when a desktop frame is queued and once when it is dequeued in the microtask. Each read is O(1).
  • A stale source drops the queued frame (mobile-session-tabs-delivery.ts, continue). It is never re-projected.
  • A new delivery mark on each owe drops a frame queued during the microtask gap. Base did the same, because each base touch stored a new snapshot object and changed the source.
  • Each owe made while a listener exists schedules a successor flush, so drops happen no more often than in base and cannot loop.
  • Paying keeps the mark, so a frame whose own projection paid the bump is not dropped. Without that, every desktop frame would be dropped. The rule is verified at mobile-session-snapshots-by-worktree.ts:66-74.

Can any path do more total snapshot stores than base?

No. I checked every path:

  • Plain touch: each owe stems from at least 1 touch, and base stored once per touch. Head stores at most once per owe, and only when a projection reads it.
  • Owe, then a structural store with a higher version: the owe is cleared, so no pay. 1 store, against base's 2.
  • Owe, then an inventory-only store (stampMobileSnapshotVersion keeps the version): the owe stays, so 1 + 1 pay = 2. Base also did 2.
  • Owe, then a main-layout no-op (store returns existing, no set; ORCA_LAYOUT_OWNER_IS_MAIN is off in shipped builds): 1 pay. Base: 1.
  • touch(immediate) or a key whose spelling doesn't match: the unchanged base branch.
  • Concentration (one-time, not a finding): with no listener, owed bumps build up across the worktrees that had a status change since their last store, at most the number of stored snapshots (≤1,900; ≤19k at 10x). The first session.tabs.subscribeAll census or full projection then pays up to that many stores in one RPC.
    • Each paid store is O(tabs), the same order as the projection that census already runs for every worktree. So the subscribe-time cost at most roughly doubles, once per (re)subscribe.
    • Base had already paid at least the same number of stores earlier, one per touch.
    • Not timed.

Unbounded growth in the new per-worktree maps?

No.

  • owedVersions (Set) and deliveryMarks (Map) are written only in oweVersion. That is reached only when mobileSessionTabsByWorktree.get(worktreeId) exists and snapshot.worktree === worktreeId (mobile-session-membership.ts:66-73), so their keys are always a subset of the map's own keys.
  • The overridden delete and clear drop both. Map has no other removal path, and ReverseIndexedMap itself only goes through delete/clear.
  • A non-paying set drops the mark.
  • Upper bound: number of stored workspaces × (string ref + number). At 1,900 workspaces that is under 200 KB; at 19k, under 2 MB. It does not grow with time, history or touch count.
  • deliveryMarkSequence is a single number that increments.

Dormant code made live for everyone?

No.

  • The only new always-on work is the O(1) check in settleOwedMobileSessionSnapshotVersion on each projection, and the O(1) deliverySource lookup.
  • No env flag, setting or kill switch was loosened. The PR adds a listener gate in front of the coalescer.
  • The pay store reuses the existing storeMobileSessionSnapshot. Base already ran it on every touch; head runs it less often.

Listener census and send rate (session-tabs publication path)

Listeners are the entries in mobileSessionTabListeners. They are added only by the RPC streams session.tabs.subscribe (per worktree; mobile app, paired or remote desktop) and session.tabs.subscribeAll (inventory).

The local desktop renderer holds one subscribeAll listener once structured chats are in use (use-local-structured-session-tabs-sync.ts: ready && inUse).

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

  1. 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.
  2. 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.
  3. 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).
  4. 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.
  5. Execution host: not applicable. This is in-process logic, the same on all platforms and on remote runtimes (which run the same runtime class).
  6. 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)

  1. Whole-workspace projection per status flush. notifyMobileSessionTabsChangedNow projects the full workspace snapshot for one status-row change: titleStructuredConversationTabs, favicon inlining, bot-home pins and sender associations. subscribeAll then runs isDeepStrictEqual on the whole projected snapshot for each change (session-tabs-inventory.ts publishChange). Cost is O(tabs) per touched worktree per flush window, per listener. The count is unchanged by this PR.
  2. structuredConversationTabName per agent-session tab per projection. It runs getWorkspaceSessionForWorktree(...).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.
  3. 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.ts passed 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.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 21, 2026 11:23
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Eligible non-immediate mobile-session updates now defer snapshot version bumps and track them per worktree. The projection path settles an owed bump before inlining favicons, and publication uses a per-worktree delivery source. Performance tests check PTY-title fanout and status-driven republishing.

Merge Risk: Minimal · up to 4ac22

This change defers session-tab snapshot storage for status updates, reducing repeated work. No concrete defect was found, and version ordering is preserved for clients. The remaining cost is a one-time settle on the first read after an idle period, which was not profiled at fleet scale.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: agent status changes no longer rebuild the workspace's full tab list on each update. The changeset defers non-urgent snapshot-version bumps and stores a snapshot only …
Description check Passed The description follows the repository template and covers ELI5, What Changed, Why, Testing, Performance, Risk, and the checklist. It gives concrete before and after behavior, measured Linux A/B resul…
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: Title check

Explanation

The title names the main change: agent status changes no longer rebuild the workspace's full tab list on each update. The changeset defers non-urgent snapshot-version bumps and stores a snapshot only when a listener or client reads it, which matches the title. The title is specific and concise, and it does not use vague terms.

Full details: Description check

Explanation

The description follows the repository template and covers ELI5, What Changed, Why, Testing, Performance, Risk, and the checklist. It gives concrete before and after behavior, measured Linux A/B results, performance-contract tests, and a clear risk statement with a revert path. The Linked Issue section says N/A (internal perf work), which is weak for the template's requirement, and the Risk section does not give a 'Level' justification beyond 'Low'. The AI Disclosure section is empty. These are non-critical gaps, so the description is mostly complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8549f2b-c5a9-4417-914d-c343b8a5e5e0
Commits

Reviewing files that changed from the base of the PR and between 1a19391 and 4ac220f.

Files selected for processing: 1

  • src/main/runtime/session-lifecycle/projection/prune-mobile-session-tab-group-layout.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. 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

  • Same-run Linux A/B, exact builds of base 753a25b and head 1a19391 (base, head, head, base), ~1,900-workspace profile, fake Codex chats in one workspace, all streaming, 30 s allocation profile of main:
    • Snapshot-store allocation: 112 / 119 MB per 30 s on base vs 30 / 30 MB on head at 200 chats (about -75%); 2.0 / 2.2 MB vs 1.3 / 1.4 MB at 20 chats.
    • Total main allocation (48.5 / 54.6 vs 50.9 / 52.1 MB/s) and peak main RSS after the burst: no change beyond run-to-run noise. The desktop window always listens, so on a desktop the win is coalescing; skipping applies to hosts with no client.
  • Perf contract status-session-tabs-store.performance.test.ts: N and 10N refreshes store 0 times with no listener and once per workspace per flush with one; reverting the change fails it (40 stores vs 0).
  • Reviews on 1a19391: Claude reviewer READY; blinded regression audit SAFE; perf-scan clean (posted above). CI green.

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)

  • A queued desktop frame was no longer dropped when a newer status arrived (owed bumps now carry a delivery mark).
  • Paying an owed bump during an unrelated read dropped a queued "follow" navigation frame (paying now keeps the mark).
  • A terminal-create reply could carry ready content at a version the client had already seen as pending (every projection now pays the owed bump; the "only when listening" gate was removed).

Deferred (not blocking, P2)

  • After a long period with no client, the first subscribe/list pays one store per workspace whose status changed, in one pass (never more than base already paid during that period; reviewers agreed no fix needed).
  • Some internal projections that never reach a client (tab close, group move, PTY record refresh) also pay the owed bump; harmless today, and total stores never exceed base.
  • Pre-existing, follow-ups: each flush still projects the whole workspace for one row change; the saved chat-title lookup scans the workspace's tabs per chat per projection.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan (3): PR #46246, session-tabs status deferred store

Head 1a1939115aa6fe9df629fc0d966ca14977ba40fe, base 753a25b9f28. This review grades the three surfaces the detector reported in src/main/runtime/session-tabs/restoration/mobile-session-membership.ts, and re-checks an earlier scan's conclusions on the rest of the diff.

Verdict: clean

No perf finding is introduced or amplified. On every path I traced, head does no more snapshot stores, frames or timers than base:

  • With no listener, head drops the per-touch O(tabs) store and the coalescer timer entirely.
  • With a listener, head runs one store per flush window instead of one per touch.
  • The new per-workspace state is bounded by the stored-snapshot map.
  • Idle wakeups are 0/s on main and on the daemon, both before and after.

Findings

None (no P0 or P1).

Surface 1: hot-path (touchMobileSessionTabsForWorktree)

Trigger and frequency. Production callers, all non-immediate unless noted:

  • hook status row mutations (hook-status-session-tabs-republish.ts:43)
  • PTY title, foreground and bind fanout (pty-backed-session-publication.ts:203; immediate is passed through for structural exits)
  • the agent-status heartbeat (runtime-identity-state.ts:275, listener-gated at mobile-session-membership.ts:110-115)
  • favicon inlining (browser-tab-favicon-data-urls.ts:130)
  • title-authority changes (session-title-publisher.ts:58)
  • sender-scope refresh (mobile-session-membership.ts:55, listener-gated)

At the reference fleet this is 100+ agents at more than 1 status update/s, plus title spinners from a few hundred terminals: several hundred touches/s.

Owner and thread. The runtime singleton. That is Electron main on desktop and the main thread of the headless backend on remote hosts (core-runtime-activation.ts, same class).

Work per event.

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. subscribeAll runs isDeepStrictEqual against the last published state before emitting. The frame carries a bumped snapshotVersion, 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.get identity check, plus one Set.delete when 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.

    • owedVersions and deliveryMarks are written only by oweVersion. That runs only after mobileSessionTabsByWorktree.get(worktreeId) returns a snapshot whose worktree matches, so both sets of keys are a subset of the map's keys.
    • The delete and clear overrides drop both. A non-paying set drops 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 calls set on an existing key neither reorders nor revisits entries.
  • session-tabs-change-publication.ts, source changed to deliverySource: 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.ts checks 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).
  • Corrections to the earlier scan.

    1. 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.
    2. Grading line. Its closing line reported surfaces=none. This report grades the three detector surfaces explicitly.
    3. 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

  1. 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.
  2. Ownership multiplying work. Reviewed. One owe per workspace, one pay per owe, one projection per flush, frames fanned out per listener as on base.
  3. 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.
  4. Growth and progress. Reviewed. The collections are bounded by stored snapshots. With a listener, each owe schedules a flush; with none, the census pays.
  5. Execution host. Not applicable beyond point 3. This is in-process logic with identical behavior on mac, linux, windows and remote hosts.
  6. 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 subscribeAll then deep-compares it: O(tabs) per touched workspace per flush window, per listener. The count is unchanged.
  • Per-tab title lookup. structuredConversationTabName runs a unifiedTabs.find per 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
@brennanb2025
brennanb2025 merged commit 07d05f9 into main Nov 21, 2026
71 of 72 checks passed
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