Skip to content

perf(bots): browser navigation and terminal title writes re-read only their own workspace (STA-18521, STA-18523) - #49495

Merged
AmethystLiang merged 3 commits into
mainfrom
AmethystLiang/fix-bot-sidebar-workspace
Nov 26, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
AmethystLiang/fix-bot-sidebar-workspace

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

What Changed

  • STA-18521, browser navigation. setBrowserPageUrl and updateBrowserPageState rebuilt browserTabsByWorktree with 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 calls linkRecordWrite to record the one bucket it replaced. The spread itself is unchanged, so key order and the layout-writer ratchet count stay the same.
  • STA-18523, terminal titles. When a tab-keyed record changed (pane titles, PTY ids, layouts), the reader rebuilt a tab→workspace map from every tab bucket. A combined pane and tab title update also replaces 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 replaceTabBuckets would 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.ts adds 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 browserTabsByWorktree could 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 annotated browserTabsByWorktree, 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

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

…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.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Browser page state and URL actions now journal affected browser-tab bucket writes. Attention tracking resolves changed tab owners directly from updated tab state. Tests cover browser-write journaling, workspace mirror repair, attention consistency after browser and terminal updates, and read counts across 750 workspaces.

Merge Risk: Minimal · up to f670d

This change reduces unnecessary workspace reads in bot-sidebar attention checks without changing the sidebar's result. No actionable merge risk remains, and reverting is a sufficient rollback.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: browser navigation and terminal title writes now re-read only their own workspace. It matches the raw summary, which covers the browser journal entries in bo…
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.
Description check Passed The description follows the repository template closely. It has an ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with checklist items, Performance with a concrete reas…
Full details: Title check

Explanation

The title names the two changes in the PR: browser navigation and terminal title writes now re-read only their own workspace. It matches the raw summary, which covers the browser journal entries in bot-sidebar-attention.ts and the tab-owner lookup for terminal title writes. The title uses a conventional perf(bots) prefix and includes ticket IDs. It is long (112 characters), but it is specific and accurate.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing with checklist items, Performance with a concrete reason, Risk with level Low and a back-out plan, and the Agent skill boundary section. The Linked Issue section names STA-18521 and STA-18523 as follow-ups to #49352 and does not use a 'Fixes #' issue link, which the template asks for from outside contributors. The author appears to be a maintainer, so this is acceptable. The Performance section has a concrete reason, so the 'None, because' line is replaced with a fuller explanation. The AI Disclosure section is blank. The template says to skip it for internal team members. The lint/typecheck/test/build checklist item is unchecked, but the author notes that CI will cover it. The Testing section says manual testing was not done, yet the checkbox for manual testing is unchecked, which is consistent. The PR-LoC block is auto-generated and should be left as is.

  • 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: bc4d6f62-98d4-4bbc-ac2b-9cd74e079be6
Commits

Reviewing files that changed from the base of the PR and between c2e5f56 and f670d81.

Files selected for processing: 1

  • src/renderer/src/components/bots/bot-sidebar-attention.performance.test.ts

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

…(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.
@AmethystLiang
AmethystLiang merged commit fdcea56 into main Nov 26, 2026
60 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