Repository navigation
perf(bots): browser navigation and terminal title writes re-read only their own workspace (STA-18521, STA-18523) - #49495
Conversation
…A-18521) setBrowserPageUrl and updateBrowserPageState rebuilt browserTabsByWorktree with a plain spread, so the record carried no change journal. The bot sidebar attention reader from #49352 then fell back to comparing every browser workspace key, once per armed bot list, on every navigation, load, title or favicon update. Each of those writes now records the one bucket it replaced with linkRecordWrite. The spread itself is unchanged, so surviving keys keep their order and the layout writer ratchet still reads it as a content update. Journal readers touch only that workspace; readers that compare identities see the same records as before.
…(STA-18523) When a write touched a tab-keyed record (pane titles, PTY ids, layouts), the bot sidebar attention reader from #49352 rebuilt a tab-to-workspace map from every tab bucket. A combined pane and tab title update replaces tabsByWorktree too, so the cached map missed on each such write and the rebuild read every tab in the fleet. The reader now asks the shared terminal tab owner index for each changed tab. That index follows tab-bucket writes by the buckets they name (the title writer already adopts its result), so the lookup costs nothing per other bucket. Ownership rules are unchanged: the last bucket holding a tab owns it.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…(STA-18521, STA-18523) The perf contracts counted reads through a Proxy whose get trap called Reflect.get, which the low-evidence lint rejects. They now count through a copy whose own entries are getters. Production code is unchanged.
ELI5
The bot sidebar checks which of a bot's workspaces need attention. #49352 made it re-check only the workspaces a change could affect. Two kinds of change still made it look at everything: a browser page navigating anywhere, and a terminal title changing. Now both name the one workspace they touched, so the check looks only there.
What Changed
setBrowserPageUrlandupdateBrowserPageStaterebuiltbrowserTabsByWorktreewith a plain spread, which leaves no change journal. The attention reader then compared every browser workspace key, once per armed bot list, on each navigation, load, title or favicon update. Each of those writes now callslinkRecordWriteto record the one bucket it replaced. The spread itself is unchanged, so key order and the layout-writer ratchet count stay the same.tabsByWorktree, so the map's cache missed on every such write. The reader now asks the shared terminal tab owner index for each changed tab. That index already updates per named bucket, and the title writer already adopts its result. The ownership rule is the same: the last bucket holding a tab owns it.Nothing visible changes. The sidebar shows the same answer, for less work.
Why
Both are follow-ups to #49352 that extend its keyed-journal design instead of adding new machinery. The alternatives were more invasive. Routing the browser writes through
replaceTabBucketswould have raised the file's layout-writer ratchet count. Teaching the reader to skip browser records would have dropped a real attention input (a browser tab makes a workspace live).Linked Issue
STA-18521, STA-18523 (follow-ups to #49352)
Visual Proof
N/A: performance-only change with no visual or interaction difference.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
bot-sidebar-attention.performance.test.tsadds two tests that count reads through counting getters on the records, at 750 browser workspaces and 750 tab buckets. On main they fail with 750 browser-bucket value reads (one per browser workspace; the counter counts value reads, not key enumeration), after a navigation and again after the page-state update that follows it, and with 749 tab-id reads after a combined title write. With each fix they read 0. Each fix clears only its own test.bot-sidebar-attention.test.ts(the reader must equal a full read after every write) now also runs the real browser writers: navigate, page-state update, mirror repair and close. It also runs the combined, plain and clearing title writers, including on a tab that moved between workspaces. Those full-read comparisons guard correctness and also pass on main; the fail-before evidence is the counting tests and the journal checks below. Because attention sees only whether a browser bucket exists, the test also checks each browser write's journal entry directly: it must name only the replaced workspace. On main it reads as a full resync.Locally: both test files pass, plus web typecheck, oxfmt, oxlint (including the low-evidence pattern config), the changed-code quality gate and the ratchet runner. CI runs the full test suite.
Performance
Better: per armed bot list, a browser navigation or page-state update elsewhere goes from a scan of every browser workspace (N value reads plus key enumeration) to 0. A combined title write goes from reading every tab in every bucket to one indexed lookup per changed tab. Both are reasoned from the code and pinned by the counting tests above. The writers' own per-write cost is unchanged apart from one small journal entry per write. Their existing once-per-write page and workspace id lookups are out of scope here.
Risk
Level: Low
The riskiest part is the journal entry: if it named the wrong key, journal readers of
browserTabsByWorktreecould miss a change. Each entry names exactly the key its spread replaced, and the invariant test checks the reader against a full read after each writer. Before this change nothing annotatedbrowserTabsByWorktree, so its other readers only ever took the full-compare path. To back out, revert the PR; no saved data or protocol changes.AI Disclosure
Review
No comparable: mechanical.
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)