Repository navigation
Terminal title changes update the app once instead of twice - #46507
Conversation
Perf scan: #46507 at
|
| Work | Trigger | Population | Bound |
|---|---|---|---|
onTitleChange → setRuntimePaneTitle(tabId, paneId, title, { alsoTabTitle }) (parked-terminal-byte-watcher.ts:144-148) |
Every OSC title the parked byte watcher observes (pty-output-title-observer.ts:76-78). This includes agent spinner frames, up to ~10/s per working agent. |
One call per parked pane with title output. At the reference fleet: a few hundred terminals and 100+ agents. | One store set() per observed title. Base made two: setRuntimePaneTitle, then updateTabTitle. |
runtimePaneTitlePatch (terminal-tab-presentation.ts:204-233) |
Same | One pane | Same code as base, moved: O(1) equality check, decorative-frame gate, and a classification compare. Owner lookup goes through the cached shared owner index. One replaceRecordEntries runs only on a real change. |
applyTerminalTabTitleUpdates called inside the same updater (terminal-tab-presentation.ts:157-168) |
Same, when drivesTabTitle |
The owner worktree's tabs only | Same function and inputs as base updateTabTitle. Its owner stage is O(tabs in one worktree), and the existing N/10N contract in this file pins it at 0 rows scanned in other workspaces. sortEpoch composes in the same order as before: the pane bump is applied first, then the tab bump. |
scheduleRuntimeGraphSync() |
Tab title actually changed | Global | Unchanged count. Already called inside the updater at base, and coalesced to one pending timer (graph-sync-scheduler.ts:28-43). |
withStatusTransaction wrapper per set() (status-transaction-boundary.ts:28-63) |
Every call | Global | Halved. A changed write pays one {...get(), ...requested} copy of the full state plus agent-status staging. A no-op write (equal title or decorative frame) returns early at requested === current, and it now hits that early return once instead of twice. |
Store write: listener census at this head
Zustand runs every listener on every notification, whichever field changed. A driving title change touches runtimePaneTitlesByTabId, plus tabsByWorktree/unifiedTabsByWorktree and possibly sortEpoch. These are all the subscribers it reaches, including in unchanged files.
Always installed, non-React
- Store-internal listeners:
installSettledSortEpoch(settled-sort-epoch.ts:45), with an identity check onsortEpoch/worktree rows. AlsoinstallStoreListenerCensus(counts at subscribe time only) and thewithStatusTransactionerror-wrapper around each listener. installTerminalParkingInputs(terminal-parking-input-transitions.ts:20). Its body runs on every write. It then diffs only the changed buckets and the title keys of changed tabs.- Runtime graph sync key (
use-runtime-graph-sync.ts:30). About 22 identity checks. A title change always rebuilds the key and schedules one coalesced sync. AtabsByWorktreechange rebuilds the mobile tabs projection over all tabs. wsl-host-ipc-bridge.ts:135. Identity-gated. Only when WSL is serving does it runselectWslHostsWithVisibleWorktwice, and it sends IPC only when the result differs.legacy-chat-rename-migration.ts:80: O(chat tabs) on aunifiedTabsByWorktreechange.StructuredAgentSessionStatusBridge.tsx:355: addressed diffs per changed workspace.agent-status-ipc-bridge.ts:271: retry gate, thenkeyedListsMatchover changed buckets only.installPRAutoRefreshCadenceObserver,runtime-file-position.ts:110,sleeping-records-to-layout-owner.ts:15,web-session-visible-tab-pick-report.ts:76,worktree-operation-store.ts:131,connector-connect-state.ts:322,connector-host-state.ts:228,ipynb-kernel-session.ts:310. Each is gated on an unrelated field and does no work on a title write.
Refcounted or open-surface, non-React
activity-thread-projection.ts:128. No gate: notifies every reader, and each runs a shallow compare over ~20 fields.structured-chat-name-observation.ts:116andbot-background-sessions.ts:225, gated onunifiedTabsByWorktree.terminal-pane-attention-subscriptions.ts:73, no work on a title write.SpaceWindowStatePublisher.tsx:46, only while that window is open. It runs twoObject.valuespasses of ~35 fields per write and queues a 100 ms IPC publish when titles or tabs change.
Transient, one flow each
web-runtime-browser-creation-context.ts:170,native-chat-side-chat-placement.ts:151,browser-request-ipc-bridge.ts:31,mobile-terminal-close-ipc-bridge.ts:67(ungated check),worktree-agent-activation-gate.ts:73,wake-sleeping-agents-in-background.ts:33.agent-terminal-presence.ts:64: until its agent appears, a tabs change scans all worktrees.
React useAppStore hooks: one listener per mounted hook
- Sidebar worktree cards.
use-worktree-activity-status.ts:65-75is mounted once per visible card. Its per-worktree title selector caches by source identity, so each title write starts a new generation and every mounted card rebuilds its own record. That is O(all tabs across mounted cards) per notification. - Tab bar and panes.
use-terminal-tab-activity.ts:71(one per tab) anduse-terminal-pane-tab-state.ts:19-31(one per pane) compare one tab's slot. - Dashboard drawer, while mounted.
useLiveDashboardSnapshot.ts:18-28subscribes to the wholetabsByWorktree,unifiedTabsByWorktreeandruntimePaneTitlesByTabIdmaps. Every title write re-runsbuildDashboardSnapshotover all worktrees. - Ungated whole-map selectors:
StatusBarAccountControls.tsx:11,use-workspace-space-manager-bindings.ts:27,31,use-worktree-jump-palette-store-state.ts:102. - Gated whole-map selectors: the resources status segment (on
viewActive), the palette live status (onactive), the send-target popover and the context menu. - No React selector reads
sortEpoch.
Rate under load. Take the reference fleet: a few hundred parked terminals and 100+ agents. Assume ~1–5 real title changes/s fleet-wide (status transitions and title text), which is the same order as hook status traffic.
- Real changes: base ran the census above twice per change (2–10 passes/s). This head runs it once (1–5 passes/s). Each removed pass saves one full-state copy, one parking-input diff, one sync-key build, one generation rebuild for every mounted sidebar card, and one dashboard snapshot rebuild when the drawer is open.
- Spinner frames: up to ~10/s per working agent, so hundreds/s fleet-wide. These notify nobody at either base or head, because both actions return the same state. Head calls the middleware wrapper once per frame instead of twice.
- Commits: both base writes ran in one task, so React likely already batched them into one commit. The saving is selector and listener evaluation, not commits. This is a count from source, not measured timing. I did not read the live listener count (
readStoreListenerCount) from a running app.
Regression classes touched
- No-op store write returns new identities: checked and ruled out. An equal title, or a decorative frame with no label change, returns
s(terminal-tab-presentation.ts:162-164). The new contract asserts 0 notifications on a repeat. - Update published when nothing changed: checked and ruled out, same evidence.
- One change published as N notices: this is what the PR fixes. 2 → 1, asserted by
terminal-title-fanout.performance.test.ts:167-181. On revert, that test fails becausealsoTabTitleis ignored and the tab title assertion breaks. - Per-row derivation over the whole collection per write: the sidebar-card generation rebuild and the dashboard snapshot are pre-existing. This PR halves how often they run.
- New idle wakeups / fixed-cadence poll: none. No timer or subscription added.
scheduleRuntimeGraphSynckeeps the same call count. - Per-entity state outlives the entity: no new per-entity state is kept.
Six questions
- Unused work before the skip gate: reviewed. The equality and decorative-frame gates still run before any allocation. The combined path still calls
applyTerminalTabTitleUpdateswhen the pane slot is unchanged, exactly as baseupdateTabTitledid. - Ownership multiplying work: reviewed. One watcher per parked pane, unchanged. Listener fanout per change is halved (census above).
- Thread paying: renderer main thread only, as before. No sync fs, SQLite or IPC added.
- Growth: constant per event. Owner-stage work is O(tabs in one worktree), and the existing contract covers N=200 and 2,000 workspaces.
- Execution host: not applicable. This is renderer store logic and behaves the same for local, SSH, WSL and mobile-mirrored terminals.
- Obsolete work stops: not applicable. No new resource, timer or retained closure.
Pre-existing (not regressions of this PR, do not block it)
- The mounted (non-parked) title path still writes twice per driving title change:
pane-title-observation.ts:27then:38. So doshell-command-inference.ts:135/137andconfirmed-shell-agent-title.ts:19/21. The samealsoTabTitleoption would halve those too. - Whole-map or ungated subscribers that do fleet-scaled work on every title write:
useLiveDashboardSnapshot(all worktrees, while the drawer is mounted)- sidebar card title-record generation (all mounted cards' tabs)
activity-thread-projection(no gate)use-worktree-jump-palette-store-state.ts:102(no gate)
Evidence
- Ran:
pnpm test src/renderer/src/store/terminal-title-fanout.performance.test.ts, 2/2 passed. That covers the new 1-notification / 0-on-repeat contract and the existing 0-rows-scanned at N=200 and 2,000. - Read in full: the diff,
terminal-tab-title-batch.ts, thewithStatusTransactionmiddleware,settled-sort-epoch.ts,graph-sync-scheduler.ts, the title observer, and the subscriber sites listed above. - Not run: no app-level timing, CPU or listener-count capture. No typecheck or full suite.
Perf scan: #46507 at
|
| # | Work | Trigger | Population | Bound |
|---|---|---|---|---|
| 1 | setRuntimePaneTitle(…, { alsoTabTitle }) runs runtimePaneTitlePatch and applyTerminalTabTitleUpdates inside one set() (terminal-tab-presentation.ts:150-175) |
A non-decorative OSC title change on the active pane of a visible terminal (pane-title-observation.ts:28), or on a parked terminal whose pane drives the tab (parked-terminal-byte-watcher.ts:148) |
One tab. The owner lookup goes through the shared identity-cached getTerminalTabOwners. getOwnerStage indexes only the owning worktree's tab and unified-tab buckets |
Same calls as before (updateTabTitle already ran applyTerminalTabTitleUpdates on every such change). Notifications drop from 2 to 1. If both patches are null the setter returns s, so zustand's Object.is check skips the notify. The contract asserts 0 notifications on a repeat |
| 2 | Same batching for the neutral-title reset after an inferred interrupt (shell-command-inference.ts:135) |
Title-only interrupt timer fires, one per interrupt | 1 pane | Notifications drop from 2 to 1 |
| 3 | Same batching for clearing a stale agent title on a confirmed shell (confirmed-shell-agent-title.ts:19) |
Shell confirmed after agent exit, one per transition | 1 pane | Notifications drop from 2 to 1 |
| 4 | alsoTabTitle: false, or no option (inactive split panes, parked tabs that don't drive the tab, and the restart path at terminal-parked-tab-watchers.ts:79) |
Same as before | 1 pane | Same single runtimePaneTitlePatch write as base |
| 5 | sortEpoch: the tab step reads panePatch.sortEpoch ?? s.sortEpoch |
A non-active worktree's title changes classification or text | — | Same total increment as base (pane +1 and tab +1), now published once instead of across two notifications |
| 6 | scheduleRuntimeGraphSync() when the tab title changes |
Same as base | 1 timer | Already coalesced (syncScheduled latch, RUNTIME_GRAPH_SYNC_COALESCE_MS). Same as base |
Decorative spinner frames: the pane step returns null (isDecorativeAgentTitleFrameChange). The tab step at most rewrites the unified label to the current tab.title, which is a no-op. Result: 0 notifications, same as base.
No new timers, intervals, IPC, subprocesses, filesystem or SQLite work, imports, or retained state. Steady-idle wakeups per second are unchanged on renderer, main and daemon (0 added).
Listener census for the store write
Each zustand notification reaches every raw subscribe listener plus every mounted useAppStore(selector) hook. At this head the renderer has 101 raw subscribe sites (non-test; many are conditional or one-shot waiters) and 3,126 useAppStore( call sites. The selectors that run depend on what is mounted. The PR does not change who subscribes. It halves how often all of them run for a tab-driving title change.
These listeners read the fields a title change writes (runtimePaneTitlesByTabId, tabsByWorktree, unifiedTabsByWorktree, sortEpoch). Most are unchanged files:
use-runtime-graph-sync.ts:30: does an identity skip gate, then builds an incremental sync key and calls the coalescedscheduleRuntimeGraphSync. Before: 2 key builds per change (pane field, then tab field). After: 1.use-runtime-graph-sync.ts:60: compares 5 catalog fields by identity and returns.settled-sort-epoch.ts:45: on an epoch bump it runscountLiveWorktrees, an O(worktrees) walk over the indexed list. Before: up to 2 walks per non-active classification and title change. After: 1.session-write-subscriber.ts:273: filtersSESSION_RELEVANT_FIELDSand arms a debounce. Once per notification, and an armed timer isn't reset.terminal-session-name-sync.ts:148:terminalTabNamesChangedrunsObject.keysover all worktree buckets whenevertabsByWorktreechanges. 1 per tab-title change in both base and head (pre-existing, see below).ai-vault-tab-title-sync.ts:271: gated onruntimePaneTitlesByTabIdidentity. Visits only the changed owning-pane requests.bot-background-sessions.ts:225: callsrecompute()whenunifiedTabsByWorktreechanges. 1 per tab-label change in both base and head.workspace-layout-frame-drawn-workspaces.ts:27: identity check ongroupsByWorktreeandunifiedTabsByWorktree.agent-terminal-presence.ts:64,structured-chat-name-observation.ts:116,legacy-chat-rename-migration.ts:80,StructuredAgentSessionStatusBridge.tsx:355,bot-home-tab-placement.ts:146,runtime-status-subscriptions.ts:61/313,wsl-host-ipc-bridge.ts:135, and the remaining raw listeners: identity or field gates that return early on a title write.subscribeTabTransitions(tab-transition-subscription.ts) has no production caller at this head.- Mounted hook readers of titles (tab bar activity, sidebar card activity/status inputs, the dashboard snapshot, the cmd-j live status, worktree-jump status inputs) each run their selector once per notification instead of twice.
Rate under load (reference fleet): assume 100+ agents, each emitting at most ~1 non-decorative title change per second. Spinner frames are filtered upstream.
- Base: up to ~200 notifications/s from active-pane and tab-driving parked titles.
- Head: ~100/s.
- Each notification fans out to the ~101 raw listeners plus every mounted selector.
- At 10× fleet: ~2,000/s → ~1,000/s. Per-notification work is unchanged, so the PR halves the total.
Regression classes touched
- One change published as N notices. This is the class the PR fixes. Verified by
terminal-title-fanout.performance.test.ts("notifies store subscribers once"), which I ran: 2/2 passed. The new test fails if reverted, because without the option the tab title isn't written. - No-op store write returns new identities. Matched and disproved: the setter returns
swhen both patches are null, and the contract asserts 0 notifications on a repeat apply. - Per-row derivation over the whole collection per write. Matched and disproved: the existing contract asserts 0 other-workspace rows scanned per title change at 200 and 2,000 workspaces (passes).
- Hidden owners keep working. Matched (parked terminals write titles). The behavior is unchanged and the output is required (sidebar and tab title). The PR only reduces notifications.
- New idle wakeups and fixed-cadence poll. No matching code.
Six questions
- Unused work before the skip gate. Reviewed. Pane and tab equality and decorative-frame gates run before any patch is allocated. When both are no-ops, the result is a no-op return.
- Ownership multiplies work. Reviewed. One write per title event per pane. No new owners or subscriptions.
- Thread and storage. Renderer main thread only, with no sync I/O. Persistence goes through the existing debounced session writer.
- Growth. Reviewed. Per-write cost is O(tabs in one worktree) through the cached owner index, held at 0 cross-workspace rows at 10N by the existing contract.
- Execution host. Not applicable. This is renderer store logic, identical for local, SSH, WSL and paired hosts.
- Obsolete work. Not applicable. No timers or resources are added. Parked watcher teardown is unchanged.
Pre-existing (not introduced or amplified by this PR)
terminal-session-name-sync.ts:20terminalTabNamesChangedcallsObject.keyson all worktree buckets twice pertabsByWorktreechange. That is ~1,500 key visits per tab-title change at 750 worktrees, or ~150k/s at 100 changes/s. The count is the same in base and head.settled-sort-epoch.ts:13countLiveWorktreeswalks all worktrees on everysortEpochbump, which happens on non-active title changes. This PR lowers it from ≤2 to 1 walk per change.
Evidence and gaps
- Source-traced on renderer store paths at merge
43ddaa91b60(PR head on main3b8cbe221f2). - Ran
terminal-title-fanout.performance.test.ts: 2/2 passed. - No runtime timing or CPU profile was captured, so no millisecond claims. The impact is stated as notification counts.
- Behavior note, not perf: in
pane-title-observation.tsthe tab title is now written beforeagentCompletionCoordinator.observeTitle. The coordinator reads hook status and the raw title, nottabsByWorktree, so the ordering change has no observable effect.
…name sync or live-worktree count
Perf scan: #46507 @
|
| # | Work | Trigger | Population per event | Bound / invalidation | Before → after |
|---|---|---|---|---|---|
| 1 | setRuntimePaneTitle(..., { alsoTabTitle }) (terminal-tab-presentation.ts:150): pane-title patch plus applyTerminalTabTitleUpdates in one set |
Every terminal title change, from three places: a parked terminal's byte watcher; a visible pane's title observation (pane-title-observation.ts:28); and two neutral-title resets (shell-command-inference.ts:135, confirmed-shell-agent-title.ts:19) |
1 tab: owner lookup from the shared owner index (O(1) after adoptTerminalTabOwnerMetadataOnlyBuckets), owner-stage maps over one worktree's tabs, one replaced bucket in tabsByWorktree / unifiedTabsByWorktree |
Pane-level skips (same title, decorative spinner frame) run before any allocation; returns s when neither patch exists, so unchanged input notifies 0 times |
2 store notifications → 1 per title change on the active pane or the tab-driving pane. The patch is the same; a sortEpoch change is still +1 or +2 overall, now in a single write |
| 2 | countLiveWorktrees cached on worktreesByRepo identity (settled-sort-epoch.ts:16) |
Every store write that changes sortEpoch or the rows; title writes for a non-active worktree bump sortEpoch |
Base: full getIndexedAllWorktrees walk (750 rows, 7,500 at 10×) per sortEpoch bump. Head: one identity compare; the walk runs only when rows change |
Invalidated by worktreesByRepo identity, which every row write replaces. Retains one reference to the last counted worktreesByRepo, and only one |
O(worktrees) per title-driven bump → O(1) |
| 3 | terminalTabNamesChanged reads readTabMapChanges (terminal-session-name-sync.ts:21) |
Every write that replaces tabsByWorktree (all tab-driving title writes) |
Base: Object.keys of both maps plus an identity walk over every worktree key. Head: only the addressed bucket(s) |
Falls back to the full walk when the change chain can't be addressed (unlinked write, >64-step gap, reorder); same as base in that case | O(worktrees) per tab-driving title write → O(changed bucket) |
| 4 | Contract test (terminal-title-fanout.performance.test.ts) |
test only | — | Fails if the change is reverted: two sets give 2 notifications, not 1. The unchanged case asserts 0 |
pnpm test on this file: 2/2 pass at head |
Parked terminals that don't drive their tab (drivesTabTitle=false) and pane-only titles (inactive split) still notify once, as on base. Nothing else calls the old two-step sequence on a per-title path. The remaining updateTabTitle callers run on focus change, pane close, restart and agent-status routing, not per title.
Listener census: what one title write reaches at this head
A title write is one set. A pane-only write replaces runtimePaneTitlesByTabId and maybe bumps sortEpoch. A tab-driving write also replaces one bucket in tabsByWorktree and one in unifiedTabsByWorktree, linked through replaceTabBuckets. Every useAppStore.subscribe listener in the renderer runs on every notify, so I read all 100 direct subscribe sites, plus the wrapped subscriptions (subscribeStore / subscribeStoreWithStatuses passthroughs, the session-name sync and AI-vault title sync gates, and the status-transaction wrapper), and every mounted selector hook. This includes files the PR doesn't touch.
Listeners that get past their gate on a title write and do more than O(changed bucket):
| Listener | Owner × count | Work per title write | Changed by this PR? |
|---|---|---|---|
use-runtime-graph-sync.ts:30 |
1, app-wide | Its gate includes runtimePaneTitlesByTabId, so every title write rebuilds the mobile sync key (O(changed bucket)) and arms the 16 ms coalesced scheduleRuntimeGraphSync. The sync rebuilds tab indexes cached on tabsByWorktree identity: O(all terminal tabs) after a tab-driving write |
Base ran the key build on both writes; head runs it once. Graph syncs coalesce to ≤ ~60/s either way |
session-write-subscriber.ts:273 |
1, app-wide | Pane-only writes stop at the field-identity gate. On a tab-driving write that isn't a spinner frame it projects the changed bucket and re-arms a 150 ms trailing debounce. The flush builds a session patch over all worktrees/tabs and sends it over IPC | Unchanged: base made the same tab-driving write once |
settled-sort-epoch.ts:54 |
1, per store | Per sortEpoch bump: re-arms a 3 s trailing deadline, or in Manual sort a synchronous nested setState. The live-worktree count is now O(1) (row 2 above) |
Improved: one bump-carrying write per title change instead of up to two; full scan removed |
activity-thread-projection.ts:128 |
1 while Activity readers are mounted | Tab-driving write → readers re-render → buildActivityEvents full pass over agent panes |
Unchanged (same tab-driving write count) |
legacy-chat-rename-migration.ts:80, structured-chat-name-observation.ts:116 |
1 each | Tab-driving write passes the unifiedTabsByWorktree gate → walk over all structured-chat tabs (snapshot cached, result equal → no publish) |
Unchanged |
workspace-layout-frame-drawn-workspaces.ts:27 (+ server-layout-frames.ts:148, one per paired stream) |
1 + paired streams | Tab-driving write → Object.keys(cache).filter(unshown); local path may call the unmemoized buildHostSessionRouting when an unshown key is present |
Unchanged |
agent-terminal-presence.ts:64 |
≤3, live until that agent type appears | Tab-driving write → walk over agentStatusByPaneKey and paneForegroundAgentByPaneKey |
Unchanged |
SpaceWindowStatePublisher.tsx:46 |
1, only while the Space window is open | Gate includes titles and tabs → 100 ms coalesced full-state IPC | Gate now runs once per title change instead of twice; publishes stay coalesced |
useDashboardPopoutBridge.ts:84 |
1, only while the dashboard pop-out is open | Gate includes titles and tabs → snapshot build over all worktrees, throttled to 250 ms, plus IPC | Same as above |
ai-vault-tab-title-sync.ts:271 |
1 gate | Every title write: O(changed tab). For an AI-vault refresh agent whose title key changed: microtask reconcile over requests, resolveSessionTitles IPC, timer re-arm |
Base saw the pane change on write 1 and the tab change on write 2; head sees both in one notify |
agent-status-ipc-bridge.ts:271 |
1, app-wide | O(changed bucket); if status events are queued, a tab-driving write flushes them (routing index over all tabs) | Unchanged |
Conditional / transient: wsl-host-ipc-bridge.ts:135 (WSL serving), bot-background-sessions.ts:225 (bots exist), automation-run-workspace-action.ts:69 (during a run reveal), mobile-terminal-close-ipc-bridge.ts:67 (held mirrored workspace), use-terminal-editor-close-queue.ts:52 (pending close), native-windows-pane-policy.ts:42 (one per Windows ConPTY pane, O(1) each) |
— | O(worktrees, sessions or Windows panes) per notify while active | Unchanged or halved: they don't gate on the title fields, so base ran them on both writes |
Gated at O(1) or O(changed bucket): the other ~80 direct sites. Their gates read fields a title write leaves alone (openFiles, settings, repos, worktreesByRepo, activeWorktreeId, groupsByWorktree, status maps, …), or they are short waits that check one key. This includes terminal-session-name-sync (now O(changed bucket), row 3), terminal-parking-input-transitions (addressed diff; it publishes only when a pane-title slot is added or removed), StructuredAgentSessionStatusBridge (addressed reconcile; title isn't a semantic field), and runtime-status-subscriptions:61 (returns on runtimeStatusByEnvironmentId identity).
Selector hooks: useAppStore(...) is used in ~908 renderer files, and there are 67 useAppStoreWithHostStatuses call sites. Every mounted selector re-runs once per notify. Halving notifications per title change halves this selector work. Renders are unchanged: the tab-driving output is the same, and readers that select the whole tabsByWorktree or runtimePaneTitlesByTabId re-render once per title change, as they did once per write.
Rate under load (reference fleet): spinner frames are filtered before any write (isDecorativeAgentTitleFrameChange at both pane and tab level). Assume 100+ agents emitting real title changes at ~1–2/s each, with most of them driving their tab. That is ~100–200 title writes/s fleet-wide, ~1,000–2,000/s at 10×.
- Base: up to 2 notifications per title change → ~200–400 full listener + selector passes/s (2,000–4,000 at 10×).
- Head: ~100–200/s (1,000–2,000 at 10×).
- Each bump-carrying write also loses an O(750) live-worktree walk (O(7,500) at 10×). Each tab-driving write loses an O(750) worktree-key walk in the session-name sync.
- These rates are derived from source, not from a profile. No timing is claimed.
Regression classes touched
| Class | Disposition |
|---|---|
| No-op store write returns new identities | Disproved: returns s when neither patch exists. The contract test asserts 0 notifications for an unchanged title |
| One change published as N notices | This is what the PR fixes; the test asserts 1 notification |
| Per-row derivation over the whole collection per write | Removed for countLiveWorktrees and terminalTabNamesChanged. Fallback paths stay O(N) only for unaddressable changes, same as base |
| Update published when nothing changed | Disproved (as above) |
| Per-entity state outlives the entity | Disproved: the module cache holds one worktreesByRepo reference and is replaced on the next recount; no per-entity keys |
| New wakeups in steady idle | No matching code: no timer, poll, rAF or IPC added. Idle wakeups/s per process are the same as base (none added on main, renderer or daemon) |
| Hot-path rescans | Reduced (rows 2 and 3) |
Six questions
- Unused work before the skip gate: reviewed. Pane-level checks (equality, decorative frame) run before allocation. Tab title work is shared with the existing
applyTerminalTabTitleUpdates, so nothing is reimplemented. - Ownership multiplying work: reviewed. No new owners or subscribers. Callers per pane are unchanged; deps pass
setRuntimePaneTitlethrough by reference, sooptionsreaches the store. - Thread/storage: renderer only. No sync I/O or SQLite; no main-process change.
- Growth / progress: reviewed. Both new caches are keyed on identity and invalidate correctly. No retries or cursors.
- Execution host: not applicable. The change is a renderer store action and runs the same on local, SSH, WSL and remote hosts. The title source differs per host; the write does not.
- Obsolete work: not applicable. No async work, timers or retained handles added.
Pre-existing (not introduced by this PR, not blocking)
Found while taking the census. Each is reached once per tab-driving title write on both base and head:
activity-thread-projectionre-renders its readers and runs a fullbuildActivityEventspass.- The chat-name observers walk every structured-chat tab.
session-write-subscriberandsettled-sort-epochuse trailing debounces with no max wait (150 ms / 3 s), so sustained fleet-wide title churn can keep pushing the flush or settle back. I did not check whether another path forces a flush (e.g. on quit).
These are worth a separate look but are outside this PR's change.
Evidence
- Reproduced: the targeted contract test passes at head. The notification counts in rows 1–3 are proven from source.
- Not run: typecheck, full suite, benchmarks, profiles. No timing, CPU or heap numbers are claimed.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…itle-one-notification
Review status: readyProblem. Each terminal title change wrote the pane title and the tab title as two separate store updates, so every store subscriber ran twice. On a large profile these notifications showed up in 28 of 74 sampled long tasks. User-facing change. None visible. Titles and sidebar order end up exactly as before; each title change now reaches subscribers once, and an unchanged title reaches them zero times. What changed, by review pass
Every finding, and what happened to it
Verified
Benchmark: head=500bc1496fe47fd781719d50859090dca768a69c gate=PASS 1,900 workspaces, 1,000 unique title changes per mode, listeners mounted: agent hook completion sync, AI-vault title freshness and sync inputs, tab-name sync, mobile session sync key, visible agent orchestration, agent terminal presence. Two calls: median 355 µs, p90 583 µs, 200 notifications per 100 changes. One call: median 319 µs, p90 468 µs, 100 notifications per 100 changes. |
Perf scan: #46507 at
|
| Work | Trigger | Population | Bound / disposition |
|---|---|---|---|
setRuntimePaneTitle(…, { alsoTabTitle }) merges the pane-title write and the tab-title write into one set() (terminal-tab-presentation.ts:150) |
A non-decorative OSC title change on the active pane of a visible pane, a parked terminal (drivesTabTitle), a confirmed-shell neutral title, or an inferred interrupt |
One tab bucket, owner looked up through the shared owner index (already warm, same as base) | Store notifications per title: 2 → 1. Middleware passes (withStatusTransaction, withEditorBufferRecords, retention, cascade probe): 2 → 1. Each subscriber now sees the union of the two old patches once. The fields that change, and their identities, match base. |
runtimePaneTitlePatch extracted from the old inline body |
Same | Same | Same code. Decorative spinner frames and unchanged titles return null. The new contract confirms 0 notifications for an unchanged title. |
applyTerminalTabTitleUpdates now always runs when alsoTabTitle is set, including when the pane patch is a no-op |
Same | 1 owner bucket: O(tabs in that workspace) index build |
Base did the same: updateTabTitle ran unconditionally after the pane write. No new work. |
sortEpoch composition (version-bump surface) |
A classification change on a pane outside the active workspace (+1), plus a tab title change outside the active workspace (+1) | — | The tab update reads panePatch?.sortEpoch ?? s.sortEpoch, so the final value is base +2, the same as base's two sequential writes. It publishes once instead of twice. alsoTabTitle: false is unchanged. There is no publish when nothing changed: both bump conditions require a real classification or title change. |
countLiveWorktrees identity cache (hot-path surface: settled-sort-epoch.ts:12-29) |
Every store notification where sortEpoch was bumped or worktreesByRepo changed |
All worktrees (750 at the reference fleet, 7,500 at 10×) | Before: one O(W) walk per epoch bump. Every non-active-workspace title change bumps, so about 100 titles/s × 750 ≈ 75k row visits/s at the reference fleet, and about 7.5M/s at 10× fleet and title rate. After: O(1) while the row map identity is unchanged, and a recount only when rows change. Retention: one module-level reference to the current worktreesByRepo, replaced on every recount. This is bounded to one snapshot and does not grow. The identity key relies on the same immutability that getWorktreeSnapshot already assumes. A module singleton shared across store instances (tests) stays correct because it is keyed on identity. |
terminalTabNamesChanged reads addressed readTabMapChanges (terminal-session-name-sync.ts:21) |
Every notification where the tabsByWorktree identity changed (every tab-title write) |
Changed buckets. The fallback for unannotated writes is the old full scan. | Before: Object.keys over every workspace plus an identity loop over all W buckets per title. After: a link walk (depth ≤ 64, normally 1) plus only the changed buckets. A workspace add or delete returns true, as the old length check did. The contract now counts 0 unrelated-bucket reads at 200 and 2,000 workspaces. |
Call-site refactors (parked byte watcher, pane-title observation, confirmed-shell title, shell-command inference) and type widening in the two deps types and terminal-actions.ts |
— | — | They take no extra store reads (the parked watcher drops one getState() local). The active-pane check runs once per title, as before. |
Listener census for the title write (this head, unchanged files included)
Zustand notifies every listener once for each set() that changes state, so a title write reaches all of them. Populations:
- 100 direct
subscribe(sites in 95 renderer files, plus indirect subscribers wired through dependencies:TerminalSessionNameSyncGate, AI-vault title sync throughruntimeStatusSubscriptionsFor, parking inputs and PR cadence throughSTORE_OBSERVER_INSTALLERS, the structured-selection catalog, and the HTTP-link accessor. - React hooks: about 3,100
useAppStore(call sites. Each mounted one is a listener that re-runs its selector on every notification. This population grows with mounted sidebar rows and panes, so at 750 rows it is in the thousands.
Listeners that read fields a title write changes (tabsByWorktree, unifiedTabsByWorktree, runtimePaneTitlesByTabId, sortEpoch):
| Listener | Work per title notification at this head |
|---|---|
installSettledSortEpoch |
Identity checks, then O(1) count (was O(W) on a bump; fixed here) |
startTerminalSessionNameSync → terminalTabNamesChanged |
Changed buckets only (was O(W); fixed here) |
whenAgentTerminalAppears, hook-completion sync, AI-vault title freshness and sync inputs, mobile session sync key (use-runtime-graph-sync), visible agent orchestration |
Own bucket only. The fanout contract enforces 0 unrelated reads at N=200 and 10N=2,000. |
installTerminalParkingInputs |
Addressed diff of the changed bucket (diffUnknownParkingRecordKeys) |
tab-transition-subscription |
readTabMapChanges walk, depth about 1 |
session-write-subscriber |
Identity gate, then projection of the changed buckets plus a debounced flush |
workspace-layout-frame-drawn-workspaces, server-layout-frames |
Identity gate on unifiedTabsByWorktree, then the unshown set |
wsl-host-ipc-bridge report |
Windows/WSL only. Identity gate, then O(workspaces focused this session). This is pre-existing, has the same count per title as base, and is not fleet-wide. |
activity-thread-projection (subscribe(notify)) |
Runs on every write and fans out to observed activity listeners. Pre-existing; halved by this PR. |
| The remaining ~85 direct sites (bots, native chat, editor, GitHub, connectors, browser, …) | Identity compares on unrelated slices, O(1) per notification. Halved by this PR. |
Rate:
- Idle: with no title changes there are 0 writes. The PR adds no timer, poll, subscriber or IPC, so idle wakeups per second (renderer, main, daemon) are unchanged from base.
- Under load: at the reference fleet, assume about 100 non-decorative titles/s across 100+ agents. Base produced about 200 notifications/s for tab-driving titles, each running every listener and mounted selector. This head produces about 100/s. Pane-only titles (an inactive split pane, or a parked pane with
drivesTabTitlefalse) stay at 1. At 10× (about 1,000 titles/s) it is 2,000/s → 1,000/s. The per-listener work per notification is unchanged or lower, as shown above.
Regression classes touched
- No-op store write returns new identities: matched and disproved. An unchanged or decorative title returns
s, and the new contract asserts 0 notifications. - Per-row derivation over the whole collection per write: matched. This PR fixes two instances (
terminalTabNamesChangedandcountLiveWorktrees), and the contract now covers the first. - One change published as N notices: this PR fixes it (2 → 1).
- Update published when nothing changed (
sortEpoch): matched and disproved. A bump needs a real change, and the value equals base. - Per-entity state outlives the entity: matched and disproved. The module cache holds one current snapshot and no per-entity keys.
- New idle wakeups: no matching code.
Six questions
- Unused work before the gate: reviewed. The decorative and unchanged gates still run before allocation, and the tab path does the same work as base.
- Ownership multiplication: reviewed. No new owners. Each parked watcher and pane session still makes one call per title.
- Thread: renderer only, synchronous within
set(). No new main, SQLite or IPC work.scheduleRuntimeGraphSyncstill fires once per tab-title change, as in base. - Growth: reviewed. Two
O(W)per-title paths becomeO(changed)orO(1). Nothing new grows with history. - Execution host: not host-dependent. SSH, WSL and remote workspaces use the same renderer store path, and the WSL bridge cost is unchanged.
- Obsolete work and release: not applicable. No new resources, timers or subscriptions. The cache is replaced, not accumulated.
Coverage and residual gaps: I did not take a live listener count (readStoreListenerCount) or a renderer profile, and I did not run base and head on the same workload. The notification reduction is source-proven and asserted by the new test. The ~85 identity-gated listeners were classified with a field-reference screen plus a read of each title-relevant body, not a line-by-line read of every listener.
Review status: ready (supersedes the previous status comment: adds the reference comparison and the perf-scan on the merged head)Problem. Each terminal title change wrote the pane title and the tab title as two separate store updates, so every store subscriber ran twice. On a large profile these notifications showed up in 28 of 74 sampled long tasks. User-facing change. None visible. Titles and sidebar order end up exactly as before; each title change now reaches subscribers once, and an unchanged title reaches them zero times. What changed, by review pass
Every finding, and what happened to it
Verified
Benchmark: head=500bc1496fe47fd781719d50859090dca768a69c gate=PASS 1,900 workspaces, 1,000 unique title changes per mode, listeners mounted: agent hook completion sync, AI-vault title freshness and sync inputs, tab-name sync, mobile session sync key, visible agent orchestration, agent terminal presence. Two calls: median 355 µs, p90 583 µs, 200 notifications per 100 changes. One call: median 319 µs, p90 468 µs, 100 notifications per 100 changes. |
ELI5
When a terminal changes its title, the app used to tell the rest of the app about it twice in a row: once for the pane's own title and once for the tab's title. Every part of the app that watches for changes woke up both times. Now both titles change together, so everything wakes up once. Two of those watchers also used to look through every workspace on each title change; now they only look at the one that changed. Nothing looks different.
What Changed
Before: a terminal title change made two separate store updates: one for the pane title and one for the tab title when that pane is the tab's active split. This happened for parked (hidden) terminals and for visible ones. Every store subscriber ran twice per title change.
After: a single store update writes both. Subscribers run once. If neither title actually changed, there's no update and no notification, as before.
Mechanism:
setRuntimePaneTitletakes an optional{ alsoTabTitle }flag. With it set, oneset()call computes the pane-title patch and then runs the existingapplyTerminalTabTitleUpdatesagainst the post-panesortEpoch. This keeps the result identical to the old back-to-back calls, including the double sort bump when both changes reclassify an inactive workspace. The parked terminal watcher's title callback now uses this flag instead of making two calls. So do the three visible-terminal call sites: title observation, the inferred-interrupt title reset and the confirmed-shell title reset. In title observation the tab title is now written together with the pane title, a few lines earlier than before. Nothing in between reads the tab title. The pane-title logic moved unchanged into aruntimePaneTitlePatchfunction.Two store subscribers that every title change reaches also stop scanning all workspaces:
terminalTabNamesChanged(tab-name sync) used to callObject.keyson the whole tab map and walk every workspace key. It now reads the changed workspace ids from the store's existing write provenance (readTabMapChanges). It falls back to the old full walk only when a write wasn't annotated.countLiveWorktrees(sidebar sort settling) used to walk every worktree on each sort bump. Title churn bumps the sort counter without changing worktree rows, so the count is now reused until the rows object changes.Why
Store notifications from background terminal title changes showed up in 28 of 74 sampled long tasks on a large profile. Each title change paid the full subscriber fan-out twice. Combining the two writes halves that cost without changing any title behavior.
Linked Issue
N/A (internal performance report)
Visual Proof
N/A: no visual or interaction change. Titles end up exactly as before; only how many store updates it takes changed.
Testing
The existing fanout perf contract in
terminal-title-fanout.performance.test.tsnow also includes the tab-name sync subscriber; it fails (2 scans instead of 0) if that subscriber goes back to scanning all workspaces. Also added a contract there: a title change that drives its tab notifies store subscribers exactly once, writes both titles, and notifies zero times when repeated with the same title.Timing, measured with a throwaway harness (not committed) on head 500bc14: 1,900 workspaces, the real title-change store subscribers attached (including tab-name sync), 1,000 unique title changes per mode, macOS. Both modes run on the same head, so this isolates the one-write change; the scan fixes help both modes equally.
Platforms: macOS (unit + timing). The change is platform-independent renderer store code; CI covers Linux and Windows.
Performance
Improves: half the store notifications per terminal title change (parked and visible) when the pane drives its tab. Measured at 1,900 workspaces: about 10% lower median and 20% lower p90 per change. Visible terminals use the same store action. No new work for anyone: the combined path calls the same two existing reducers. Per title change, tab-name sync goes from O(workspaces) to O(changed workspaces), and the live-worktree count goes from O(worktrees) to O(1). It still recounts all worktrees when the worktree rows themselves change.
Risk
Low. The riskiest part is ordering inside the combined update: the tab-title step has to see the pane step's
sortEpochbump. It does, so the result matches the old two calls. If it went wrong, a background workspace could sort one step differently. The second risk is the visible-terminal title observation, where the tab title is now written slightly earlier, before agent completion tracking sees the title. Completion tracking reads only agent status, not the tab title, and sends its notifications later from timers. The remainingsetRuntimePaneTitlecallers (parked-watcher restarts) pass no options and behave exactly as before. The scan fixes keep a full-walk fallback for unannotated writes, and the live-worktree count recomputes whenever the worktree rows change. Back out with a plain revert.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
Does not overlap #46016 (main-process mailbox writes) or #45731 (session persistence keys); neither touches this renderer call site.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)