Skip to content

Bot Items list: fetch only what changed, and never re-fetch loaded Closed pages - #45990

Merged
brennanb2025 merged 48 commits into
mainfrom
brennanb2025/bot-home-items-host
Nov 21, 2026
Merged

brennanb2025 merged 48 commits into
mainfrom
brennanb2025/bot-home-items-host

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A bot's Items list kept fetching far more than it showed. When one item got a comment, the app re-downloaded every item in the list with its full text, and if you had pressed "Show more" on Closed, it re-downloaded each of those pages too, each one dragging the whole open list along again. Now the list fetches short versions of items, fetches only the item that changed (or, when a worker's state changes, only the items that have a worker), and doesn't re-fetch Closed pages you already loaded on every change (only after a missed change, when a chat's own list refreshes, or when so many items have workers that fetching them one by one would cost more than fetching the loaded pages). The list looks and behaves the same; it just does a small fraction of the work. One small difference: when you open an item, its long description can appear a moment after the rest, because the list no longer carries it and the opened item fetches it (as it already did). Another small difference: pressing Show more in one view of a bot (its own panel or a group panel) loads the same older items in its other open views too.

Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​509 $\color{#cf222e}{\Huge{\mathbf{−}}}$​71 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​438
Prod 26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1301 $\color{#cf222e}{\Huge{\mathbf{−}}}$​430 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​871

What Changed

Before: with 600 open and 400 closed items, one comment on one item made the list do several reads of over a megabyte each, and the app's main process spent many seconds per minute answering them while a bot was busy.

After: one item change is one small read of that item. Pressing Show more reads only the next Closed page. The opened item still loads its full text as it does today.

Mechanism:

  • The items list call takes four optional params: summary (rows without description, done means and close note), closedOnly (with closedCursor, only that Closed page), closedLimit (how many Closed items one page holds) and uids (only those items, plus the counts). A host that doesn't know them ignores them and answers as before; the client still handles a whole answer, paging down to the loaded depth itself.
  • Item change notices name the items that changed, per bot (itemUids). The Items list (the bot's own and the chat-filtered one) reads just those and merges them by uid: unchanged rows keep their identity, a missing one is dropped, a new one added. A worker change reads, by uid, the loaded items that link a worker (any state), picked when the read starts and read fifty per call (a Closed page's worth, so no answer is larger than a page); the host's own resolver then answers each with its newest worker, so follow-ups, reused terminals and resets need no reverse lookup on the host. A host that can read by uid marks its worker notices (namesItems); from an older host a worker change reads the whole list, as before. Named items are read fifty per call; when that would take more calls than reading every loaded page (pages still owed by a stopped read counted), the list reads every loaded page instead, so a notice never costs more calls than a whole read. A notice that names nothing (older hosts, more than 100 items at once), or any read after a failed one, reads the whole list. A whole read that pages down the loaded Closed depth stops after a page when a newer update is waiting, so that update is not held behind the rest; the next read goes on from where it stopped.
  • Closed pages are part of the list's one read: Show more is one more read of it, taken in turn with the update reads, so a page and an update never race. Updates never re-read loaded pages; a whole read reads the first page and, only when it moved, the rest of the loaded depth a page per call (as before, and no answer larger than before, which a paired connection's answer-size cap needs). The list never holds more Closed rows than were loaded: rows an update pushes past the end wait behind Show more (a list read to its end keeps room for the pages it took, as re-reading each of them did). Every view of one bot's Items (its panel, a group panel) shares that one read, so Show more in one deepens Closed in the others while they are open. A read stops calling the host once no view shows it.
  • The named-items query looks rows up by uid instead of scanning the bot's items.

Why

The cost grew with the number of items and with how far Closed had been paged, on every change. Reading what changed keeps each update small and flat in item count, and summaries keep the list read small when it does have to read whole.

Linked Issue

None (maintainer change; no issue filed).

Visual Proof

N/A for screenshots: the list renders the same rows. The one visible difference is timing: an opened item's description, done-means and close note appear when the item's own read lands (a moment after the title and status), instead of being shown from the list row first. Measurements are under Testing.

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

Tests: the list call's summary, Closed-page-alone and named-items answers; notices naming changed items, a worker change reading the items that link a worker, and falling back to a whole read; work contracts for the loader (calls per read, Closed-only pages, fifty uids per call, going on from where a read stopped for a newer update with each page read once, no paging once nothing shows the list); the uid merge keeping the host's order; the list read reaching every Closed item exactly once through Show more after a bulk close and a reopen at the loaded edge, and reading its loaded depth again on a whole read, page by page from an older host; an older host's whole answer to a named read keeping the loaded Closed rows.

Measurements (Linux, E2E production build, hidden window; one bot with 50 or 600 open items plus 400 closed, Closed paged to the end with Show more, then 60 item comments at one per second; the same probe on base and on this PR's final code):

base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
Size of each read 205 KB 1 KB 1,320 KB 0.9 KB
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Main handler time for list reads, per 60 s 1.9 s 0.08 s 10.0 s 0.07 s
Show more to the end (5 pages) 1.0 MB 0.18 MB 6.6 MB 0.18 MB
First list read when the panel opens 205 KB 76 KB 1,323 KB 452 KB

Per item change, cost is now flat in item count (a worker change reads the loaded items that link a worker, fifty per call, never more calls than a whole read). Row re-renders and mounted rows (renderer long tasks, heap) are unchanged here; they are the separate list-rendering change.

Platforms: Linux (measurement run above). No platform-specific code.

Performance

This change makes the Items list do much less work. Per item change: 1 small read instead of 6 large ones, with main-process handler time for list reads flat in item count (0.08 s vs 0.07 s per minute at 50 and 600 open items, against 1.9 s and 10.0 s before; measured above). Show more reads one Closed page without the open list. A worker's state change now reads the loaded items that link a worker, fifty per call, instead of the whole list; a notice never takes more calls than a whole read of the loaded pages (beyond that it reads them all, as before); a whole read stops at an unchanged first page, as before, and pages a page per call when it moved. No new timers, polls or IPC channels; notices go out at the same rate, carrying up to 100 item ids per bot. Trade-off: a worker change on a bot with many worker-linked items reads every loaded page, as before, though as summaries and a page per call.

Risk

The riskiest part is merging named items into the list with its loaded Closed rows: a mistake would show a stale row until the next whole read. All reads of one list run one at a time on one value, and whole reads (a notice naming nothing, after any failed read, on reconnect) read the loaded depth again. Older paired phones and servers keep working: the new params and notice fields are optional on both sides, and the phone app doesn't send the new params. Against an older host, a named read that comes back whole is read as a whole read, and a whole read of the bot's list pages down to the loaded depth only when the host's first page moved, while the chat-filtered list pages down on every whole read (each as before this change), so loaded Closed rows never disappear. A plain revert backs it out; nothing is saved.

Level: Medium

Review

Reviewed by a fresh pair of reviewers and a separate performance review on the final head; status comment to follow.

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 brennanb2025 changed the title perf(bots): read Bot Home items as summaries and only the items that changed Bot Items list: fetch only what changed, and never re-fetch loaded Closed pages Nov 20, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 3034b77

Verdict: no regression. Each piece of work this PR adds or changes either costs less than what it replaces or adds nothing. It adds no timers, polls or listeners. The botsChanged frame rate does not change. Each frame now carries at most 100 uids per bot. I found no finding at P0 or P1.

Method: I read the source at the PR head merged onto current main. I did not run the app or any benchmark, so there are no timing claims below. Costs are given as proven counts with their triggers.

Work added or changed: trigger, population, bound

Work Trigger Population Bound Compared with base
BotItemsHost.changed(items) groups uids by owner bot (bot-items-runtime.ts:170) each item write: comment, status, snooze, writeResult, owed mail items in one write O(k) same call sites; it used to group bot ids
addBotChange / botChangeNotice gather itemUids per bot (bot-change-scope.ts:465) each changed(), joined into one notice per 500 ms window bots × uids in the window per bot, at most BOT_CHANGE_ITEM_UIDS_MAX = 100 uids; above that it falls back to "read whole" (null) new, O(k)
Named list read: json_each(?) CROSS JOIN items WHERE items.uid = … (bot-items-reads.ts:74), on the bots DB worker each items notice that names uids, at most one read in flight and ≥500 ms between reads, per open list k ≤ 100 uids k lookups by primary key, plus the existing per-status COUNT (it uses idx_items_owner_open, as base did) less. Base read every open item (pages of 101 until done) plus 50 Closed items with full bodies
views(named, summary) on main same k items one batched join of links and workers for k items; drops description, doneMeans and closeNote less. Base built views for all P = open + 50 items with full text
closedOnly Closed page (bots-items-owner-methods.ts:101) Show more, a Closed depth read again, the item walk's Next 50 rows one Closed page; it skips allOpenItems less. Base sent the whole open list with every page
mergeNamedBotItems in the renderer (bot-item-merge.ts:631) each named read that lands P items in the read, k named O(P + k·P), from the elsewhere scan at :664, plus a sort of P when something changed less. Base ran reuseEqualJson over the whole parsed P-item answer with bodies. At 10× fleet (about 5,000 open items in one bot, k = 100) the elsewhere scan is about 500k compares, at most about 2 per second
carriedPages / loadedItems / allShown (use-bot-items-closed-pages.ts) each change of read identity while Closed pages are loaded P + loaded Closed rows linear; one extra render-time setPages per named read less. Base read every loaded Closed page again on every read: depth × (open + 50) rows over RPC
botItemsNamedSince chain walk each render while pages.base !== read, and when a page lands merges since the base at most 20 hops, usually 1. A whole read has no step, so it stops in O(1) new, O(1)
steps WeakMap and WeakRef chain each merged read live reads keyed weakly and pointing back weakly, so a chain of reads is not kept alive no growth
useBotChatItems asks (use-bot-items.ts:120) items/workers notice for the bot uids ≤ listPageMax (100) one read in flight; asks made meanwhile are joined; a failed read leads to one whole read same in-flight rule as base; base always read whole

Subscriptions and publications

botsChanged publication. The only producer is BotChangeNotices. It sends on the next tick after a change, then at most one notice per 500 ms window per host. Desktop windows get it over IPC (bots:changed). Paired and remote clients get it through emitClientEvent. The PR changes the payload only: it adds itemUids, at most 100 uids per bot it names. The rate is unchanged:

  • idle: 0 frames/s before and after. The PR adds no timer and no poll.
  • under load: at most about 2 frames/s per host before and after.
  • frames that change nothing for a given reader: they are filtered out by botChangeConcerns, as in base, before any listener does work.

Desktop renderer listeners of orca:bots-changed at the head. All files are listed, changed or not. Each listener parses the scope with readBotChangeScope; that parse now copies itemUids (O(uids)).

Listener Interest What it does on a matching notice Changed by this PR?
use-bot-host-read.ts:300, one per mounted useBotHostRead (Items, Activity, chat tree) bot + read kinds request(ref, partsOf(scope)), gated on a visible window, joined per bot entry, with the read's minimum gap (Items: 500 ms) yes. Items now reads only the named uids; other reads still read whole
use-bot-items.ts:176 useBotChatItems, only while a chat filter is set bot + items/workers named or whole read, one in flight yes, same as above
use-bot-item-view.ts:130, the open item bot + items/workers one item read no
bot-host-refresh.ts:167 items + bot/automations/settings, any bot applies needsYou and reads nothing; a list notice reads the host list no
bot-host-per-bot-read.ts:142 (own chats, up-next unseen) their kinds (no items) per-host read no
use-bot-tidy-up.ts:67 bot + BOT_VIEW_KINDS Tidy-up read no
bot-mention-chats-read.ts:133 bot + chats – no
bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100, composio-key-client.ts:41, ComposioEventsCard.tsx:152, bot-host-orca-account.ts:125 settings/bot – no
bot-access-requests.ts:155 access – no
bot-group-list.ts:39, use-bot-group-transcript.ts:52 groups/bot – no
use-webhook-data.ts (BOTS_CHANGED_EVENT) raw – no

The phone listens through host-bot-refresh.ts and calls its own list-or-skip. That path is unchanged and simply ignores itemUids.

The shared host read in use-bot-host-read.ts. There is one entry per bot, shared by every surface that shows the bot. Reads go one at a time, with the minimum gap between starts. Asks are now joined as uids, falling back to the whole read when there are more than max or when any ask is whole. A read that names parts is merged only onto a good value. again now calls schedule rather than request, so it keeps the asks that came in meanwhile. A merge that changes nothing returns previous, so it tells no one. Hidden windows still keep a missed flag and read once when shown. Reads with no parts (Activity, chat tree) behave exactly as before. Idle wakeups: 0 before and after.

Regression classes

Class Disposition
Whole snapshot for one change Fixed by this PR. A change to 1 of P items now reads 1 item, not P plus the depth × (P + 50) re-read of loaded pages
Update published when nothing changed Disproved. mergeNamedBotItems returns previous when nothing changed, and both readers skip publishing it
No-op store write Disproved, for the same reason (use-bot-items.ts:89, use-bot-host-read.ts:345)
Hot-path rescans Matched but not a regression. bot-item-merge.ts:664 runs uids.some(… previous.items.some …), which is O(k·P) where a Set would make it O(k + P). The total work per notice is still well below base. Optional cleanup
Fixed-cadence poll / idle wakeups No matching code. The PR adds no timer
Hidden owners Disproved. The visibility gate in useBotHostRead is unchanged; useBotChatItems has never had one (pre-existing, and only while a chat filter is on)
Per-entity state outlives entity Disproved. steps is a WeakMap with WeakRef links back; pending.itemUids is reset with each notice
Unbounded fan-out Disproved. At most 100 uids per notice per bot, and uids is capped at 100 in the RPC params schema
Sync SQLite on main Disproved. store.list runs on the bots DB worker

Six questions

  1. Unused work paid for before the skip gate: reviewed. The summary drops the long texts before they are serialized. Named reads skip the open scan. closedOnly skips the open list.
  2. Ownership multiplying work: reviewed. There is one shared entry per bot. Group panels mount one MemberReader per member, as before. The PR adds no new owner.
  3. Which thread pays: reviewed. SQL runs on the DB worker. views runs on main, now for k items instead of P. The merge runs on the renderer and is linear apart from the bounded k·P scan above.
  4. Growth and progress: reviewed. Uids are capped at 100, with a fallback to a whole read. A failed named read leads to one whole read. One gap: a Show more page that lands after the chain of steps is no longer known is dropped, and the code returns more: true. A broken chain needs more than 20 merges, or the WeakRef'd intermediate read being garbage-collected, during one page fetch (that needs at least 2 merges, so at least 1 s at the 500 ms gap). The cost is then one 50-row page RPC thrown away per click. The user clicks again; nothing retries on its own (the item walk and Show more are both user-driven). This is not a perf regression.
  5. Execution host: reviewed. On SSH or remote hosts each named read is still one round trip, but it carries k rows instead of P. Older hosts ignore summary, closedOnly and uids and answer whole, and the client merges that answer.
  6. Obsolete work stops: reviewed. generation drops stale Closed reads. The live flags stop reads after unmount. Asks are joined into the one read in flight.

Residual gaps: no runtime measurement. I priced the k·P merge scan from source and did not run it at N or 10N.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 48d01c1

Verdict: no regression. This head adds no new idle wakeups, sends no extra notices, and makes no extra RPCs per notice. Each read is smaller than on base, and Closed pages are no longer read again on a named change. I found no P0 or P1. Three pre-existing items are listed below. None of them block this PR.

Evidence I collected: source-traced work counts at the production seams, plus a SQLite EXPLAIN QUERY PLAN and timing of the new named-uid query against the head schema (200k items, 20k per bot). I did not run the app, so this report makes no claims about renderer frame times.

Work the diff adds or changes

Work Trigger Population Bound
BotItemsHost.changed(items) groups uids by owner bot (bot-items-runtime.ts:170) Each item write: comment, status, snooze, write-support, worker-link change The items in one write O(items written). Same callers and same call count as base, so there are no new publications.
addBotChange collects per-bot itemUids (bot-change-scope.ts:134) Each changed() inside the 500 ms notice window uids per bot in the window Max 100 per bot (BOT_CHANGE_ITEM_UIDS_MAX). Past that the entry becomes null, the uids are left out of the notice, and the reader reads the list whole.
Notice payload carries itemUids Each botsChanged emit (IPC to each window, plus a client event to paired desktops and phones) Bots with a pure items change At most 100 uids × ~40 B per bot, so ≤4 KB per bot per notice and ≤2 notices/s
Named list read: json_each(?) CROSS JOIN items WHERE items.uid = named.value (bot-items-reads.ts:74) Each notice that names uids for a shown bot ≤100 named uids The plan is SCAN named followed by SEARCH items USING INDEX sqlite_autoindex_items_1 (uid=?), i.e. a PK lookup per uid. Measured 0.14 ms for 100 uids, vs 7.0 ms for one 101-row page of the whole open read (summary-less rows). The counts GROUP BY is unchanged per read (0.56 ms for a 20k-item bot). Links are joined only for the named rows.
summary rows (no description, done means or close note) Every desktop list read and Closed page All rows Up to 3 × 8,000 chars less per row on the wire. The open item view still reads its own copy (use-bot-item-view.ts).
closedOnly Closed page (owner-methods.ts:101) Show more, and a depth re-read 1 Closed page It skips allOpenItems, so each page now carries 50 rows instead of all open items + 50. This also covers the workers-notice path, which still re-reads the depth.
mergeNamedBotItems (bot-item-merge.ts:28) Each named read that lands P = the previous read's items (all open + ≤50 Closed) O(P), plus an O(P log P) sort only when something changed. It returns previous (no publish, no render) when nothing changed. Base parsed the whole read and ran reuseEqualJson over it, also O(P), so this is not worse.
botItemsNamedSince WeakRef step chain One render per new read in useBotItemsClosedPages, plus one Show more landing Hops between reads Max 20 hops. It holds the previous read only weakly, so the chain cannot grow. If the chain breaks it returns null, which falls back to base behaviour (read the depth again).
carriedPages, loadedItems, allShown (use-bot-items-closed-pages.ts) Each new read, and each Show more Read items + loaded pages Linear, memoized on read and the pages. They replace base's mergeBotItemsByUid, which was also linear. The render-time setPages stops once pages.base === read, so there is no loop.
useBotHostRead asks (addBotReadAsk, schedule) Each consumer's onBotsChanged Asks per shared entry One Set per bot entry, capped at 100 and then 'whole'. Reads without parts (activity, chat tree) always ask 'whole', the same as base.
useBotChatItems named reads Each notice for a chat-filtered list ≤100 uids One read in flight, the rest merged into the next one. Same RPC count as base. An unchanged named answer sets no state.

Publication: botsChanged with itemUids

  • Producer. BotChangeNotices (bot-change-notices.ts) sends a leading notice on the next tick, then at most one per 500 ms window. Its timer re-arms once after each notice and stops when nothing is pending.
  • Idle rate. 0 frames/s on base and on head. There is no timer, poll or IPC at idle on main, renderer or the daemon.
  • Rate under load. With 100+ agents writing items, the rate is ≤1 leading + 2/s, on both base and head. The PR adds no frames. Each frame is just larger by its itemUids (bounded as above).
  • Frames that carry no change for a reader. For a given Items list, a frame naming items outside its chat scope, or items whose fields are unchanged, still costs 1 RPC per shown bot. That is the same count as base. It now costs a ≤100-uid PK lookup instead of reading all open items and depth × (open + 50) Closed rows, and it produces 0 publishes and 0 renders (mergeNamedBotItems returns previous).
  • Debounce. The shared read keeps its 500 ms minimum gap, and asks that arrive during it are merged.

Listener census at head (orca:bots-changed, every listener)

Each listener runs readBotChangeScope, which now also filters itemUids (≤100 strings per bot). At ~25 listeners that is a few thousand typeof checks per frame at ≤2 frames/s, so microseconds.

Desktop renderer, app-lifetime (one each):

  • bot-host-refresh.ts:167, all kinds. An items notice with needsYou only applies the counts, with no RPC.
  • bot-tool-checks.ts:61, kinds settings/bot.
  • composio-client.ts:100, kinds settings/bot.
  • google-setup-run-store.ts:117, kinds settings/bot.
  • bot-access-requests.ts:155, kind access.
  • bot-group-list.ts:39, kinds groups/bot.
  • bot-host-per-bot-read.ts:142, used twice: bot-own-chats (chats/threads/bot) and bot-up-next-unseen (lookAround/bot).
  • use-webhook-data.ts:100, a raw listener for every kind while any webhook key is mounted (pre-existing).

Desktop renderer, per mount:

  • use-bot-host-read.ts:300, one per useBotHostRead consumer:

    • the items read: BotActivityPanel and MemberReader per group member. It now passes partsOf(scope).
    • the activity read (BOT_WORK_KINDS, no items): about 8 consumers.
    • the chat-tree read: about 4 consumers.

    Each consumer's request is merged into one entry per bot.

  • use-bot-items.ts:176, one per chat-filtered list (items/workers).

  • use-bot-item-view.ts:130, one per open item (items/workers).

  • use-bot-tidy-up.ts:67, BOT_VIEW_KINDS (no items).

  • bot-mention-chats-read.ts:133, one per ref (chats).

  • use-bot-group-transcript.ts:52, groups.

  • ComposioEventsCard.tsx:152 and composio-key-client.ts:41, settings.

  • bot-host-orca-account.ts:125, settings/bot.

Bridges (emitters into the window event):

  • app-lifetime-ipc-bridge.ts:80 for the local runtime.
  • runtime-client-ipc-bridge.ts:128 → emitPairedBotsChanged for paired hosts.
  • bot-host-listing.ts sends bare notices when a host comes back.
  • BotCloudSignInNotice.tsx.

Phone (client event stream, unchanged files):

  • host-bot-refresh.ts:61 drives use-route-bot, use-phone-bot-items, use-mobile-bot-tidy-up and use-phone-bot-chat-tree.
  • use-host-bot-chat-trees.ts:111.
  • use-host-bots.ts, use-bot-access-requests.ts and use-mobile-bot-group-transcript.ts.

The phone ignores itemUids and summary, and still reads whole, the same as base.

Listeners that do RPC work on a pure items notice for bot B:

  • the shared items read: 1 RPC per shown bot.
  • each chat-filtered list: 1 RPC.
  • each open item view: 1 RPC.
  • the webhook reader, if mounted.
  • the phone route.

Regression classes touched

Class Disposition
Update published when nothing changed Disproved. A named merge returns previous; the shared read checks value !== entry.value; useBotChatItems sets no state. A whole chat-filtered read still publishes a new identity when equal, but base did that on every read.
One change published as a whole snapshot This is what the PR fixes. One item change now produces one named read carrying that item.
Re-reading unchanged input This is also what the PR fixes. Loaded Closed pages are not read again on named reads, and depth re-reads skip the open list (closedOnly).
New idle wakeups No matching code: the PR adds no timer, interval or poll.
Fixed-cadence poll No matching code.
Per-entity state outlives entity Disproved. steps is a WeakMap keyed by read objects and its back-links are WeakRefs. entry.parts lives on the existing per-bot entry.
Hot-path rescans Disproved. The merges are linear in read size, run once per landed read, and use Map/Set lookups (the "one set lookup" commit removed the last .includes loop).
Unbounded fan-out Disproved. Named reads are capped at 100 uids on the host and in the renderer, then fall back to a whole read; there is one read in flight per entry.
Sync SQLite / fs The query runs in the existing items store remote, and the named query is a PK lookup (plan above).
Expensive code past a gate No gate removed. closedOnly adds a gate that skips work.

Six questions

  1. Unused work before the skip gate. Reviewed. Long texts are no longer built for list rows. Named reads build only the named rows. The remaining unused work is 1 RPC per out-of-scope frame, the same count as base.
  2. Ownership multiplying work. Reviewed. One shared read per bot across all consumers. Group panels mount one list per member bot, and each reads only for its own bot (itemUids[botId]).
  3. Which thread pays. Reviewed. Host: a ≤100-row PK lookup plus the existing counts query. Renderer: linear merges once per landed read.
  4. Growth and progress. Reviewed. Uid sets are capped (100); past the cap the reader reads whole. A failed named read is followed by a whole read (missed, 'whole'). A late Show more page whose step chain is lost is shown, and the depth is read again.
  5. Execution host. Reviewed. Paired hosts get the same notice through readBotChangeScope. An older host ignores uids, summary and closedOnly and answers whole; the merge then treats that answer as the named answer. An older client ignores itemUids. SSH/WSL: no new probes or spawns.
  6. Obsolete work stops. Reviewed. The generation and live guards are unchanged. The shared read keeps its visibility gate, and useBotChatItems keeps its lack of one (pre-existing, see below).

Pre-existing (not regressions, not blocking)

  • use-bot-item-view.ts:130. An open item view reads itself again (item read plus event pages) on every items or workers notice for its bot, even when itemUids does not name it. Under load that is ≤2 RPC/s per open item view. Fix: skip when botChangeItemUids(scope, id, kinds) is non-null and does not include uid.
  • use-bot-items.ts:176 (useBotChatItems). There is no document.visibilityState gate, so a hidden window reads on each notice (≤2/s). Fix: copy useBotHostRead's missed-while-hidden flag.
  • workers notices. Dispatch and worktree transitions (orca-runtime-bots.ts:370-381, orca-runtime-agent-transitions.ts:248) still make the bot's Items list read whole and read the Closed depth again, because botChangeItemUids returns null when another kind changed. With summary and closedOnly each of those pages now carries 50 summary rows instead of all open items, but the read count under worker churn is still 1 + depth per window.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head ab31860

Verdict: no regression. No new idle wakeups. The botsChanged rate is unchanged. Each item notice now does work that scales with the items it names, not with the whole list times the loaded Closed depth. I found three pre-existing amplifications next to this path; none of them is made worse by this PR. They are listed below as follow-ups and do not block it.

Evidence types: work counts proven from source; one SQLite query plan run on a 50k-row scratch table with the PR's schema and query. I read the new tests but did not run them, because this machine has no node_modules for the checkout. No timing, CPU or heap claims.

Work the diff adds or changes

Work Trigger / rate Population Bound (base → head)
BotItemsHost.changed groups uids by owner (bot-items-runtime.ts:170) every item write, status/snooze batch, comment, linked Dispatch row change items in that write O(items in write); same notify count as base
addBotChange per-bot uid sets (bot-change-scope.ts:149) each changed() inside one 500 ms window changed items per bot capped at BOT_CHANGE_ITEM_UIDS_MAX=100, then null (read whole); cleared every window
botChangeNotice adds itemUids ≤1 immediate + ≤1 per 500 ms per host bots in the window ≤100 uids per bot (~4 KB per bot at most)
Named list read bots.items.owner.list {uids} (bots-items-owner-methods.ts:84, bot-items-reads.ts:74) each items notice naming ≤100 uids, per open list (shared read, ≥500 ms apart) named uids 1 counts scan + k primary-key lookups (plan: SEARCH items USING INDEX sqlite_autoindex_items_1 (uid=?)) + views(k) with summaries. Base: all open items paged + 1 Closed page + full bodies for O+50 rows, then D more Closed-page reads, each re-reading all O open items. Example with O=200 open and D=5 loaded pages: base views 6×250 = 1,500 full rows per notice; head views k (usually 1) summary rows. Runs on the bots DB worker, not on Electron main.
summary views drop description, done-means and close note (each ≤8,000 chars) every list read rows bytes per row drop by up to ~24 KB
closedOnly Closed page (bots-items-owner-methods.ts:102) Show more, depth re-read 1 page base re-read every open item per page; head reads 51 rows
mergeNamedBotItems (bot-item-merge.ts:29) each named read that lands previous.items = O open + ≤50 Closed O(O+50) scan; sort only when something changed; returns previous (no publish) when nothing changed
botItemsNamedSince (bot-item-merge.ts:140) each render where pages.base !== read, and when Show more lands merge chain ≤20 hops; steps is a WeakMap holding WeakRefs, so it cannot pin old reads
carriedPages set during render (use-bot-items-closed-pages.ts:112) once per new named read while Closed pages are loaded loaded Closed rows R O(R + read); converges in one render (base becomes read)
loadedItems + allShown memos (use-bot-items-closed-pages.ts:153) each published read or page read + R O(read + R); replaces base's mergeBotItemsByUid, which was the same order
useBotChatItems named asks (use-bot-items.ts:126) chat-filtered list, per notice ≤100 uids one read in flight, waiting asks merged; a failed named read falls back to a whole read
botItemsClosedInTimeOrder endAt (bot-item-groups.ts:205) group panel render members O(members)

Subscriptions and publications

botsChanged producer (bot-change-notices.ts:40 → orca-runtime-bots.ts:325): sends one IPC frame per window (bots:changed) and one runtime client event per paired client or phone.

  • Idle: 0 frames/s in base and head. The diff adds no timer, interval, rAF or listener; the one subscribe( line is a moved hook.
  • Under load (a dozen agents writing items every few seconds, 100+ agents changing phase): ≤2 frames/s per host (one on the next tick, then one per 500 ms window), the same in base and head. Only the payload grows, by itemUids.
  • Frames carrying no change: a no-op item write (writeResult calls changed before checking eventId) still sends a frame, as in base. In head the Items list then reads 1 row and mergeNamedBotItems returns previous: 0 publishes and 0 Closed re-reads. In base the same frame cost a whole list read.

Renderer listeners of orca:bots-changed at head. The desktop renderer re-emits local frames from app-lifetime-ipc-bridge.ts:79 and paired-host frames from runtime-client-ipc-bridge.ts:128. Each onBotsChanged handler runs readBotChangeScope, which now also copies itemUids. That costs O(listeners × uids) per frame: about 50 listeners × 100 uids ≈ 5k string checks, ≤2×/s. This is negligible, and it stays under ~1M checks/s at 10× fleet (500 listeners × 10 bots × 100 uids × 2/s, the worst case).

Listener Lifetime / multiplicity Kinds Does an items frame cause work?
bot-host-refresh.ts:167 followBotHostNotices app, 1 bot, automations, settings, items items frames carry needsYou, so counts are applied and nothing is read
bot-access-requests.ts:155 app, 1 access no
bot-group-list.ts:39 while subscribed, 1 groups, bot no
bot-host-per-bot-read.ts:142 (own chats; Up next unseen) while subscribed, 1 each chats/threads/bot; lookAround/bot no
bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100 while subscribed, 1 each settings, bot no
composio-key-client.ts:41, ComposioEventsCard.tsx:152 per mounted card settings(, bot) no
bot-host-orca-account.ts:125 per mounted consumer (~7 sites) settings, bot no
use-bot-group-transcript.ts:52 per open group chat groups no
bot-mention-chats-read.ts:133 per watched bot ref in the chat picker chats no
use-bot-tidy-up.ts:67 per mounted Tidy-up BOT_VIEW_KINDS (no items) only workers frames
use-bot-host-read.ts:300 (activity, chats tree, items) per mounted surface × read (chats tree once per sidebar row); one read per bot, shared items read: items, workers items read: named read (≤2/s per open bot); visibility-gated
use-bot-items.ts:176 useBotChatItems per chat-filtered list (BotActivityPanel; one per member in a group panel) items, workers named read, one in flight
use-bot-item-view.ts:130 per open item items, workers whole item read on every items frame for the bot (pre-existing, see 2)
use-webhook-data.ts:100 (raw addEventListener, no scope filter) while the webhooks page has entries every frame refreshes every entry (pre-existing, see 3)

Mobile reads botsChanged from runtime client events (mobile/src/bots/*, home-bots-query.ts). It ignores itemUids and does whole reads as before, so its rate and work are unchanged.

Shared bot host read (use-bot-host-read.ts):

  • Idle: 0 timers.
  • Under load: ≤1 read per bot per 500 ms for items (1,000 ms for the chats tree), asks merged across surfaces, and a named or whole decision per batch.
  • An unchanged answer publishes nothing. That holds for a whole read (reuseEqualJson) and for a named read (merge returns previous).
  • finally → schedule keeps the min gap, as base's request did.
  • A hidden window marks the read as missed and does one whole read when it becomes visible.

Pre-existing (not regressions of this PR; follow-ups)

  1. Chat-filtered list republishes an equal whole read and re-reads the Closed depth.
    • Where: use-bot-items.ts:147 (last = next === last ? { ...next } : next). Base did the same through setRead({ value }).
    • Trigger: every workers frame for the bot (worker phase changes; ≤2/s under agent load) while a chat filter is active and Show more is loaded.
    • Cost: 1 whole read + D Closed-page reads per frame, even when nothing changed. Head makes each page cheaper (closedOnly) but keeps the re-read on purpose.
    • Fix: reuse an equal whole read, as the shared read does. Needs a decision on how deep pages get refreshed.
  2. An open item re-reads on every item change of its bot.
    • Where: use-bot-item-view.ts:130.
    • Trigger: any items/workers frame for the bot (≤2/s), not only frames that name its uid.
    • Fix: skip the read when botChangeItemUids(scope, botId, ['items','workers']) is non-null and leaves out its uid.
  3. Webhooks page refreshes every entry on every botsChanged frame.
    • Where: use-webhook-data.ts:100. The listener does no scope filtering, so items frames hit it too.

Candidates checked and disposed

  • Closed rows grow between whole reads. After Show more, a named read carries rows pushed off the first page into pages.items (carriedPages), so loaded rows R grow by one per newly Closed item until a whole read publishes and the depth is re-read. Base re-read the depth on every notice, so R stayed at 50·(D+1).
    • Head's R equals the Closed items newer than the loaded end, which is exactly what the list shows. It is output, not hidden work.
    • Any published whole read resets it: workers frames, >100 uids, unscoped frames, a failure, the window becoming visible again.
    • Price: per-frame cost O(R) in memos and rendering (rows are not virtualized). For example 50k closures/day across a 10× fleet split over 25 bots is ~2k per bot. R reaches that only if no whole read publishes all day.
    • Not a finding. A cap at depth·50 would bound it if wanted.
  • Counts scan. SELECT status, COUNT(*) … GROUP BY status runs on every named read and grows with the bot's item history. It is a covering-index range scan on the DB worker, and base ran it on every read too (plus D more times). Pre-existing, and reduced here.
  • Older host. It ignores uids, summary and closedOnly and answers whole. The renderer merges only the asked uids, so the cost equals base. It never sends itemUids anyway.

Regression classes touched

Class Disposition
Update published when nothing changed matched and disproved: a named read with no change returns previous, so 0 publishes and 0 Closed re-reads. The chat path's equal whole read is pre-existing (1)
One change published as a whole snapshot fixed by this PR: one item change reads k rows instead of (D+1)·(O+50)
Re-reading unchanged input fixed for Closed pages (named chain, closedOnly); the open-item view is pre-existing (2)
No-op store write returns new identities matched and disproved: mergeNamedBotItems keeps every unasked row's identity and reuseEqualJson keeps asked rows that are equal
Per-row derivation over the whole collection matched: loadedItems, allShown and merge are O(list) once per publish; there is no per-row global scan
Hot-path rescans matched and disproved: Set/Map lookups, no .find inside a loop
Per-entity state outlives the entity matched and disproved: steps is a WeakMap with WeakRef from; pendingMore and latest are refs per mounted hook
New wakeups in steady idle / fixed-cadence poll no matching code (no timers added)
Unbounded fan-out matched and disproved: one read in flight per bot (shared) and per chat list; uids ≤100 (zod .max, pending cap)
Sync fs/SQLite on Electron main matched and disproved: item SQL runs on the bots DB worker (BotItemsRemote)

Six questions

  1. Unused work before the gate: reviewed. Summary rows drop the long texts and the named read skips the open-list scan. Equal answers stop before publish.
  2. Ownership multiplication: reviewed. There is one shared read per bot. The chat-filtered read is per list, as in base; group panels get M members × 2 reads, as in base.
  3. Which thread pays: reviewed. SQL runs on the DB worker; the query plan uses the uid primary key. Renderer merges are O(list) per publish.
  4. Growth and progress: reviewed. uids are capped at 100. R growth is bounded by what is shown and reset by any whole read. The counts scan grows with history (pre-existing).
  5. Execution host: reviewed. Remote and paired hosts get the same frame rate plus a few KB of itemUids. Older hosts fall back to whole reads. Not exercised on Windows/Linux or a live SSH transport; there is no platform-specific code here.
  6. Obsolete work stops: reviewed. The generation guard drops late pages, and a dropped Show more is folded into the depth re-read (pendingMore). The shared read bumps latest and clears its timer on the last unsubscribe. useBotChatItems sets live to false.

Paths examined: main item RPC (owner list, writes, status, snooze, comment), bot-change notices and scope, the bots DB read SQL, renderer items, Closed pages, the shown list, group items, the shared host read and every orca:bots-changed listener. Residual gap: runtime timing at fleet scale was not measured.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 7dcac47 (final)

Verdict: one regression (P1). Notices that name items are much cheaper now. No idle wakeups were added, and the number of botsChanged frames is the same as base. But a whole read now always re-reads the full loaded Closed depth. For a workers frame that leaves the list unchanged, base read open + 50 rows and head reads open + D. Each of those rows also goes through the linked-worker join on Electron main.

Comparison: base = merge-base with origin/main, head = 7dcac47a5be merged onto current main. The counts come from reading the source. The SQLite query plans and timings come from an in-memory node:sqlite copy of the items schema. I did not run the app or take any app timing.

Finding

P1: a whole read re-fetches the loaded Closed depth even when nothing changed (src/shared/bots/bot-items-list-load.ts:30, with src/shared/bots/bot-change-scope.ts:201-204)

  • Trigger. Any botsChanged for the bot whose kinds include workers:

    • worker phase changes (botPhaseChangeScopes sends ['status','workers'])
    • dispatch rows (dispatchesApplied)
    • federated verdicts
    • worktree lifecycle

    botChangeItemUids returns null whenever another kind the list reads (workers) is in the frame. That holds even when the frame also names the linked items, which BotItemWorkerLinks.flush already does for dispatch changes. So the list reads whole: call({ closedLimit: max(50, D) }). This runs at most 2 reads/s per visible bot list (500 ms gap) and is gated on visibility. A busy bot with 100+ agents hits that cap.

  • Work per trigger, with O open items and D = 50·(k+1) Closed items after k Show mores:

    Case base head
    workers frame, list unchanged 1 RPC, O + 50 rows (use-bot-items-closed-pages.ts:43: pages.base === read skips the depth) 1 RPC, O + D rows
    workers frame, list changed (k+1) RPCs, (k+1)·(O + 50) rows 1 RPC, O + D summary rows
    items frame naming u ≤ 100 uids (k+1)·(O + 50) rows u rows

    In the first case head views D − 50 = 50k extra rows per frame. Every row with a dispatch link goes through views() → readLinkedWorkers (bot-items-runtime.ts:243) on Electron main. Per linked dispatch that is:

    • resolveWorkerLineage, getTask, getWorkerDispatch, getFederatedDispatch, all sync orchestration SQLite (bot-work-runtime.ts:96-115)
    • 2× existsSync (:166-167)
    • showManagedTerminalWorkspace
    • taskReport(getTask)

    The rows are then serialized, sent over IPC, and deep-compared in the renderer (reuseEqualJson), which throws the result away.

  • Price at the reference fleet. k = 10 (D = 550), most Closed items linked to a dispatch, 2 frames/s: about 1,000 extra linked-worker joins per second on main, at least 4 sync SQLite calls and 2 sync stats each. That is ≥ 4,000 sync SQLite calls/s and ≥ 2,000 existsSync/s, for as long as workers are active and the list is open. The ms/s is not measured. The count grows linearly with loaded depth, and each frame may carry no change.

  • Why it blocks. The PR's stated goal is to never re-fetch loaded Closed pages, and that holds only for frames that name items. On a frame that leaves the list unchanged, the work grows from O + 50 rows to O + D. That is work scaling with history depth on a repeated trigger, and nothing gates it before the expensive step.

  • Fix (not verified). Either option keeps head's gains on changed frames and goes back to base's O + 50 on unchanged ones:

    1. Make a workers frame resolvable to items. Main already maps dispatch → linked item uids (BotItemWorkerLinks.flush). Let the Items list read the named parts when the frame's only non-items kind is workers and its uids are present. For phase-change scopes, resolve pane → dispatch → linked uids the same way.
    2. Or, on a notice-driven whole read with a good previous value, read open items + the first Closed page only. Splice the deeper Closed rows from previous; changes to deep Closed rows already arrive named through dispatchChanged → itemUids. Keep the full-depth read for mount, a failure, coming back visible, and Show more.

    Guard: a counting BotItemsListCall with previous depth D = 550 and a workers-only ask. Assert that closedLimit (rows requested) is ≤ 50 + open, and that a named change still lands.

Work the diff adds or changes

Work Trigger Population Bound
BotItemsHost.changed builds itemUids (bot-items-runtime.ts:170) every item write (comment, status, snooze, write, dispatch link) items in the write O(items) once; addBotChange caps each bot at 100 uids (BOT_CHANGE_ITEM_UIDS_MAX), then sends null (whole read)
addBotChange/botChangeNotice itemUids map per change, inside the 0 / 500 ms notice window bots × ≤100 uids cleared per window (pending = null); no growth
uids list read (bots-items-reads.ts:73-91) items frame naming ≤100 uids, ≤2/s per visible list ≤100 PK lookups + scope counts plan: SCAN named → SEARCH items USING sqlite_autoindex_items_1 (uid=?), 0.23 ms for 100 uids at 20k and 200k rows. Counts use the covering idx_items_owner_open: 0.11 ms at 4k items/bot, 1.07 ms at 40k items/bot. That cost is also pre-existing on every whole read. Both run in the bots DB worker.
views(…, summary) every list read rows returned drops description, doneMeans and closeNote (up to 8,000 chars each); the linked-worker join is unchanged (see the finding)
closedOnly + closedLimit (bots-items-owner-methods.ts:100-123) Show more; a whole read deeper than 1,000 closedLimit ≤ 1,000 per call; allOpenItems skipped one call per 1,000 Closed rows; an older host ignores it and answers one page per call (same as base)
mergeNamedBotItems (bot-item-merge.ts) each named read L = open + loaded Closed O(L), plus a sort only on change; returns previous when unchanged (0 publishes)
appendBotItemsClosedPage Show more L + 50 O(L) per click
botItemsClosedLoaded each whole read with a previous value L O(L) filter
shared read requestMore / schedule(now) (use-bot-host-read.ts:160-196) Show more click 1 read clears the pending gap timer instead of adding one; waiters are resolved in finally and on the last unsubscribe
useBotChatItems asks (use-bot-items.ts:150-210) items/workers frame while a chat filter is set ≤100 uids, then whole one read in flight; more resolved on cleanup
useBotItemsShownList.loadMore Show more items shown one Set per click
botItemsClosedInTimeOrder endAt group panel render members now skips the Math.min(...closed) spread when endAt is known

Listener census at head

orca:bots-changed (desktop renderer; the PR changes only the rows marked ✱):

  • use-bot-host-read.ts:326: one per mounted useBotHostRead. Each listener also adds a visibilitychange listener. Reads are shared per bot, with one in flight and one queued.
    • ✱ itemsRead (items, workers): BotActivityPanel, plus one MemberReader per group member. Named read or whole read (see the finding).
    • activityRead and chatTreeRead: their partsOf is null, so they always read whole, the same as base.
  • ✱ use-bot-items.ts:196 useBotChatItems: only while a chat filter is set; one read in flight.
  • use-bot-item-view.ts:130: per open item (items, workers). Pre-existing: it re-reads on every frame for the bot, even one whose itemUids leave it out.
  • use-bot-tidy-up.ts:67, bot-mention-chats-read.ts:133, use-bot-group-transcript.ts:52 (groups)
  • bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100, composio-key-client.ts:41, ComposioEventsCard.tsx:152 (settings/bot)
  • bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167, bot-group-list.ts:39, bot-access-requests.ts:155, bot-host-orca-account.ts:125
  • webhooks/use-webhook-data.ts:100: raw addEventListener, while any key is subscribed

Each listener re-parses the scope (readBotChangeScope), now including itemUids: O(listeners × ≤100 uids × bots) string checks per frame. That is negligible.

Publication side:

  • main BotChangeNotices → notifier.botsChanged → IPC bots:changed per window (runtime-window-lifecycle.ts:55) → app-lifetime-ipc-bridge.ts:80
  • emitClientEvent → paired desktops (runtime-client-ipc-bridge.ts:128, emitPairedBotsChanged) and phones (host-bot-refresh.ts, use-host-bots.ts, use-host-bot-chat-trees.ts, home-bots-query.ts, host-worktree-refresh.ts, use-host-screen-controller.ts). Phones ignore itemUids and read whole, as before.

Rates.

  • Idle: 0 frames/s at base and at head. No new timer or poll; the trailing 500 ms window timer fires once after a burst, as in base.
  • Under load: per host, one frame on the next tick, then at most 1 per 500 ms (about 2/s). The count is unchanged from base, because the PR adds no emit site. Payload grows by at most 100 uids per bot.
  • Frames with no change: the same count as base. For a frame that concerns another bot or kind, botChangeConcerns drops it with no read. For an items frame naming uids whose rows are unchanged, the read is ≤100 PK rows and causes 0 publishes. A workers frame with no change costs O + D rows (the finding).

Regression classes

Class Disposition
No-op store write disproved: mergeNamedBotItems returns previous, and the shared read notifies only on a new identity
Update published when nothing changed disproved: no new emit site; same frame count
Whole snapshot for one change fixed for items frames (u rows instead of (k+1)(O+50)); finding for workers frames (O + D)
Re-reading unchanged input finding (the loaded depth is re-read for an unchanged list)
Sync fs/SQLite on Electron main the linked-worker join is pre-existing; the PR newly reaches it for D − 50 more rows per unchanged whole read (part of the finding)
Fixed-cadence poll / idle wakeups no matching code
Per-entity state outlives the entity disproved: per-window itemUids and the more waiters are cleared on send and on unsubscribe/cleanup
Unbounded fan-out disproved: uids ≤ 100 (schema max), closedLimit ≤ 1,000, one read in flight per bot
Hot-path rescans disproved: O(L) per read, no nested scans

Six questions

  1. Unused work before the skip gate: finding. A workers whole read builds O + D views, and reuseEqualJson then discards them.
  2. Ownership multiplication: reviewed. One shared read per bot across surfaces. useBotChatItems is per chat-filtered list, the same as base.
  3. Thread and storage: the uids query runs in the bots DB worker and uses the PK (plan above). views() link joins run sync SQLite and fs on main (finding).
  4. Growth and progress: uid sets capped at 100; above that the list reads whole. A failed read makes the next read whole. A deep depth pages at 1,000 per call and advances the cursor.
  5. Execution host: an older host ignores summary/closedOnly/closedLimit/uids and never sends itemUids, so the list reads whole one page per call, as in base. A paired host's frames carry itemUids through readBotChangeScope. On SSH hosts each extra RPC costs a round trip; the named path cuts the number of rows, not the number of round trips.
  6. Obsolete work: the latest bump and the cleared timer on the last unsubscribe; requestMore waiters resolved with null; live = false in useBotChatItems. There is no hidden-window work: the read is gated on visibility and catches up when the window shows again.

Not inspected: ms per linked-worker join on a real profile (not measured); Windows existsSync cost on main.

…er; show an older host's first page while it pages down; failed Show more rejects; keep a filter's depth across Retry
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 75e17cf (final)

Verdict: two regressions (P1). Items frames that name their items now cost u rows instead of (k+1)·(O+50). No idle wakeups were added, and the botsChanged frame count is unchanged. Worker frames now resolve to the loaded items that link a worker, so the earlier finding is fixed while that set is ≤100. Two cases still re-read the full loaded Closed depth on frames that leave the list unchanged:

  • a bot with more than 100 loaded linked items, on the current host
  • any whole read against an older host, which now pages down every time

Comparison: base = merge-base with origin/main, head = 75e17cf6bfc merged onto current main. The counts below come from reading the source. One micro-measurement was run in plain Node (the scope parse below). I did not run the app or take any app timing.

Notation: O = open items, D = 50·(k+1) Closed items loaded after k Show mores, L = O + D.

Findings

P1-1: on a bot with more than 100 loaded linked items, a workers frame still reads O + D rows (src/shared/bots/bot-items-notice-parts.ts:36-43, src/renderer/src/components/bots/bot-host-read-asks.ts:22, src/shared/bots/bot-items-list-load.ts:29-35)

  • Trigger. Any frame for the bot with kind workers, at most 2/s per visible Items list (500 ms gap):

    • worker phase changes (['status','workers'])
    • dispatchesApplied
    • federated verdicts
    • worktree lifecycle
  • What happens. botItemsNoticeParts adds every loaded item with a dispatch link. That includes Closed items whose worker settled long ago. Once that set passes maxParts (100), addBotReadAsk turns it into 'whole'. The whole read then asks closedLimit: max(50, D).

  • When it applies. The set passes 100 as soon as the first Closed page plus the open items hold 100 linked items. For a bot with D = 550 that is already the case.

  • Cost on an unchanged frame. Base: 1 RPC of O + 50 rows (use-bot-items-closed-pages.ts skipped the deeper pages while pages.base === read). Head: 1 RPC of O + D rows. Every linked row goes through views() → readLinkedWorkers on Electron main: resolveWorkerLineage, getTask, getWorkerDispatch, getFederatedDispatch (sync orchestration SQLite) and 2× existsSync (bot-work-runtime.ts:96-167). The renderer then deep-compares the result and throws it away.

  • Price at the reference fleet. k = 10, mostly linked, 2 frames/s: about 1,000 extra linked-worker joins per second on main. That is ≥ 4,000 sync SQLite calls/s and ≥ 2,000 existsSync/s while workers are active. The ms/s is not measured. It grows linearly with loaded depth.

  • Fix (not verified). Either:

    1. Have main resolve the frame to items. Phase and dispatch changes are already mapped dispatch → linked uid in BotItemWorkerLinks.flush, so workers frames could carry itemUids too.
    2. Or count only links whose worker is not settled when building the worker parts, so settled Closed rows don't push the set past 100.

    Also, on a notice-driven whole read with a good previous value, read the open items plus the first page and splice the deeper rows from previous (withLoadedBelow already does this). Keep full depth for the first read, a failure, coming back visible, and Retry.

  • Guard. A counting BotItemsListCall with previous D = 550 and 150 linked items, sent a workers-only frame. Assert that the rows requested are ≤ O + 50, and that a named change still lands.

P1-2: an older host is paged down in full on every whole read (src/shared/bots/bot-items-list-load.ts:39-49)

  • Trigger. Every items frame from a paired host running a build before this PR, at most 2/s per visible list. Such a host never sends itemUids, so botItemsNoticeParts returns null and the read is whole. It sends these frames for every Dispatch row write of a linked worker, heartbeats included (BotItemWorkerLinks.flush → changed).
  • What happens. That host ignores closedLimit, closedOnly and summary. The while loop therefore makes k more calls, and each answer carries every open item with full bodies plus 50 Closed rows. appendBotItemsClosedPage then keeps only the Closed rows.
  • Compared with base. Base made 1 RPC of O + 50 rows and re-read the deeper pages only when the first page's identity changed. Head makes k + 1 RPCs of O + 50 full-body rows on every frame, changed or not. That brings back the pattern this PR set out to remove, and now on unchanged frames too.
  • Price at the reference fleet. O = 200, k = 4, 2 frames/s: 10 RPCs/s instead of 2. That is about 2,500 joined rows/s on the old host's main instead of 500, and about 4× the bytes over the paired transport, each RPC a round trip on SSH. It grows with k × O.
  • Fix (not verified). When the first answer shows the host ignored closedLimit, page down only if that answer differs from previous's matching prefix (base semantics). Otherwise return withLoadedBelow(value, previous) as the final value.
  • Guard. In bot-items-list-load.test.ts, extend the older host fake to count calls. With an unchanged list and D = 250, a whole ask makes 1 call. A changed first page still pages down.

Work the diff adds or changes

Work Trigger Population Bound
BotItemsHost.changed builds itemUids (bot-items-runtime.ts:170) item writes: comment, status, snooze, write, dispatch link items in the write O(items) once per write
addBotChange / botChangeNotice itemUids (bot-change-scope.ts) each change inside the 0 / 500 ms window bots × uids 100 per bot (BOT_CHANGE_ITEM_UIDS_MAX), then null (whole); cleared every window
uids list read (bot-items-reads.ts:73-91) a frame naming ≤100 parts ≤100 PK lookups + the scope count runs in the bots DB worker: json_each → items PK, then a covering-index count (that count already ran on every base read)
views(…, summary) every list read from the desktop rows returned drops 3 texts of up to 8,000 chars each; the linked-worker join is unchanged
closedOnly / closedLimit (bots-items-owner-methods.ts:100-123) Show more; whole read ≤1,000 Closed rows per call skips allOpenItems for a Closed page
stillOpen filter each whole read O one Set
botItemsNoticeParts (bot-items-notice-parts.ts) each concerning frame, per useBotHostRead(itemsRead) mount and per useBotChatItems L × links O(L) scan; see P1-1
mergeNamedBotItems each named read L O(L), sorts only on a change, returns previous when unchanged (0 publishes)
appendBotItemsClosedPage Show more L + 50 O(L) per click
whole-read loop (bot-items-list-load.ts:29-50) whole ask D 1 call on the current host (closedLimit ≤ 1,000 each); D/50 calls on an older host (P1-2)
shared read requestMore / schedule(now) (bot-host-read-store.ts) Show more 1 read clears the gap timer instead of adding one; waiters resolved in finally and on the last unsubscribe
useBotItemsShownList.loadMore Show more items shown one Set per click
botItemsClosedInTimeOrder endAt group panel render members now skips the Math.min(...closed) spread when endAt is known

Listener census at head (orca:bots-changed, desktop renderer)

Producers:

  • local: main BotChangeNotices → runtime-window-lifecycle.ts:55 IPC bots:changed per window → app-lifetime-ipc-bridge.ts:80
  • paired: emitClientEvent → runtime-client-ipc-bridge.ts:128 (emitPairedBotsChanged)

Phones get the same client event and ignore itemUids (mobile/src/bots/*: host-bot-refresh, use-host-bots, use-host-bot-chat-trees, use-route-bot, items/use-phone-bot-items, home-bots-query, host-worktree-refresh, use-host-screen-controller). Pre-existing: the phone Items list still re-reads whole plus every loaded page, each carrying the open list.

Window listeners (✱ = changed or newly reached by this PR):

  • ✱ use-bot-host-read.ts:109: one per mounted useBotHostRead, gated on visibility, with one visibilitychange listener each. One shared read per bot, one in flight.
    • ✱ itemsRead (items, workers): BotActivityPanel, plus one MemberReader per group member. Each frame runs partsOf, which is O(L), then a named read or a whole read.
    • activityRead, chatTreeRead (per sidebar bot and the panel): no options, so partsOf returns null and they read whole, as in base.
  • ✱ use-bot-items.ts:206 useBotChatItems: only while a chat filter is set. Not gated on visibility (pre-existing).
  • use-bot-item-view.ts:130: per open item (items, workers). Pre-existing: it re-reads on every frame for the bot, even one whose itemUids leave the item out.
  • use-bot-tidy-up.ts:67 (BOT_VIEW_KINDS), bot-mention-chats-read.ts:133 (chats, per ref), use-bot-group-transcript.ts:52 (groups)
  • bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100, composio-key-client.ts:41, ComposioEventsCard.tsx:152 (settings/bot)
  • bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167 (every frame; needs-you fast path), bot-group-list.ts:39, bot-access-requests.ts:155 (access), bot-host-orca-account.ts:125
  • webhooks/use-webhook-data.ts:100: raw listener while any key is subscribed

Every listener re-parses the scope (readBotChangeScope) before its interest check, which now includes itemUids. Measured in plain Node: 0.76 µs for 100 uids and 2.3 µs for 1,000. At about 40 listeners × 2 frames/s that is ≤ 0.2 ms/s even at 10× fleet. Not a finding; parsing once at the producer would remove it.

Rates.

  • Idle: 0 frames/s at base and at head. No new timer, poll or subscription. The trailing 500 ms window timer fires once after a burst, as in base. The paired-workspace refresh (15 s → 120 s backoff, visible only) is pre-existing.
  • Under load: per host, one frame on the next tick, then at most 1 per 500 ms (about 2/s), the same as base. The payload grows by at most 100 uids per bot.
  • Frames with no change: the same count as base. Most frames under load are Dispatch heartbeats, which re-name linked items even when their view is unchanged (pre-existing). On the current host each one costs ≤100 PK rows and 0 publishes when the parts set is ≤100. Two cases cost more: O + D rows (P1-1), and (k+1)·(O+50) from an older host (P1-2).

Regression classes

Class Disposition
No-op store write disproved: mergeNamedBotItems returns previous; the shared read and useBotChatItems publish only on a new identity
Update published when nothing changed disproved for the diff: no new emit site. Heartbeat frames that change nothing are pre-existing
Whole snapshot for one change fixed for named items frames; finding P1-1
Re-reading unchanged input findings P1-1 and P1-2
Sync fs/SQLite on Electron main the linked-worker join is pre-existing; P1-1 reaches it for D − 50 more rows per frame
Fixed-cadence poll / idle wakeups no matching code
Hidden owners useBotHostRead is gated on visibility; useBotChatItems and the item view are not (pre-existing, unchanged)
Per-entity state outlives the entity disproved: entries deleted on the last unsubscribe; pending.itemUids cleared every window; kept ref per hook instance
Unbounded fan-out disproved: uids ≤ 100 (schema max), closedLimit ≤ 1,000, one read in flight per bot; the group panel's Show more is one read per member
Hot-path rescans disproved: O(L) per read, no nested scans

Six questions

  1. Unused work before the skip gate: finding. Whole reads build O + D views (P1-1), or k + 1 old-host pages (P1-2), that reuseEqualJson then discards.
  2. Ownership multiplication: reviewed. One shared read per bot across surfaces. partsOf runs once per mounted listener, O(L) each. useBotChatItems is one per chat-filtered list, as in base.
  3. Thread and storage: the uids query runs in the bots DB worker on the PK. views() link joins run sync SQLite and fs on main (P1-1).
  4. Growth and progress: uid sets capped at 100, then whole. A failed parts read makes the next read whole. Deep reads page by 1,000 and advance the cursor.
  5. Execution host: P1-2 (an older paired host). A current paired host's frames carry itemUids through readBotChangeScope. On SSH every extra RPC is a round trip.
  6. Obsolete work: the last unsubscribe bumps latest, clears the timer and resolves the more waiters with null. A whole read already in flight finishes its loop after close: one bounded tail of ≤ ⌈D/1000⌉ calls, or D/50 on an older host, with no retry.

Not inspected: ms per linked-worker join on a real profile, existsSync cost on Windows, and whether a heartbeat-only Dispatch write changes the item view on an older host. If it does, P1-2 equals base for those frames.

… host's whole answer to a named read is read whole
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 1eec284 (final)

Verdict: three regressions (P1). None is fleet-scaled. The PR's main goal holds on a current host:

  • An items frame reads only the u named rows, not (k+1)·(O+50).
  • A workers frame tagged workersNamed reads nothing. Its items arrive in their own named items frame.
  • Show more is one closedOnly read.
  • No idle wakeups were added.

Three costs remain:

  1. An older paired host gets two whole reads per worker frame where base made one.
  2. Every agent phase change now runs the pane's orchestration projection twice on Electron main.
  3. A linked worker's phase change now sends a second botsChanged frame when changes are sparse.

How this was checked:

  • Base is the merge-base with origin/main (edf6acdf70b). Head is 1eec2843dbe merged onto current main.
  • Every count below comes from reading the source.
  • Nothing was run: no app, no timing, no test.

Notation: O = open items, D = Closed items loaded (50·(k+1) after k Show mores), L = O + D, u = uids named.

Findings

P1-1: on an older host, a named read that comes back whole is thrown away and read again (src/shared/bots/bot-items-list-load.ts:31-35)

  • Who hits it. A paired host on a build before this PR. It never sends workersNamed.
  • Trigger. Each workers frame from that host, at most 2/s per visible list (ITEMS_MIN_READ_GAP_MS). Sources: phase changes ['status','workers'], Dispatch row writes (heartbeats included), federated verdicts.
  • How it gets there. botItemsNoticeParts adds every loaded item with a working/unknown dispatch link. That is the normal state while any item's worker runs, so the ask becomes a named read.
  • What happens.
    • call({ uids }) goes out. The old host ignores uids and summary, and answers with every open item at full body plus the first 50 Closed rows.
    • Line 34 sees items it didn't ask for, drops that answer, and recurses with whole: true.
    • The recursion's call({ closedLimit }) gets the same answer again, since the old host also ignores closedLimit.
    • When D > 50 and the first page moved, the paging loop follows, as in base.
  • Compared with base. Base made 1 RPC of O + 50 full-body rows per frame. Head makes 2.
  • Price at the reference fleet. O = 200, 2 frames/s while workers run:
    • 4 RPCs/s instead of 2, about 1,000 joined rows/s on the old host's Electron main instead of 500
    • every linked row's views() join does sync orchestration SQLite and existsSync (bot-work-runtime.ts)
    • double the bytes over the paired transport, each RPC a round trip on SSH
    • grows with O
  • Fix (not verified). The discarded answer is exactly what that host returns for the whole read. Hand it to the whole path as its first page (for example, a first value that replaces the first call) instead of calling again. uids and closedLimit ship together, so a host that ignored one ignored the other. Optionally remember per host that uids isn't supported, so later frames skip the named attempt.
  • Guard. In bot-items-list-load.test.ts, count calls on the older host fake. A named ask with D = 50 should make 1 call, and the named change should still land.

P1-2: each agent phase change runs getAgentStatusOrchestrationContextForPaneKey one extra time on main (src/main/bots/bot-change-notices.ts:159 and :125, src/main/runtime/construction/orca-runtime-agent-transitions.ts:229-230)

  • Trigger. Every non-observed agent transition while the host has bots. That covers every pane, workers or not. With 100+ agents this is a few per second.
  • What happens.
    • followAgentPhasesForBots calls facts.workerDispatch(paneKey).
    • Then botPhaseChangeScopes calls it again for the same change.
    • botOfPane can call it a third time when the index has no pane.
    • Base made one call (workerPane), plus the botOfPane fallback.
  • Cost per call.
    • getTerminalHandleForPaneKey
    • orchestrationProjectionFacts(...).refresh(now), which reads the version/revision and dirty keys through sync SQLite
    • getActiveDispatchForTerminal or getLatestDispatchForTerminal
    • composeOrchestrationDispatch for a worker
  • Price. The work per call is constant and does not grow with the fleet. The ms is not measured. It is new, repeated work on a status-update path on Electron main.
  • Fix. Resolve dispatchId once in followAgentPhasesForBots and pass it into botPhaseChangeScopes. botOfPane can take it too.
  • Guard. A BotPaneFacts fake that counts workerDispatch calls: one transition makes exactly 1 call.

P1-3: a linked worker's phase change now sends two frames where base sent one (src/main/bots/bot-change-notices.ts:159-166, src/main/runtime/orca-runtime-bots.ts:370-374)

  • The order of events.
    1. workerChanged queues the BotItemWorkerLinks.flush microtask.
    2. notices.changed({status, workers, workersNamed}) arms wait(0).
    3. The flush awaits bots-DB worker round trips: links(uid) for an item-started worker, linksTo, then viewRows.
    4. setTimeout(0) fires first, so frame 1 carries status/workers.
    5. The items scope lands after that and goes out in a second frame at the end of the 500 ms window.
  • Federated verdicts follow the same order.
  • Who pays per extra frame. The new desktop Items list is fine: frame 1 gives parts [] and 0 RPCs; frame 2 is a named read of u rows. The others:
    • the open item view (use-bot-item-view.ts:130) re-reads on both frames. Pre-existing: it ignores itemUids.
    • an older desktop client reads its whole list plus k pages on each frame
    • a foreground phone re-reads the host's bots on each frame (host-worktree-refresh.ts:100)
    • use-webhook-data.ts:100 reacts to any frame
    • the host runs one needsYouCounts() per items frame
  • Bound. At most 2 frames/s per host, the same ceiling as base. The extra frame appears only when changes are sparser than one per 500 ms. Dispatch row writes already had this split in base (botDispatchChanged); the PR extends it to phase changes and federated verdicts.
  • Price. Per isolated linked-worker transition: 1 → 2 frames, and 1 → 2 item-view reads and phone bot-list reads. Under sustained load: 0 extra.
  • Fix (not verified). Add the workers scope after the dispatch flush settles, so both go out in one frame. For example, dispatchChanged returns the flush promise and the caller adds both scopes when it resolves. Separately, the item view could skip frames whose itemUids leave its uid out, and workersNamed frames.
  • Guard. A BotChangeNotices test with fake timers and a deferred viewRows: one linked phase change emits 1 frame carrying both workers and itemUids.

Cost of dispatchChanged per worker status change (Electron main)

  • Sync, in the microtask flush:
    • dispatchItemUid: 1 dispatch_contexts PK read
    • lineageAncestors: 1 + depth PK reads, depth ≤ 100, typically 1–2, memoized per flush
    • ids is a Set, so phase changes in the same tick share one flush
  • Async, off main:
    • item-started workers: store.links(uid) on every call, even when already linked. This was pre-existing on every Dispatch row write; phase changes newly reach it.
    • linkedDispatches() is cached until the next items write. After a write, one SELECT DISTINCT ref FROM item_links WHERE kind='dispatch' runs, and the Set is cloned to main. That is O(dispatch links in history), at most once per items write, as in base.
    • only when the lineage is linked: linksTo (indexed idx_item_links_ref), then viewRows, then changed → one items scope (≤ 100 uids per bot) and one needsYouCounts.
  • Overall. Constant per transition. It does not grow with worktrees, agents or open items. It replaces, on the current host, the whole-list read that each worker frame used to cost. Not a finding apart from P1-2 and P1-3.

Work the diff adds or changes

Work Trigger Population Bound
BotItemsHost.changed → itemUids item writes (comment, status, snooze, write, worker link) items written O(items) once per write
addBotChange / botChangeNotice itemUids, workersNamed each change in the 0 / 500 ms window bots × uids 100 per bot, then null (whole); cleared every window
dispatchChanged from phase changes and federated verdicts (new trigger) non-observed worker transitions; changed federated ids dispatches changed see above; microtask-batched
extra workerDispatch lookup every non-observed transition with bots 1 pane P1-2
uids list read (bot-items-reads.ts:73-91) named read ≤ 100 PK lookups + the scope count bots DB worker; the count ran on every base read too
views(…, summary) every desktop list read rows returned drops 3 texts of ≤ 8,000 chars each
closedOnly / closedLimit Show more; whole read ≤ 1,000 Closed rows per call skips allOpenItems
botItemsNoticeParts each concerning frame, per mounted useBotHostRead(itemsRead) / useBotChatItems L × links O(L). Current host: workersNamed skips the scan's purpose. Older host: only working/unknown links
mergeNamedBotItems each named read L O(L); sorts only on a change; returns previous when unchanged
loadBotItemsList whole path whole ask D 1 call on the current host; old host: P1-1 plus k pages when the first page moved, else sameFirstPage returns previous
shared read store (bot-host-read-store.ts) asks, Show more 1 read per bot in flight gap timer only on an ask; entry deleted on the last unsubscribe; more waiters resolved

Listener census at head (orca:bots-changed and botsChanged)

Producers:

  • local: BotChangeNotices → orca-runtime-bots.ts:327-328 → IPC → app-lifetime-ipc-bridge.ts
  • paired: client event → runtime-client-ipc-bridge.ts:128

Desktop window listeners. Each re-parses the scope (readBotChangeScope), now including itemUids, at ≤ 100 uids per bot. ✱ marks a listener the PR changes or newly reaches.

  • ✱ use-bot-host-read.ts:109: one per mounted useBotHostRead, gated on visibility. Consumers:
    • itemsRead [items, workers]: named reads via partsOf
    • activityRead and chatTreeRead (BOT_WORK_KINDS): read whole, as in base
  • ✱ items/use-bot-items.ts:206 useBotChatItems: only while a chat filter is set; not gated on visibility (pre-existing)
  • items/use-bot-item-view.ts:130: open item [items, workers]; ignores itemUids (P1-3)
  • use-bot-tidy-up.ts:67 (BOT_VIEW_KINDS), bot-mention-chats-read.ts:133 (chats), use-bot-group-transcript.ts:52 (groups)
  • settings/bot: bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100, composio-key-client.ts:41, ComposioEventsCard.tsx:152
  • bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167 (an items frame with needsYou reads nothing), bot-group-list.ts:39, bot-access-requests.ts, bot-host-orca-account.ts
  • webhooks/use-webhook-data.ts:100: raw listener on any frame

Phones: mobile/src/worktree/execution-hosts/host-worktree-refresh.ts:100 re-reads on any foreground frame. The other phone bot readers ignore itemUids.

Rates:

  • Idle: 0 frames/s at base and at head. No new timer, poll or IPC. The microtask flush and the shared-read gap timer run only on a change.
  • Under load: per host, one frame on the next tick, then ≤ 1 per 500 ms (≤ 2/s), the same as base.
  • Frames with no change: under load, most frames are Dispatch heartbeats and phase changes that leave the item view unchanged (pre-existing). Current host: each costs ≤ u PK rows and 0 publishes. Older host: 2 × (O + 50) rows (P1-1). Sparse changes: +1 frame per linked phase change (P1-3).

Regression classes

Class Disposition
Update published when nothing changed P1-3 (split frame); heartbeat frames are pre-existing
One change published as a whole snapshot fixed for current hosts (named items, workersNamed)
Re-reading unchanged input P1-1
Sync SQLite on Electron main P1-2 (duplicate projection); flush PK reads constant
No-op store write disproved: mergeNamedBotItems and reuseEqualJson return previous; publish only on a new identity
Fixed-cadence poll / idle wakeups no matching code
Per-entity state outlives the entity disproved: read entries deleted on the last unsubscribe; pending cleared per window; flush Set swapped per flush
Unbounded fan-out disproved: uids ≤ 100 (schema), closedLimit ≤ 1,000, one read in flight per bot
Hot-path rescans disproved: O(L) per read, no nested scans

Six questions

  1. Unused work before the skip gate: P1-1, an old-host answer is discarded and fetched again. Otherwise reads are gated by parts.
  2. Ownership multiplication: reviewed. One shared read per bot; partsOf O(L) per mounted listener; the item view is unfiltered (P1-3).
  3. Thread and storage: P1-2 on main. The uids query runs on the PK in the bots DB worker. Flush PK reads are constant.
  4. Growth and progress: uid sets capped at 100, then whole. A failed read makes the next read whole. Deep reads page by 1,000.
  5. Execution host: P1-1 (older paired host). On SSH each extra RPC or frame is a round trip.
  6. Obsolete work: the last unsubscribe bumps latest, clears the timer and resolves the waiters. An in-flight whole read finishes a bounded tail.

Not measured: ms per projection lookup and per linked-worker join on a real profile, and the Dispatch heartbeat cadence (it sets how often P1-3's extra frame shows).

Correctness note (not perf): with an older host and D > 50, the recursion at bot-items-list-load.ts:35 can return previous via sameFirstPage. A named row on page 2+ is then not refreshed until a later read.

… a worker's phase goes out with its items' notice; one Dispatch lookup per phase change
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan at 02767ff3546: no regression

The scan covers the PR diff against its merge-base with main, read on a checkout merged onto current main. The work counts come from reading the source. Nothing was timed: no app run, no profile, no benchmark.

Findings

No P0 or P1. The three P1s from the scan of 1eec2843dbe are fixed at this head:

Earlier finding At this head
P1-1: a named read sent to an older host got a whole answer, threw it away, and read whole again Can't happen any more. botItemsNoticeParts (bot-items-notice-parts.ts) names items only when the notice carries itemUids. A workers change counts as named only when it carries workersNamed, and an older host sends neither. So an older host always gets one whole read, which costs what base cost. The fallback at bot-items-list-load.ts:34 is still there as a guard, but nothing reaches it.
P1-2: an extra getAgentStatusOrchestrationContextForPaneKey lookup on each phase change Fixed. followAgentPhasesForBots (bot-change-notices.ts:159) resolves dispatchId once and passes it to botPhaseChangeScopes. That is one lookup per transition, plus the botOfPane fallback, the same as base.
P1-3: a linked worker's phase change sent two frames Fixed. The status/workers scope is now added inside workerChanged(dispatchId).then(tell) (bot-change-notices.ts:165). The federated path uses Promise.all(told).then(...) (orca-runtime-bots.ts:370-376). BotItemWorkerLinks.dispatchChanged resolves after changedItems has called notify, and only microtasks run between the two calls. The wait(0) timer can't fire in that gap, so both scopes leave in one frame.

Optional tidy-up, not a regression. Each worker phase change now runs BotItemWorkerLinks.flush (bot-item-worker-links.ts:47-78), and two parts of it repeat work:

  • It reads the worker's own Dispatch row twice: once in dispatchItemUid and again as the first step of lineageAncestors.
  • For a worker started from an item, link() calls store.links(uid) (:87) on every phase change, even when the item already links the worker. Checking the cached linkedDispatches() first would skip that call.

Each costs one primary-key read: on main for the first, in the bots DB worker for the second. Neither grows with the fleet. Head's total for this trigger is already below base's (see "Main-process cost per agent phase change").

Pre-existing, not changed by this PR

These are the same in base and at this head.

  • Open item view (items/use-bot-item-view.ts:130). It re-reads the open item on every items/workers frame for its bot. That includes frames whose itemUids leave its uid out, and workersNamed frames that changed nothing for it. Using itemUids would let it skip those.
  • Phone Items list (mobile/src/bots/items/use-phone-bot-items.ts:62, :91). On every items/workers frame it still reads the whole list with full text fields. It then re-reads each loaded Closed page, and each page carries the whole open list again, because it doesn't send closedOnly. The problem this PR fixes on desktop is unchanged on phones.
  • Per-listener scope parsing (bots-changed-window-event.ts:51). Each onBotsChanged listener parses the scope again. With this PR that includes itemUids, capped at 100 uids per bot: a few hundred string checks per listener per frame.

Main-process cost per agent phase change

  • Pane that is not a worker: unchanged. There is one workerDispatch lookup, which replaces base's workerPane, and no flush.
  • Worker pane (new trigger for BotItemsHost.dispatchChanged): one flush per microtask. Changes in the same tick share it, because the ids are a Set.
Step Where it runs Count per change
dispatchItemUid main, sync SQLite (dispatch_contexts primary key) 1
lineageAncestors (only when some item links some Dispatch) main, sync SQLite (primary key) 1 + depth (capped at 100, usually 1–2), memoized per flush
linkedDispatches() bots DB worker cached; one SELECT DISTINCT ref after each items write, as in base
worker started from an item bots DB worker +1 links(uid)
worker an item links bots DB worker +linksTo (indexed) and +viewRows for the linked uids. Then one items scope and one needsYouCounts per notice window, at most 2/s per host

The status/workers notice now waits for the flush. For a worker no item links, the flush makes no worker call while the cache is warm, so the wait is microtasks. Otherwise it waits for one to three bots DB worker round trips, capped by the worker's 10 s timeout. The promise never rejects (.catch(warn).finally(resolve)).

Price at the reference fleet:

  • Assumed rate: about 1–5 worker transitions per second.
  • Sync work on main: about 2–4 primary-key reads per transition, so roughly 3–20 reads/s. At 10× the fleet that is up to about 200 reads/s, a few ms/s at tens of µs per read (not measured). Far below the P0 line.
  • Compared with base: base did none of this work on main. Instead, every mounted Items list (each bot in each window, plus paired clients) re-read the whole list on each such frame:
    • allOpenItems: ⌈open/100⌉ list calls
    • one Closed list call
    • viewRows over open plus loaded depth
    • one RPC per loaded Closed page, each repeating the whole open list
  • With no Items list open: head adds only the constant cost above. It is needed to name the items for whichever client shows them, and the host can't see which clients do (paired desktops and phones included).

Work the diff adds or changes

Work Trigger Population Bound
BotItemsHost.changed → itemUids item writes (comment, status, snooze, write), worker link changes items written or linked once per write, O(items)
addBotChange / botChangeNotice (itemUids, workersNamed) each change in the 0 ms / 500 ms window bots × uids 100 uids per bot, then null (read whole); cleared each window
dispatchChanged from phase changes and federated verdicts worker transitions that aren't observed; changed federated ids Dispatches changed see the table above; one flush per microtask
uids list read (bot-items-reads.ts:73-91) a named read ≤ 100 (schema) json_each CROSS JOIN on the items.uid primary key, plus the scope count base already ran; in the bots DB worker
views(…, summary) every desktop list read rows returned drops 3 text fields of up to 8,000 chars each
closedOnly / closedLimit Show more; whole re-read ≤ 1,000 Closed rows per call Show more skips allOpenItems; depth comes back in one call, not one per page
botItemsNoticeParts each matching frame, per mounted items listener kinds O(kinds)
mergeNamedBotItems each named read L loaded rows O(L), sorts only on a change, returns previous when nothing changed
loadBotItemsList whole path an unnamed frame, a failure, the first read depth D current host: 1 call (plus ⌈(D−1000)/1000⌉ past 1,000). Older host: 1 call, plus ⌈D/50⌉−1 pages only when the first page moved (base always paged).
shared read store (bot-host-read-store.ts) asks, Show more 1 read in flight per bot gap timer only on an ask; an ask with no parts schedules nothing; entry deleted on the last unsubscribe; more waiters resolve to null

Listener census at head

Producers:

  • Local: BotChangeNotices → orca-runtime-bots.ts:327-328 → IPC → app-lifetime-ipc-bridge.ts:80.
  • Paired: the client event stream → emitPairedBotsChanged (bot-host-listing.ts:122-127), and only while that host is live.

Desktop window listeners on orca:bots-changed. ✱ marks one this PR changes. The PR adds no listener and removes none.

  • ✱ use-bot-host-read.ts:109, one per mounted useBotHostRead, gated on visibility:
    • itemsRead [items, workers]: reads only the named uids. A frame with no parts (workersNamed, or one with no items for this bot) makes 0 RPCs.
    • activityRead and chatTreeRead: read whole, as in base.
    • The group panel mounts one itemsRead per member through MemberReader.
  • ✱ items/use-bot-items.ts:206 useBotChatItems: only while a chat filter is set. Same parts logic. Not gated on visibility (pre-existing).
  • items/use-bot-item-view.ts:130 (open item), use-bot-tidy-up.ts:67 (BOT_VIEW_KINDS), bot-mention-chats-read.ts:133 (chats), use-bot-group-transcript.ts:52 (groups).
  • Settings and bot kinds: bot-tool-checks.ts:61, google-setup-run-store.ts:117, composio-client.ts:100, composio-key-client.ts:41, ComposioEventsCard.tsx:152.
  • Host level:
    • bot-host-refresh.ts:167: an items frame that carries needsYou only compares the counts, and an equal answer notifies no one.
    • bot-host-per-bot-read.ts:142, bot-group-list.ts:39, bot-access-requests.ts:155, bot-host-orca-account.ts:125.
    • webhooks/use-webhook-data.ts:100: a raw listener on any frame.

Phones: unchanged. The route, group transcript and host bot list re-read on matching frames. A linked worker's frame matched them in base too, through workers/status, so phones get no new reads.

Rates:

  • Idle: 0 frames/s in base and at head. No new timer, poll or IPC on main, renderer or phone. The flush microtask and the read gap timer run only on a change.
  • Under load: per host, one frame on the next tick, then at most one per 500 ms (≤ 2/s), as in base. One trigger is still one frame (P1-3 is fixed).
  • Frames that change nothing for Items: with many workers running, most frames come from workers no item links. At head they cost the Items list 0 RPCs. In base, each cost one whole read, plus D/50 Closed pages, per mounted list and per bot, held to at most one read per 500 ms by the gap. The open item view, Activity and the chats tree still read on those frames (pre-existing).

Older paired hosts (no uids, closedLimit, closedOnly or summary)

  • Their frames: they carry no itemUids or workersNamed, so every Items read is whole: 1 RPC of the open list plus 50 full-body rows.
  • Deeper loaded Closed list:
    • If the first page didn't move, sameFirstPage returns previous: 1 RPC, fewer than base.
    • If it moved, the list pages down. Each page repeats the open list because the host ignores closedOnly, the same as base.
  • Show more: 1 RPC carrying the open list plus one page, the same as base.
  • Named reads: never sent to these hosts.
  • Older desktop and phone clients on a new host: they ignore the new fields. A linked worker's frame now also lists items, but they already re-read on that frame through workers. Frame counts are unchanged.

Regression classes

Class Disposition
One change published as a whole snapshot Fixed by this PR for current hosts (named items, workersNamed)
Re-reading unchanged input Fixed: loaded Closed pages are no longer re-read per frame. Older host: sameFirstPage
Update published when nothing changed Disproved: one frame per trigger. changed([]) returns early, so a worker no item links sends no items scope
Sync fs or SQLite on Electron main Matched and priced: 1 + lineage primary-key reads per worker transition; constant and microtask-batched (optional tidy-up above)
No-op store write Disproved: mergeNamedBotItems and reuseEqualJson return previous; the store notifies only on a new identity
Fixed-cadence poll / new idle wakeups No matching code
Per-entity state outlives the entity Disproved: entries are deleted on the last unsubscribe, pending is cleared each window, and the flush Set is swapped each flush
Unbounded fan-out Disproved: uids ≤ 100, closedLimit ≤ 1,000, one read in flight per bot. Federated ids share one flush
Hot-path rescans Disproved: O(L) per read, no nested scans

Six questions

  1. Unused work before the skip gate: reviewed. An ask with no parts schedules nothing, so unnamed-worker frames cost Items 0 RPCs. Main builds the item names even when no Items list is open; that cost is constant and priced above.
  2. Ownership multiplication: reviewed. There is one shared read per bot, and each mounted listener costs O(kinds). The group panel's per-member reads are unchanged from base.
  3. Thread and storage: reviewed. Main pays the primary-key reads; the bots DB worker pays the uids, links and viewRows queries.
  4. Growth and progress: reviewed. Uid sets are capped at 100, then the list reads whole. A failed read makes the next read whole. Deep reads page by 1,000.
  5. Execution host: reviewed. Older paired hosts cost what base cost or less. On SSH, each RPC is one round trip, and at head there are fewer of them.
  6. Obsolete work: reviewed. The last unsubscribe bumps latest, clears the timer and resolves the waiters. A whole read already in flight finishes its bounded remainder.

Not measured: ms per primary-key read and per linked-worker join on a real profile, and the real rate of worker transitions.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 5be7be5

Verdict: no regression. The app code is the same as at b4042a64432. The last two commits change only bot-items-list-load.performance.test.ts, its fixture and bot-items-list-load.test.ts. Every trigger still costs the same as base or less, on current and older hosts.

The new closedOnly check closes half of the earlier gap: it guards Show more but not the depth pages a whole read makes. A second contract, "stops paging once nothing shows the list", can't fail either. Both are test gaps, not runtime costs. I checked both by mutation in a throwaway copy (details at the end).

Base is the merge-base edf6acdf70b. Fleet sizes used: one bot with 600 open items, 2,000 Closed items and 250 loaded Closed rows (D = 4 pages below the first). A change touches k = 1–5 items. A worker notice can land on L loaded items that link a Dispatch, up to 650. Notices arrive at most 2/s under load.

Work per trigger (head vs base)

trigger → owner → work per event → bound. Line numbers are in src/shared/bots/bot-items-list-load.ts unless another file is named.

Trigger Base Head Bound
Item change (botsChanged with itemUids) 1 whole RPC: 600 open items and 50 Closed, with full bodies. When the value changed, D more Closed-page RPCs followed, each carrying the 600 open items again: about 3,050 rows in 5 RPCs. 1 RPC with uids (:123): a uid lookup on the primary key (bot-items-reads.ts:74), plus the count scan base also ran, plus views over k summaries. Renderer: an O(N) merge (bot-item-merge.ts:52), with a sort only when something changed (:70). k ≤ 100 per bot per window (BOT_CHANGE_ITEM_UIDS_MAX). Past that, a whole read.
Worker notice (namesItems) Same as an item change ⌈L/100⌉ RPCs (:117), L summaries in total. 0 RPCs when L = 0. L ≤ loaded items
Show more 1 RPC: the 600 open items and 50 Closed 1 RPC with closedOnly (:100): 50 Closed rows one page
Whole read, first page unchanged (paired refresh at 15 s backing off to 120 s, Retry, reopening) 1 whole RPC 1 summary RPC (:62, :65) 1 call
Whole read, first page moved 1 + D RPCs, each with the open list 1 RPC, shown at once (:70-71), then ⌈(depth−50)/50⌉ closedOnly pages of ≤ 50 rows each (:77-83) loaded depth
Chat-filtered list, whole read (pageUnmoved) 1 + D RPCs, each with the open list 1 + D RPCs; the pages leave out the open list loaded depth

Older paired host (it doesn't know uids, summary, closedOnly or closedLimit):

  • Its notices carry neither itemUids nor namesItems, so botItemsNoticeParts returns null (bot-items-notice-parts.ts:33,40) and the list reads whole. A named read never reaches it.
  • A whole read with an unchanged first page costs 1 call. When the first page moved, it makes the same 1 + D open-list calls base made.
  • So it costs the same as base or less. readNamed falls back to a whole read (:124) only as a safeguard.

Phone app: nothing under mobile/ changed. It sends none of the new params, and the host answers it as at base.

botsChanged census

  • Frames: this PR doesn't change how many go out. There is still at most one per quiet window, on the same timer as base (bot-change-notices.ts:53).
    • A frame grows by up to 100 uids for each bot whose items changed.
    • namesItems is one boolean, added only to frames that carry a workers change.
    • Frames that carry no change: 0 at base, 0 at head.
  • Rate: 0 frames/s at idle, before and after. Under load, at most one per window, as at base.
  • Renderer listeners:
    • The shared Items read: one per bot, however many surfaces show it. It is visibility-gated and starts reads at least 500 ms apart.
    • useBotChatItems: one per mounted chat filter or group member. It isn't visibility-gated, which predates this PR, and it runs one read at a time.
    • Activity and chat-tree reads get null from partsOf, so they still read whole, as at base.
    • The item view isn't touched.
  • Phone app listeners (host-bot-refresh.ts, use-host-bot-chat-trees.ts, use-phone-bot-items.ts and the rest under mobile/src/bots) read only botIds and kinds. The new fields don't change how often they fire or what they read.
  • Idle wakeups on main, the renderer and the daemon: 0 → 0. This PR adds no timer, poll or IPC.

Regression classes

  • No-op store write: checked; not a problem. mergeNamedBotItems returns previous when nothing changed. The store notifies only when the value's identity changes (bot-host-read-store.ts:111,125).
  • Update published when nothing changed / one change sent as a whole snapshot: this PR fixes that class.
  • Re-reading unchanged input: an unchanged first page ends the read after 1 call.
  • Fixed-cadence poll / new idle wakeups: none added.
  • Hidden owners: the bot list is gated. The chat list isn't, as at base, and it is now cheaper.
  • Unbounded fan-out: none. Each list makes one call at a time, in sequence.
  • Per-entity state: released. A store entry and its more waiters go when the last surface unsubscribes (bot-host-read-store.ts:217-224). The pending itemUids map goes with each window.
  • Sync SQLite on main: this runs on the bots DB worker, as at base.

Six questions

  1. Unused work before the skip gate: checked. Summaries leave out the long texts, and reuseEqualJson catches an unchanged answer before any listener runs.
  2. Ownership: checked. One shared entry per bot.
  3. Which thread pays: checked. The DB worker pays for SQLite. The renderer pays for an O(N) merge.
  4. Growth and progress: checked. Calls are bounded by k/100, L/100 or depth/50. When a page below fails, the fresh first page stays (:86).
  5. Execution host: checked for current and older hosts. Live SSH and paired timing were not measured.
  6. Obsolete work stops: live() (bot-host-read-store.ts:109) gates each next page and batch (:77, :118). An RPC already in flight can't be cancelled, and its result is discarded.

Not a regression (numbers)

  • A worker notice can take more round trips than base. With L = 600 and no pages loaded below the first, head makes 6 sequential RPCs carrying 600 summaries. Base made 1 RPC carrying 650 full items, plus D more when the value changed. The rows and store reads are the same or fewer; the extra cost is round-trip latency on paired or SSH hosts. This predates this head.
  • The item view ignores itemUids. This predates the PR, which doesn't touch it.

Perf contracts in bot-items-list-load.performance.test.ts

I checked them by mutating the loader in a throwaway copy and running just this file and bot-items-list-load.test.ts.

These contracts fail when their bound is reverted:

  • An unchanged whole read makes 1 call. Removing the sameFirstPage gate (:65) fails it.
  • Show more sends closedOnly. Sending closedOnly: false at :100 fails the new check (perf test :30-32).
  • Worker notices read only the linked items, in hundred-item batches. Removing the 100 cap at :117 fails it.

Gap 1: the new closedOnly check doesn't reach the depth pages.

  • At perf test :23, the last whole read finds its first page unchanged and returns after 1 call. So pages holds only the two Show more calls from :100.
  • With closedOnly: false at :81, all 8 tests in both loader files still pass. The fixture's extra open rows are filtered out at :88.
  • That is the path that re-sent the 600 open items on every moved whole read and on every chat-list read, which is the original bug.
  • Fix (verified): at perf test :53 (the pageUnmoved read, which does reach :81), check closedOnly === true on every call with a closedCursor. With that check, the :81 mutation fails and the unmutated file passes.

Gap 2: "stops paging down the depth once nothing shows the list" (perf test :58-70) can't fail.

  • Its data doesn't change, so the whole read returns at the sameFirstPage gate after 1 call and never reaches the loop.
  • With live() && removed from :77, all tests pass.
  • Fix (verified): pass pageUnmoved: true with live at :68, or change an item so the first page moves. With that change, the mutation fails (3 calls instead of 1) and the unmutated file passes.

Not assessed

  • Live paired or SSH timing.
  • A phone on the current host (its code is unchanged).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head f09321f

Verdict: no regression. The app code is the same as at b4042a64432. The last commit, f09321f4484, changes only bot-items-list-load.performance.test.ts. Every trigger still costs the same as base or less, on current and older paired hosts. The new commit closes both test gaps the previous scan found. One smaller contract gap remains; it's a test gap, not a runtime cost (details below).

Base is the merge-base edf6acdf70b. Fleet sizes used: one bot with O = 600 open items, 2,000 Closed items and C = 250 loaded Closed rows (D = 4 pages below the first). A change touches k = 1–5 items. A worker notice can land on L loaded items that link a Dispatch, up to 850. Notices arrive at most 2/s under load. Line numbers are in src/shared/bots/bot-items-list-load.ts unless another file is named.

Work per trigger (head vs base)

Trigger Base Head Bound
Item change (botsChanged with itemUids) 1 whole RPC: 600 open items and 50 Closed, with full bodies. When the value changed, D more Closed-page RPCs followed, each carrying the 600 open items again: about 3,250 rows in 5 RPCs. The chat-filtered list made all 5 on every notice, because its value was never reused. ⌈k/100⌉ RPCs with uids (:123). Each is a primary-key lookup (bot-items-reads.ts:74) plus the per-status count base also ran, then views over k summaries. Renderer: an O(N) merge (bot-item-merge.ts:52), with a sort only on change (:76). k ≤ 100 per bot per window (BOT_CHANGE_ITEM_UIDS_MAX). Past that, a whole read.
Worker notice (namesItems) Same as an item change ⌈L/100⌉ RPCs (:117), L summaries in total. 0 RPCs when L = 0 (:42, :57 and :97 all skip). No render when nothing changed. L ≤ loaded items
Show more 1 RPC: the 600 open items and 50 Closed 1 RPC with closedOnly (:100): 50 Closed rows one page
Whole read, first page unchanged (paired-workspace refresh at 15 s backing off to 120 s while visible, Retry, reopening, a notice naming no items) 1 whole RPC 1 summary RPC (:62, :65) 1 call
Whole read, first page moved 1 + D RPCs, each with the open list 1 RPC, shown at once (:70-71), then D closedOnly pages of ≤ 50 rows (:77-83; host caps closedLimit at 50, bots-items-params.ts:123) loaded depth
Chat-filtered list, whole read (pageUnmoved) 1 + D RPCs, each with the open list 1 + D RPCs; the pages leave out the open list loaded depth

Older paired host (it doesn't know uids, summary, closedOnly or closedLimit):

  • Its notices carry neither itemUids nor namesItems, so botItemsNoticeParts returns null (bot-items-notice-parts.ts:33,40) and the list reads whole. A named read never reaches it. The fallback at :124 is only a safeguard.
  • A whole read with an unchanged first page costs 1 call, as at base. When the first page moved, it makes the same 1 + D open-list calls base made; closedLimit is ignored and each answer is one 50-row page, so the loop stops at the same depth.
  • Show more makes 1 call carrying the open list, as at base.

Phone app: nothing under mobile/ changed. It sends none of the new params, and the host answers it as at base. Old params keep the old answers: without closedOnly, a Closed page still carries the open list.

botsChanged census

  • Publisher: BotChangeNotices (bot-change-notices.ts:39-61) sends one frame on the next tick, then at most one per 500 ms window. This PR doesn't change that.
    • itemUids adds up to 100 uids for each bot whose items changed, built in O(uids) (bot-change-scope.ts:151-209). The pending map is dropped with each window.
    • namesItems is one boolean, added only to frames that carry a workers change.
  • Rate: 0 frames/s at idle, before and after. Under load, at most 2/s per host, as at base. Frames that carry no change: 0 at base, 0 at head.
  • Renderer listeners (17 onBotsChanged sites; each mounted one parses the frame through readBotChangeScope before its interest filter, now copying itemUids too):
    • The shared Items read (use-bot-host-read.ts:109): one listener per mounted surface, but one read per bot. It's gated on visibility and starts reads at least 500 ms apart.
    • useBotChatItems (use-bot-items.ts:207): one per mounted chat filter or group member. It isn't gated on visibility, which predates this PR, and it runs one read at a time.
    • Activity and chat-tree reads get null from partsOf, so they still read whole, as at base.
    • The item view (use-bot-item-view.ts:130) isn't touched.
    • Parse cost at 100 listeners × 100 uids is about 10k string checks per frame, at ≤ 2 frames/s.
  • Phone app listeners (host-bot-refresh.ts, use-host-bot-chat-trees.ts, home-bots-query.ts, host-worktree-refresh.ts, use-host-bots.ts, and use-phone-bot-items.ts through the route's read count) read only botIds and kinds. The new fields don't change how often they fire or what they read.
  • Idle wakeups on main, the renderer and the daemon: 0 → 0. This PR adds no timer, poll or IPC.

Regression classes

  • No-op store write: checked; not a problem. mergeNamedBotItems returns previous when nothing changed. show and the landing path notify only when the value's identity changes (bot-host-read-store.ts:111,125).
  • Update published when nothing changed / one change sent as a whole snapshot: this PR fixes that class for the desktop list.
  • Re-reading unchanged input: an unchanged first page ends the read after 1 call.
  • Fixed-cadence poll / new idle wakeups: none added. The paired refresh is unchanged and now cheaper per tick.
  • Hidden owners: the bot list is gated. The chat list isn't, as at base, and it now costs less.
  • Unbounded fan-out: none. Each list makes one call at a time, in sequence.
  • Per-entity state: released. A store entry and its more waiters go when the last surface unsubscribes (bot-host-read-store.ts:217-224).
  • Hot-path rescans: namedParts, sameFirstPage and the merge are each O(N) per read, the same order as base's reuseEqualJson over the whole answer.
  • Sync SQLite on main: this runs on the bots DB worker, as at base. The new uids path is a primary-key lookup.

Six questions

  1. Unused work before the skip gate: checked. Summaries leave out the long texts, and reuseEqualJson catches an unchanged answer before any listener runs.
  2. Ownership: checked. One shared entry per bot. Chat lists are one per filter, as at base.
  3. Which thread pays: checked. The DB worker pays for SQLite. Main pays for views over the rows returned, which is fewer than base. The renderer pays for an O(N) merge.
  4. Growth and progress: checked. Calls are bounded by k/100, L/100 or depth/50. When a page below fails, the fresh first page stays (:86).
  5. Execution host: checked for current and older hosts. Live SSH and paired timing weren't measured.
  6. Obsolete work stops: live() (bot-host-read-store.ts:109) gates each next page and batch (:77, :118). An RPC already in flight can't be cancelled; its result is discarded.

Not a regression (numbers)

  • A worker notice can take more round trips than base. With L = 600 and no Closed pages loaded below the first, head makes 6 sequential RPCs carrying 600 summaries. Base made 1 RPC carrying 650 full items (its host-side open loop also ran 7 store reads), plus D more when the value changed. The rows and store reads are the same or fewer; the extra cost is round-trip latency on paired or SSH hosts. This predates this head.
  • Pre-existing, outside the PR: the item view re-reads its item on every items or workers notice of its bot, without checking itemUids (use-bot-item-view.ts:130). The phone's Items list (mobile/src/bots/items/use-phone-bot-items.ts) still makes 1 + D open-list reads per notice, which is base's desktop behaviour.

Perf contracts in bot-items-list-load.performance.test.ts

I mutated the loader in a throwaway copy and ran just this file and bot-items-list-load.test.ts (8 tests pass unmutated).

These contracts fail when their bound is reverted:

  • Depth pages send closedOnly (new at :51-63). closedOnly: false at :81 now fails. This closes the previous scan's gap 1.
  • Stops paging once nothing shows the list (:77, now with pageUnmoved). Removing live() && at :77 of the loader now fails. This closes gap 2.
  • Show more sends closedOnly. Sending closedOnly: false at :100 fails.
  • Unchanged whole read makes 1 call. Removing the sameFirstPage gate at :65 fails.
  • Worker notices read the linked items only, 100 per call. Removing the 100 cap at :117, or reading every loaded item instead of the Dispatch-linked ones, fails.
  • Depth bound. Paging to the end instead of to the loaded depth (loaded < want dropped at :77) fails 5 tests.

Remaining gap: "a page per call" (perf test :26-28) can't fail.

  • The last whole read in that block (:23) finds its first page unchanged and returns after 1 call. So limits only ever holds undefined, and the ≤ 50 check never sees a number.
  • With the one-page cap removed (closedLimit: want - loaded at :82), all 8 tests still pass. In production a current host's schema refuses closedLimit over 50, so that read would fail rather than grow. That's why this is a test gap, not a runtime cost.
  • Fix (verified): pass { pageUnmoved: true } to the whole read at perf test :23. The unmutated file still passes. With the cap removed, the check fails, because the read asks for closedLimit 100.

Not assessed

  • Live paired or SSH timing.
  • A phone on the current host (its code is unchanged).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. A bot's Items list re-read far more than it showed. One item comment made the list re-read every item with full text, plus every Closed page the owner had loaded with Show more, each page carrying the whole open list again: 6 reads of about 1.3 MB per update with 600 open items.

What changes for users. The list looks the same. An item change now reads only that item, as a summary row; Show more reads only the next Closed page; loaded Closed pages are not re-read on updates. A worker's state change reads only the loaded items that link a worker, a hundred per call. Two small visible differences, both in the PR body: an opened item's description, done-means and close note appear when the item's own read lands, and Show more in one view of a bot (its panel, a group panel) also deepens Closed in its other open views.

Fixed during review (in order): Closed pages folded into the list's one serialized read so pages and updates cannot race; whole reads page a page per call (no answer larger than before, which a paired connection's answer-size cap needs) and stop at an unchanged first page, as before; worker changes read the loaded worker-linked items, picked when the read starts, with no reverse lineage lookup on the host (a design review chose this over host-side naming, which kept missing follow-up and reused-terminal cases); older paired hosts and clients keep working (they never get by-uid reads); a list read to its end keeps room for the pages it took; a failed page below a whole read's first page keeps that fresh page; a failed Show more page keeps a named update; reads stop once no view shows the list.

Verified.

  • Regression audit on the code at b4042a6 (merged onto main): SAFE. The commits after it change only tests.
  • Performance scan on the final head: no regression (comment above, verdict=clean).
  • Typecheck, lint, the changed-code quality gate and the tests the change touches pass on the final head.
  • Benchmark on the final code (Linux, production build, hidden window; 60 item comments at one per second; Closed paged to the end):
base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Main handler time for list reads, per 60 s 1.9 s 0.08 s 10.0 s 0.07 s
Show more to the end (5 pages) 1.0 MB 0.18 MB 6.6 MB 0.18 MB
First list read when the panel opens 205 KB 76 KB 1,323 KB 452 KB

Benchmark: head=f09321f4484df4621041525442a10af8dd30d9b0 gate=PASS build=bf0b4079518cd0b062317c85c15e7796b353c5e8 (the head plus a render-probe commit used only for measuring) listeners=bot Home Items panel (bot list read, Activity tab), main RPC probe on bots.items.owner.list

Deferred (follow-ups, none a regression):

  • The phone app's Items list still re-reads its whole list and every loaded Closed page on each change; the same fix applies there.
  • An opened item re-reads on every items or workers notice of its bot, even when the notice names other items.
  • A worker change reads every loaded worker-linked item, not only those whose worker changed; naming the changed Dispatch in the notice would narrow it.
  • A pull-request or issue link's state on a row no longer refreshes as a side effect of other items changing (it refreshes on a whole read).
  • With two views of one bot open, Next/Prev in one can skip Closed rows that Show more in the other loaded.
  • If an opened item's own read fails, it shows without its description.
  • Two Show more failure paths (inside a whole read, or with a named update) are silent instead of showing an error.
  • One work-contract check (a page per call) does not reach the deeper pages; the host's parameter limit enforces the bound in production.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 21, 2026 07:28
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head f09321f (hot-path, subscribe)

Verdict: no regression. Every trigger costs the same as base or less on Electron main, the bots DB worker and the renderer, for current and older paired hosts. This PR adds no idle wakeups (0 → 0 on main, the renderer and the daemon).

Base is the merge-base edf6acdf70b. Workload: one bot with O = 50 or 600 open items and 400 Closed items. D is the number of Closed pages loaded below the first, from 0 to 7 (7 means all 400 are loaded). k is the number of items a change touches (usually 1–5, capped at 100 per bot per notice window). L is the number of loaded items that link a Dispatch. Notices come at most 2/s per host under load (500 ms window, unchanged).

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

The SQLite queries run on the bots DB worker (BotItemsRemote, bot-items-ops.ts:33). Main receives those rows by structured clone, joins each item's links to its workers (readLinkedWorkers, bot-items-link-join.ts:58), builds the views (bot-items-runtime.ts:235) and serializes the answer.

Work per call

Each list query also runs the per-status count (bot-items-reads.ts:67-72). That count is a range scan over the bot's idx_items_owner_open entries: 450 at O = 50, 1,000 at O = 600. Base ran it the same way.

Call list queries (each with its count) Item rows from the worker Items joined and viewed on main
Base, any call (whole read, or a Closed page, which also carries the open list) O=50: 2. O=600: 7 (6 open pages of 101 rows + 1 Closed page) O=50: 101 + 100 (viewRows) = 201. O=600: 656 + 650 = 1,306 100 / 650
Head, whole read (summary) 2 / 7, same as base 201 / 1,306, same as base 100 / 650. The wire leaves out description, doneMeans and closeNote
Head, named read (uids, :84-98) 1. The uids lookup is a primary-key join (json_each CROSS JOIN items, bot-items-reads.ts:74-76) 2k (k + k from viewRows) at both O k
Head, Closed page (closedOnly, :101-102) 1 51 + 50 = 101 at both O 50

Bytes

  • Base: every viewed item crossed to the renderer or the paired socket with its long texts. Those are capped at 20,000 + 2,000 + 8,000 characters per item (BOT_ITEM_LIMITS).
  • Head: summaries leave the texts out (bot-items-runtime.ts:256-264). Wire bytes per call are therefore about (items viewed) × S, where S is the summary row (title, owner, chat, links, timestamps).
  • I did not measure S. An assumed S ≈ 1 KB, with ≈ 2 KB of text per item at base, is used only to show the scale in the next table.
  • Unchanged from base: the worker still sends main the full rows (SELECT items.*, plus viewRows again), so main still pays the structured clone of the texts. That isn't a regression, but it's the next cut if these reads ever show up in a profile.

Main-process work per trigger (head vs base)

Trigger Base Head
Item change (notice with itemUids) 1 + D whole calls. D = 0: 1 call (201 / 1,306 rows). D = 7: 8 calls, 16 / 56 list queries, 1,608 / 10,448 rows, 800 / 5,200 views, about 2.4 / 15.6 MB on the wire (at the assumed sizes) 1 named call: 1 query, 2k rows, k views, about k KB. The same at O = 50 and O = 600
Worker notice (namesItems) Same as an item change ⌈L/100⌉ named calls (bot-items-list-load.ts:117), L views in total. L ≤ O + 50(1 + D). 0 calls when L = 0
Show more 1 call carrying the open list: 201 / 1,306 rows, 100 / 650 views 1 closedOnly call: 101 rows, 50 views
Whole read, first page unchanged (paired-workspace refresh at 15 s backing off to 120 s, only while the window is visible, use-paired-activity-refresh.ts; also reopen, Retry, a notice naming no items, more than 100 uids) 1 call 1 call, same rows, summary bytes (:62-68)
Whole read, first page moved 1 + D calls, each carrying the open list 1 call + D closedOnly calls of ≤ 50 rows each (:77-83; the host caps closedLimit at 50, bots-items-params.ts:123)
Chat-filtered list Every notice: 1 + D calls carrying the open list. Its value was never reused, so the Closed pages were always read again Notices: named, as above. Whole reads: 1 + D, with the pages leaving out the open list (pageUnmoved)

Older paired host (it doesn't know uids, summary, closedOnly or closedLimit):

  • Its notices carry no itemUids and no namesItems, so botItemsNoticeParts returns null (bot-items-notice-parts.ts:33,40) and the list reads whole.
  • Unchanged first page: 1 call. Moved: 1 + D calls carrying the open list. Show more: 1 call carrying the open list. All the same as base.
  • The loop stops at the same depth, because each answer is one 50-row page.

Older client or phone on a current host: they send none of the new params, and the handler takes the base path (:100-123). The only new work there is stillOpen, one Set filter over O items.

Author's benchmark on this head (from the PR's status comment):

  • List reads per update: 6 → 1.
  • Main handler time for list reads per 60 s: 1.9 s → 0.08 s at 50 open, and 10.0 s → 0.07 s at 600 open.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner write (comment, status, snooze), and each agent write through writeResult. A dozen agents may call the CLI every few seconds.
  • Change: changed(items) now passes the records it already holds. botItemsChangeScope groups them by bot in O(k) (bot-change-scope.ts:51-63).
  • New work: no new store read, IPC or timer. The Dispatch path (bot-items-runtime.ts:301-302) uses the viewRows result base already read.
  • Notices: addBotChange merges uids into a per-bot Set. Past 100 uids it sets that bot to null, and the list reads whole. The pending state is dropped each window (bot-change-notices.ts:53-58).
  • Frame: each frame grows by at most 100 uids per bot, plus one boolean when the frame carries a workers change.
  • Rate: frames per second are unchanged.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19, store in bot-host-read-store.ts)

The state hook was moved here from use-bot-host-read.ts unchanged.

Store census. Three store instances; each useSyncExternalStore adds one listener per mount.

  • itemsRead (use-bot-items.ts:41): useBotItems adds 3 listeners (value + state + refreshFailed). It's mounted by:
    • BotActivityPanel.tsx:102, one per open bot panel.
    • use-bot-group-items.tsx:62, one per group member.
  • chatTreeRead (use-bot-chat-tree.ts): 3 listeners per mount. It's mounted by BotActivityPanel, BotChatMentionTitle (one per mention title), use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead (use-bot-activity.ts:30): 1 listener per mount. It's mounted by BotActivityPanel, BotSettingsRoot, BotLookAroundSection, use-bot-now, use-bot-group-items, and the native-chat automation rows (NativeChatAutomationResultRow, NativeChatAutomationRunBody, NativeChatWaitRow).
  • Non-subscribing reader: botItemLastRead (bot-item-chip-preview.ts:19) reads a snapshot without subscribing.
  • Activity and chat tree are unchanged. They pass no options, so request always asks for the whole read (addBotReadAsk(…, null, 0) → 'whole') and read takes the base path (:119-122).
  • Phone app: it doesn't use this store.

When the store notifies

  • Only when the value's identity changes, or on a failure transition (:111, :125, :145).
  • mergeNamedBotItems returns previous when nothing changed (bot-item-merge.ts:70-73).
  • A whole read with an unchanged first page returns previous (bot-items-list-load.ts:65-68).
  • Idle: 0/s, the same as base. No timer is added; the paired refresh is pre-existing and notifies only on change.
  • Under load: at most 2 reads/s per bot (ITEMS_MIN_READ_GAP_MS 500), so at most 2 notifications/s per bot. Notifications that carry no change: 0. The same reads at base also notified, and each read that changed the value also started the D-page re-read.
  • Whole read with a moved first page and D > 0: 2 notifications, show (:70-71) and then the landing. When the pages below are unchanged, the second can carry the same content under a new identity. Base also rendered twice for this case (the list landing, then the Closed-pages setPages), and at head this case no longer happens on item or worker notices. So it is not a regression. Comparing the landing with shown would save that render.

orca:bots-changed census (17 renderer sites, unchanged in count). Each mounted site parses the frame with readBotChangeScope before its interest filter. That now also copies itemUids: O(uids) ≤ 100 per bot.

  • Changed by this PR:
    • use-bot-host-read.ts:109: it now passes the scope to partsOf. The read is shared per bot and gated on visibility.
    • use-bot-items.ts:207: the chat-filtered list. It now asks for named parts and runs one read at a time. It has no visibility gate, as at base; each notice now costs 1 named call instead of 1 + D calls carrying the open list.
  • Unchanged, desktop: bot-mention-chats-read.ts:133, bot-tool-checks.ts:61, ComposioEventsCard.tsx:152, composio-client.ts:100, composio-key-client.ts:41, google-setup-run-store.ts:117, use-bot-item-view.ts:130, use-bot-group-transcript.ts:52, use-bot-tidy-up.ts:67, use-webhook-data.ts:100 (raw listener), bot-access-requests.ts:155, bot-group-list.ts:39, bot-host-orca-account.ts:125, bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167.
  • Emitter: runtime-client-ipc-bridge.ts:128.
  • Phone app (mobile/, unchanged): host-bot-refresh.ts, use-host-bot-chat-trees.ts, home-bots-query.ts, host-worktree-refresh.ts, use-host-bots.ts, and the route read count behind use-phone-bot-items.ts, use-phone-bot-chat-tree.ts and use-mobile-bot-tidy-up.ts. They read botIds and kinds only. How often they fire is unchanged.
  • Frame rate: 0/s at idle before and after. Under load, at most 2/s per host, as at base. Frames that carry no change: 0 before and after. A frame is built only from changes that were added, and namesItems is set only when the frame carries a workers change.

Regression classes

  • No-op store write: disproved. Merges and the store return previous and skip notifying.
  • Update published when nothing changed: disproved. itemUids and namesItems ride only on changes that were added.
  • Whole snapshot per change; re-reading unchanged input: fixed by this PR (named reads; no D re-reads).
  • Fixed-cadence poll, idle wakeups, eager imports: no matching code.
  • Hidden owners: the chat list isn't gated on visibility, which predates this PR; it's cheaper per notice now.
  • Per-entity state: released. An entry and its more waiters go with the last unsubscribe (bot-host-read-store.ts:215-225); itemsRead has keepLast off.
  • Hot-path rescans: namedParts, sameFirstPage and the merge are each O(N) once per read, the same order as base's reuseEqualJson.
  • Unbounded fan-out: none. Calls run one at a time.
  • Sync SQLite on main: no. The queries run on the DB worker, and the new query is a primary-key lookup.

Six questions

  1. Unused work before the gate: reviewed. Summaries drop the long texts on the wire, and unchanged answers stop at reuseEqualJson before any listener runs. The full rows still cross from the worker to main, as at base.
  2. Ownership: reviewed. One store entry per bot, however many surfaces show it. Chat lists are one per filter, as at base.
  3. Thread: reviewed. SQLite runs on the DB worker. Main does the joins and views over the rows returned: k instead of (1 + D)(O + 50) per notice. The renderer does an O(N) merge, sorting only on change.
  4. Growth and progress: reviewed. Calls are bounded by ⌈k/100⌉, ⌈L/100⌉ or D ≤ 7. A failed page below keeps the fresh first page (:84-87).
  5. Execution host: reviewed for current and older hosts and for the phone. Live SSH and paired timing were not measured. A worker notice with L = 600 takes 6 sequential round trips where base took 1 + D; there are fewer rows, but more latency on a slow link.
  6. Obsolete work: reviewed. live() gates every next page and batch. An RPC already in flight runs to completion, and its result is dropped.

Not assessed

  • Live paired or SSH timing.
  • The real summary row size S (the byte figures above use assumed sizes).

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Bot item change notices now include item UIDs when available and identify worker-linked items. The owner list API supports UID-filtered reads, summary views, and Closed-page controls. Shared loading and merge helpers handle named updates, full-list reads, and pagination. Renderer reads use a shared per-bot store, and the item list UI loads Closed pages through that read path.

Merge Risk: Moderate · previous review bc43c

Show more in the Items list can skip some Closed items after an interrupted read is followed by many item changes, and the chat-filtered list can report a failure on data it has recovered. Neither affects data stored on the host, and a whole refresh recovers the list. Fix the skipped-rows case before merging; the remaining items are test and lifecycle polish.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Bot Items list: fetch only what changed, and never re-fetch loaded Closed pages" matches the main change. The changeset makes item and worker change notices name only the affected items, me…
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, a detailed What Changed section with mechanism, a Why section, Visual Proof marked N/A with a reason, a Testing section with a …
Full details: Title check

Explanation

The title "Bot Items list: fetch only what changed, and never re-fetch loaded Closed pages" matches the main change. The changeset makes item and worker change notices name only the affected items, merges those rows by uid, and stops re-reading loaded Closed pages on each update. The title is specific and concise, and a teammate scanning history would understand the primary change. It is 79 characters, which is slightly long but acceptable.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5, a detailed What Changed section with mechanism, a Why section, Visual Proof marked N/A with a reason, a Testing section with a measurement table, a Performance line that is filled in, a Risk section with a level and a backout path, and the Agent skill boundary checkbox. Two items need attention. The Linked Issue section says 'None (maintainer change; no issue filed).' The template says an issue should always be linked, and the 'Fixes #' line is not filled in. The 'pnpm lint, typecheck, test, build' checkbox is unchecked, and the description does not say whether those commands passed locally. The AI Disclosure section is also empty. That section is optional for internal contributors, so its absence is acceptable here. The 'Review' section is filled in with a note that a status comment will follow.

  • 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Minor comments: 2

src/renderer/src/components/bots/bot-host-read-store.ts: 2

224-224: Minor · Performance & Scalability · Poor tradeoff

Prevent a second host read while the previous read for the same bot is in flight.

If the last surface for a bot closes during a host call, entries.delete(key) removes the entry, but the call continues. If the bot reopens before that reply arrives, the new entry starts with inFlight: false and startedAt: 0. request then starts another callBotRpc for the same bot immediately. The identity check keeps the old reply from publishing, but it does not prevent the duplicate host call.

Keep the per-bot in-flight state and the last start time until the outstanding call settles or is cancelled. Queue the reopened surface's refresh to start after that call settles. Do not publish the old call's result.

This behavior already exists at the merge base (use-bot-host-read.ts lines 77-79, 139, and 156-162), so it is not a regression introduced by this PR. Track it as a follow-up.


223-223: Minor · Stability & Availability · Low value

Settle in-flight Show more waiters when the last surface closes.

read moves its waiters from entry.more into a local waiters array. Cleanup settles only entry.more. An in-flight waiter therefore stays pending until the host call settles, and then it receives null because the result is discarded.

No visible surface remains after the last subscriber closes, so the effect is a delayed promise settlement and retained closure state. Keep in-flight waiters reachable from the entry, so cleanup can settle them with null at close. Leave normal completion in charge while a surface remains open. Settling a promise twice has no effect, so the finally call can remain.

Nitpick comments: 1

src/shared/bots/bot-items-list-load.test.ts: 1

116-118: Trivial · Maintainability & Code Quality · Quick win

Cover the legacy cursor guard separately from the unrequested-row guard.

The older-host named read in this test also returns open rows. Those rows trigger the unrequested-UID check in readNamed on their own. The nextClosedCursor check is therefore never the deciding condition, and the assertion still passes if that check is removed.

Add a case where the older host returns only requested UIDs and still sets nextClosedCursor. In that case, the cursor must be the only signal that makes the named read fall back. The assertion must fail when the cursor check is removed. A Closed-only seed is one way to build this case, because the older-host helper always includes open rows otherwise.

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: 203563cc-e0f6-4a00-ac3b-283bc0f78a39
Commits

Reviewing files that changed from the base of the PR and between 1ccd60c and f09321f.

Files selected for processing: 32

  • src/main/bots/bot-change-notices.test.ts
  • src/main/bots/bot-change-notices.ts
  • src/main/bots/bot-items-reads.ts
  • src/main/bots/bot-items-runtime.test.ts
  • src/main/bots/bot-items-runtime.ts
  • src/main/runtime/rpc/methods/bots-items-owner-methods.ts
  • src/main/runtime/rpc/methods/bots-items-write-support.ts
  • src/main/runtime/rpc/methods/bots-items.test.ts
  • src/renderer/src/components/bots/bot-host-read-asks.ts
  • src/renderer/src/components/bots/bot-host-read-store.ts
  • src/renderer/src/components/bots/items/BotItemsSection.test.tsx
  • src/renderer/src/components/bots/items/use-bot-item-walk.test.ts
  • src/renderer/src/components/bots/items/use-bot-items-closed-pages.test.ts
  • src/renderer/src/components/bots/items/use-bot-items-closed-pages.ts
  • src/renderer/src/components/bots/items/use-bot-items-shown-list.ts
  • src/renderer/src/components/bots/items/use-bot-items.ts
  • src/renderer/src/components/bots/use-bot-chat-tree.ts
  • src/renderer/src/components/bots/use-bot-group-items.tsx
  • src/renderer/src/components/bots/use-bot-host-read-state.ts
  • src/renderer/src/components/bots/use-bot-host-read.ts
  • src/shared/bots/bot-change-scope.ts
  • src/shared/bots/bot-item-groups.ts
  • src/shared/bots/bot-item-merge.test.ts
  • src/shared/bots/bot-item-merge.ts
  • src/shared/bots/bot-item-schema.ts
  • src/shared/bots/bot-items-list-load.performance.test.ts
  • src/shared/bots/bot-items-list-load.test-fixture.ts
  • src/shared/bots/bot-items-list-load.test.ts
  • src/shared/bots/bot-items-list-load.ts
  • src/shared/bots/bot-items-notice-parts.ts
  • src/shared/bots/bot-items.ts
  • src/shared/rpc-contract/bots-items-params.ts
Files with no reviewable changes: 2

  • src/renderer/src/components/bots/items/use-bot-items-closed-pages.test.ts
  • src/renderer/src/components/bots/items/use-bot-items-closed-pages.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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head b43ab06 (hot-path, subscribe)

Verdict: no regression. Every trigger costs the same as base or less on Electron main, the bots DB worker, the desktop renderer and the phone. This PR adds no idle wakeups: 0/s before and after on main, the renderer and the daemon.

Method. I read the source at this head against the merge-base edf6acdf70b and checked this head's CI logs. I ran no app or benchmark myself, so timings below are the author's. Everything else is a proven count with its trigger.

What the newest commit changed. b43ab06e5d5 touches neither hot-path file nor the store. It does two things:

  • It moves the itemUids/namesItems parse into readBotChangeScopeWithItems (bot-change-scope.ts:238). The desktop entry points use it: the preload bridge (bot-changes-bridge.ts:8), the paired-host bridge (runtime-client-ipc-bridge.ts:129) and onBotsChanged (bots-changed-window-event.ts:51). The phone keeps readBotChangeScope.
  • It drops the summary: true flag from list rows (bot-items-runtime.ts:272-275, and bot-item-schema.ts). Nothing read that flag: at the previous head no renderer, shared or phone code used it. The summary request param still drops the long texts (:256,257,264).

Surfaces. I reran perf-surface-detect --pr 45990. It reports the same three surfaces and no others: hot-path bots-items-owner-methods.ts, hot-path bots-items-write-support.ts, and subscribe use-bot-host-read-state.ts:19.

Workload: one bot with O = 50 or 600 open items and 400 Closed items.

  • D: Closed pages loaded below the first, 0–7 (7 means all 400 are loaded).
  • k: items one change touches (usually 1–5; capped at 100 per bot per notice window, BOT_CHANGE_ITEM_UIDS_MAX, bot-change-scope.ts:149).
  • L: loaded items that link a Dispatch.
  • Notice rate: at most 2 notices/s per host under load (500 ms window, unchanged).

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

  • Where it runs: the SQLite reads run on the bots DB worker. Main joins links to workers, builds views (bot-items-runtime.ts:235) and serializes the answer.
  • The per-status count: each list query also runs it, a range scan of 450 index entries at O = 50 and 1,000 at O = 600. Base ran it the same way.

Work per call

Call list queries Rows to main Items viewed on main
Base, any call (a Closed page also carried the whole open list) O=50: 2 · O=600: 7 201 · 1,306 100 · 650
Head, whole read (summary) 2 · 7 201 · 1,306 100 · 650, without description, done-means and close note
Head, named read (uids, :84-98, a primary-key json_each CROSS JOIN items) 1 · 1 2k · 2k k · k
Head, Closed page (closedOnly, :101-102) 1 · 1 101 · 101 50 · 50

Main-process work per trigger (base → head)

  • Item change: 1 + D whole calls → 1 named call.
    • At D = 7, base ran 16 / 56 queries, sent 1,608 / 10,448 rows to main and built 800 / 5,200 views (O = 50 / 600).
    • Head runs 1 query, 2k rows and k views at either O.
  • Worker notice (namesItems): same as an item change at base. Head makes ⌈L/100⌉ named calls (bot-items-list-load.ts:117) with L views in total, and 0 calls when L = 0.
  • Show more: base made 1 call carrying the open list (201 / 1,306 rows). Head makes 1 closedOnly call (101 rows).
  • Whole read, first page unchanged: 1 call at base and head; head sends summary bytes.
    • Triggers: the paired-workspace refresh (15 s backing off to 120 s, only while the window is visible), reopen, Retry, a notice naming no items, or more than 100 uids.
  • Whole read, first page moved: base made 1 + D calls, each carrying the open list. Head makes 1 call plus D closedOnly calls of at most 50 rows (closedLimit is capped at 50, bots-items-params.ts:123).
  • Older paired host: its notices carry no itemUids/namesItems, so botItemsNoticeParts returns null and every read is the whole-read path. The counts match base.
  • Older client or the phone on a current host: they send none of the new params and take the base path. The only addition is stillOpen (:115), one Set filter over O items.
  • Remaining cost: the worker still sends main full rows (SELECT items.*, then viewRows), as at base.

Author's benchmark (from the PR's status comment; Linux production build, hidden window, 60 item comments at 1/s, Closed paged to the end; measured at f09321f4484, and the newest commit doesn't touch these paths):

base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
Main handler time for list reads, per 60 s 1.9 s 0.08 s 10.0 s 0.07 s
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Show more to the end 1.0 MB 0.18 MB 6.6 MB 0.18 MB

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status or snooze, and each agent write through writeResult. A dozen agents may call the CLI every few seconds.
  • Change: changed() now gets the records it already holds instead of their bot ids. botItemsChangeScope groups them by bot in O(k).
  • New work: no new store read, IPC or timer.
  • Notices: addBotChange merges uids into a per-bot Set, which becomes null past 100. The pending state is dropped every window. The notice timer stops once a window has nothing pending (bot-change-notices.ts:52-63).
  • Frames: the rate is unchanged. Each frame grows by at most 100 uids per bot that changed items, plus one boolean when it carries a workers change.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19, store in bot-host-read-store.ts)

Store census. Three store instances; every useSyncExternalStore mount adds one listener.

  • itemsRead: useBotItems adds 3 listeners per mount (value, state, refreshFailed). It's mounted by BotActivityPanel (one per open bot panel) and by use-bot-group-items.tsx (one per group member).
  • chatTreeRead: 3 listeners per mount. It's mounted by BotActivityPanel, BotChatMentionTitle (one per mention title), use-bot-now and use-bot-chat-tree.
  • activityRead: 1 listener per mount. It's mounted by BotActivityPanel, BotSettingsRoot, BotLookAroundSection, use-bot-now, use-bot-group-items and the native-chat automation rows.
  • Snapshot reader: botItemLastRead (bot-item-chip-preview.ts:19) reads a snapshot without subscribing.
  • Unchanged stores: activity and chat tree pass no options, so they always take the whole-read path, as at base.
  • Phone: the phone app doesn't use this store.

When it notifies. Only when the value's identity changes (:113,131) or on a failure transition (:146).

  • Merges return previous when nothing changed.
  • A whole read whose first page is unchanged returns previous.
  • Idle: 0/s, as at base. The PR adds no timer. The paired refresh is pre-existing and notifies only on change.
  • Under load: at most 2 reads/s per bot (minIntervalMs 500, :196), so at most 2 notifies/s per bot. A read that changed nothing notifies no one.
  • Whole read with a moved first page and D > 0: 2 notifies, the show of the fresh first page and then the landing. Base also rendered twice there. At head, item and worker notices no longer reach this path.
  • Teardown: the last unsubscribe drops the entry, its timer and its more waiters (:215-225).

orca:bots-changed census (counts unchanged from base).

  • Emitters:
    • main runtime-window-lifecycle.ts:55 → preload bot-changes-bridge.ts:9 (1 parse) → app-lifetime-ipc-bridge.ts:79 → emitBotsChangedWindowEvent;
    • paired hosts: runtime-client-ipc-bridge.ts:129 (1 parse) → emitPairedBotsChanged (bot-host-listing.ts:122).
  • Listeners changed by this PR:
    • use-bot-host-read.ts:109: it now passes the scope to partsOf. One read per bot, gated on visibility.
    • use-bot-items.ts:207: the chat-filtered list. A notice now costs 1 named call instead of 1 + D whole calls. It has no visibility gate, as at base.
  • Listeners unchanged, desktop: bot-mention-chats-read.ts:133, bot-tool-checks.ts:61, ComposioEventsCard.tsx:152, composio-client.ts:100, composio-key-client.ts:41, google-setup-run-store.ts:117, use-bot-item-view.ts:130, use-bot-group-transcript.ts:52, use-bot-tidy-up.ts:67, bot-access-requests.ts:155, bot-group-list.ts:39, bot-host-orca-account.ts:125, bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167, and the raw listener in use-webhook-data.ts:100.
  • Phone (mobile/, unchanged files): host-bot-refresh.ts:64, use-host-bot-chat-trees.ts:112 and host-worktree-refresh.ts:103 parse with readBotChangeScope. home-bots-query.ts and use-host-bots.ts check only the event type. The route read count drives use-phone-bot-items, use-phone-bot-chat-tree and use-mobile-bot-tidy-up.
  • Frame rate: 0/s idle before and after; under load at most 2/s per host, as at base. Change-free frames: 0 before and after, because a frame is built only from added changes.

Parse cost per notice

  • Desktop: each frame is parsed once in the bridge, then once per mounted onBotsChanged instance on that host, before its interest filter, as at base.
    • Each parse now also copies the frame's itemUids: O(U), where U is at most 100 per bot that changed items in the window (typically k = 1–5).
    • The same fields base already parses (botIds, kindBots) are O(frame) per listener, so this grows with the frame's own size, not with items, worktrees or history.
    • At 2 frames/s with tens of mounted listeners and U ≈ 5, that's a few hundred string checks per second. Not a finding.
    • Optional trim: parse itemUids only in the two listeners that read it.
  • Phone: parse cost per notice is the same as base again. readBotChangeScope no longer reads itemUids or namesItems; at the previous head it did.
    • The frame still carries up to 100 uids per changed bot over the paired socket. That's bounded, and it's the same as at the previous head.

Phone bundle

  • This head: CI's verify-mobile-web-app-bundle (run 44886136257, merge ref 0219a49ddc4) reports 11,114,541 of 11,272,192 bytes excluding fonts, 157,651 bytes under the budget.
  • Previous head: f09321f4484 failed at 11,272,368 bytes, 176 over.
  • Why the size fell: both merge refs sit on different main commits (33 commits apart, with mobile and shared changes), so most of that drop is main's. This commit's own part is small but in the right direction:
    • the phone no longer pulls in the items parse;
    • the schema drops one salvagedOptional field.
  • Shared code the phone still imports: bot-item-merge.ts (+125 lines), bot-item-groups.ts, bot-change-scope.ts and bot-item-schema.ts. The headroom covers them.

Regression classes

  • No-op store write: disproved. Merges and the store return previous, and listeners don't run.
  • Update published when nothing changed: disproved. itemUids/namesItems ride only on added changes, and an unchanged read notifies no one.
  • Whole snapshot per change; re-reading unchanged input: fixed by this PR (named reads; no re-reads of the D pages below).
  • Fixed-cadence poll, idle wakeups, eager imports: no matching code. The notice timer stops when nothing is pending.
  • Hidden owners: the chat-filtered list has no visibility gate, which predates this PR; each notice costs less now.
  • Per-entity state: released on the last unsubscribe.
  • Hot-path rescans: the merge and first-page check are each O(N) once per read, the same order as base's reuseEqualJson. The bots.find in views (O(items × bots)) predates this PR.
  • Unbounded fan-out: none; calls run one at a time.
  • Sync SQLite on main: none; the queries run on the DB worker, and the new query is a primary-key lookup.

Six questions

  1. Unused work before the skip gate: reviewed. The long texts are left off the wire, unchanged answers stop before any listener runs, and the unread row flag is gone. The full rows still go from the worker to main, as at base.
  2. Ownership: reviewed. One store entry per bot, however many surfaces show it.
  3. Thread: reviewed.
    • SQLite runs on the DB worker.
    • Main joins and views k rows per notice instead of (1 + D)(O + 50).
    • The renderer does an O(N) merge per read.
    • Parsing on the phone is the same as base.
  4. Growth and progress: reviewed. Calls are bounded by ⌈k/100⌉, ⌈L/100⌉ or D ≤ 7, and a failed page below keeps the fresh first page.
  5. Execution host: reviewed for current and older paired hosts, older clients and the phone. Live SSH or paired timing wasn't measured. A worker notice with L = 600 makes 6 sequential round trips where base made 1 + D, so the rows are fewer but latency is higher on a slow link.
  6. Obsolete work: reviewed. live() gates every next page and batch, an RPC already in flight finishes and is dropped, and the last unsubscribe cancels the timer and waiters.

Not assessed: live paired or SSH timing, and the real size of a summary row.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: fa6f7803-69c5-4878-84b7-404405ed6676
Commits

Reviewing files that changed from the base of the PR and between 0a8780c and 3d409ce.

Files selected for processing: 5

  • src/renderer/src/components/bots/bot-host-read-asks.ts
  • src/renderer/src/components/bots/bot-host-read-store.ts
  • src/renderer/src/components/bots/items/use-bot-items.ts
  • src/shared/bots/bot-items-list-load.test.ts
  • src/shared/bots/bot-items-list-load.ts

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

Comment thread src/shared/bots/bot-items-list-load.ts Resolved
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 3d409ce (hot-path, subscribe)

Verdict: regression (P1), with a one-line fix. A read that stops for a newer ask marks its value as having rows below it that weren't read again. When the next read pages the rest and finds nothing changed, it keeps the same value object, so the mark is never cleared. After that, every whole read of an unchanged list pages the whole loaded Closed depth again (1 + D calls where base made 1), and every named read whose merge changes nothing pages the remaining depth again. This lasts until some read lands a changed value. Everything else in the two newest commits costs the same as base or less. This PR adds no idle wakeups: 0/s before and after on main, the renderer and the daemon.

Method.

  • I read this head against the merge-base edf6acdf70b and against b43ab06e5d5, the last head an earlier scan graded clean.
  • I ran the committed src/shared loader by itself (tsx) with the test fixture's host and a model of the read store's queue: one read at a time per bot, a 500 ms gap between read starts, and a newer ask sets again. The model uses virtual time and covers 60 s of notices, or 600 s with the paired refresh.
  • "Rows" in the simulation tables are rows in the host's answers. On main, each answered row costs about 2 rows from the DB worker, because of viewRows.
  • I measured no app timing. Timings for the unchanged paths are the author's, from the PR's status comment.

Surfaces. perf-surface-detect --pr 45990, rerun on this head, reports the same three surfaces and no others:

  • hot-path bots-items-owner-methods.ts
  • hot-path bots-items-write-support.ts
  • subscribe use-bot-host-read-state.ts:19

The two newest commits don't touch any of those three files. They change bot-host-read-store.ts, bot-host-read-asks.ts, items/use-bot-items.ts and bot-items-list-load.ts.

Workload terms:

  • O: open items, 50 or 600.
  • Closed: 400 Closed items.
  • D: Closed pages loaded below the first. D ≤ 7 at 400 Closed; D = 19 means 1,000 Closed loaded.
  • k: items one notice names.
  • L: loaded items that link a Dispatch.

Finding (P1): the "unread" mark outlives the read that pages the rest

Where: src/shared/bots/bot-items-list-load.ts:144 sets the mark, and :161 (and :154) never clear it. Introduced by 3d409ce9287.

How it happens:

  1. A whole read stops after its first page because a newer ask is waiting. Its value V gets marked (unread.set, :144).
  2. The newer ask is usually the notice for the very change that the first page already shows. Its named read merges nothing new, so mergeNamedBotItems returns V itself.
  3. The resume pages the rest (:61). The Closed rows below rarely change, so reuseEqualJson(kept, joined()) returns V, and V keeps its mark.
  4. From then on:
    • every whole read skips the unchanged-first-page shortcut (!unread.has(previous), :100) and pages all D pages;
    • every named read resumes from the stale cursor (:47) and pages the remaining depth again.

Reproduced (deterministic): 100 open, 200 Closed, D = 3, committed loader.

Step Calls at this head Calls when never stopped (control)
Whole read that stops (newer ask waiting) first n/a
Named read of the item it already shows, then the resume named + 3 pages; same identity as V n/a
Whole read, nothing changed (#1, #2, #3) first + 3 pages, each time first
Named read, nothing changed (#1, #2) named + 3 pages, each time named

In the read-store model (O = 600, 1 notice/s for 15 s, the last change landing as a paired refresh starts, then idle to 600 s with the paired refresh backing off from 15 s to 120 s):

500 ms latency Closed pages read, previous head b43ab06 Closed pages read, this head Next whole read of the unchanged list
D = 3 6 27 (21 repeats) 1 + 3 calls (previous head: 1)
D = 7 14 63 (49 repeats) 1 + 7 calls (previous head: 1)

Price per whole read while the mark is stuck (paired refresh every 15–120 s while visible; reopen of a hidden window that missed notices; Retry; a notice naming no items):

O Base This head (D = 7)
50 1 call, 2 queries, 201 rows to main, 100 views 8 calls, 9 queries, 908 rows, 450 views
600 1 call, 7 queries, 1,306 rows, 650 views 8 calls, 14 queries, 2,013 rows, 1,000 views
600, older paired host (it ignores closedOnly, so every page carries the open list) 1,306 rows 8 × 1,306 = 10,448 rows

Bounds:

  • The extra cost scales with D, which grows with how far the user paged.
  • Each extra page is a round trip on a paired link.
  • It persists at idle for as long as nothing changes.
  • During worker churn, a worker notice whose named merge changes nothing pays the D-page tail on each read, up to 2 reads/s per bot.
  • It is not a new wakeup: the extra calls ride existing triggers.

Fix:

  • Clear the mark once a read pages to its depth: const value = reuseEqualJson(kept, joined()); unread.delete(value); return value at :161, and the same at :154.
  • Guard test: stop a whole read, then make a named read that changes nothing, then a whole read of the unchanged list. That last read must make exactly 1 call. This head makes 1 + D.

Other observations on the newest commits (none is more work than base)

  • Show more while a tail is owed re-reads the page it just appended.

    • Where: :113-118, then the resume at :61, whose want already includes that page.
    • Cost: the D = 3 run read page@201 twice. That is 1 extra call of 50 Closed rows per such Show more.
    • Base's Show more alone carried the open list (201 / 1,306 rows), so the total is not above base.
    • Fix: resume before appending, or cap the resume's want at the depth from before the Show more page.
  • Whole reads restart from the top and stop after the first page whenever an ask waits.

    • Only named and Show more reads resume from the mark.
    • Effect: when whole asks arrive faster than one round trip, the rows below the first page are not refreshed until the asks calm, and the first page (with the open list) is read more often than at the previous head.
    • Whole asks arrive that fast mainly from older paired hosts, where every notice is a whole read.

    Rows over 60 s at O = 600 and 500 ms latency:

    Host and depth Base Previous head This head
    Older paired host, D = 3 83,200 81,250 82,550
    Older paired host, D = 19 104,000 91,650 103,350
    Current host with whole asks only, D = 3 83,200 25,450 42,950
    Current host with whole asks only, D = 19 104,000 11,850 44,550
    • This head stays at or under base in every row.
    • A current host sends whole asks only for more than 100 uids, unknown kinds, the paired refresh or a visibility return.
    • Fix: let a whole read stop only after it has read at least one page below (paged = false at the start), and resume from the mark when the first page is unchanged.

The newest commits under a steady stream of item notices

Model: current host, O = 50 and 600, a whole read with a moved first page at t = 0, then named notices for 60 s. Calls are shown as first + Closed pages + named.

Latency Rate D Base (calls / rows, O = 600) Previous head This head Page repeats, this head
5 ms 1/s 0 / 3 / 19 61 / 39,650 · 244 / 158,600 · 1,220 / 793,000 2+0+59 · 2+3+59 · 2+19+59 same as previous head 0
5 ms 2/s 0 / 3 / 19 121 / 78,650 · 484 / 314,600 · 2,420 / 1,573,000 2+0+119 · 2+3+119 · 2+19+119 same 0
500 ms 1/s 0 / 3 / 19 61 / 39,650 · 128 / 83,200 · 160 / 104,000 2+0+59 · 2+3+58 · 2+19+50 2+0+59 · 2+3+59 · 2+19+59 0
500 ms 2/s 0 / 3 / 19 121 / 78,650 · 128 / 83,200 · 160 / 104,000 2+0+119 · 2+3+116 · 2+19+100 same as previous head 0
  • Calls per read. At slow latency, a stopped read costs 1 call, and each resumed read costs 1 named call plus 1 page.
  • Progress. Each resumed read advances the tail one page and repeats none. All D pages are read once in total, the same as the previous head; rows at O = 600, D = 19 are 2,309 at both heads.
  • Extra calls at D = 19, 1/s, 500 ms. This head made 9 more named calls than the previous head (80 vs 71). They are notices that the previous head coalesced behind its 10 s tail, and they keep the open rows fresh sooner.
  • One page per call. Every page call asks for one page with closedOnly (:148-152 with closedLimit ≤ 50; :116, which the host caps at the default 50).
    • The first page is {}: the open list plus 50 Closed rows.
    • Named reads ask for at most 100 uids per call.
    • The chat-filtered list passes no waiting, so it never stops and is never marked.
  • Added work per read. A resume runs one filter over the value (:56-58). A stop runs joined + withLoadedBelow + reuseEqualJson, each O(N), where N = O + 50(1 + D).
    • At O = 600, D = 19 (N = 1,600), a resumed read (named + 1 page + stop) took 0.51 ms in total under tsx. 0.27 ms of that was the fake host's answer clones, so the loader's own share is about 0.24 ms per read.
    • At ≤ 2 reads/s per bot, that is under 0.5 ms/s on the renderer. Not a finding.

Plain host reads (bot-host-read-store.ts:119-122)

  • Change: activity and chat-tree reads now skip pick + reuseEqualJson when the read is no longer live (superseded, or its last surface closed).
  • Effect: this only saves an O(answer) compare. It changes neither the call count nor when listeners run.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

Unchanged since b43ab06e5d5. The SQLite queries run on the bots DB worker; main joins links, builds the views and serializes the answer.

Call list queries, O = 50 / 600 Rows to main Views
Base, any call (a Closed page also carried the open list) 2 / 7 201 / 1,306 100 / 650
Head, whole read (summary) 2 / 7 201 / 1,306 100 / 650, without the long texts
Head, named read (uids, :84-98) 1 / 1 2k / 2k k / k
Head, Closed page (closedOnly, :101-102) 1 / 1 101 / 101 50 / 50

Per trigger, base → head:

  • Item change: 1 + D whole calls → 1 named call. A stuck mark adds the remaining depth (the finding).
  • Worker notice: 1 + D whole calls → ⌈L/100⌉ named calls, and 0 when L = 0. A stuck mark adds the remaining depth if the merge changes nothing.
  • Show more: 1 call carrying the open list → 1 closedOnly call. While a tail is owed, the owed pages are added, plus 1 repeat.
  • Whole read, first page unchanged (paired refresh, Retry, visibility return): 1 → 1 call. While stuck: 1 + D (the finding).
  • Whole read, first page moved: 1 + D calls, each carrying the open list → 1 call + up to D closedOnly pages. It stops early if an ask is waiting.
  • Older paired host: its notices carry no uids, so every read is whole, as at base. The stuck mark applies here too (see the table above).
  • Older client or the phone on a current host: they take the base path. The only addition is one Set filter (stillOpen, :115).

Author's benchmark (from the status comment, measured at f09321f4484; these paths are unchanged since then except for the loader's stop/resume):

  • List reads per update: 6 → 1.
  • Main handler time for list reads per 60 s: 1.9 s → 0.08 s at 50 open, and 10.0 s → 0.07 s at 600 open.
  • List bytes over 60 updates: 73.8 MB → 0.06 MB at 50 open, and 475 MB → 0.05 MB at 600 open.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult. A dozen agents may call the CLI every few seconds.
  • Change: changed([record]) passes the records it already holds; it previously passed only their bot ids. They are grouped by bot in O(k). There is no new store read, IPC or timer.
  • Notices: addBotChange keeps a per-bot uid Set, which becomes null past 100 uids. Pending state is dropped each 500 ms window.
  • Frames: the rate is unchanged. Each frame grows by at most 100 uids per bot.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19)

Store census. Unchanged by the newest commits. Each useSyncExternalStore mount adds one listener.

  • itemsRead: 3 listeners per useBotItems mount. It's mounted by BotActivityPanel (one per open bot panel) and by use-bot-group-items.tsx (one per group member).
  • chatTreeRead: 3 listeners per mount. It's mounted by BotActivityPanel, BotChatMentionTitle, use-bot-now and use-bot-chat-tree.
  • activityRead: 1 listener per mount. It's mounted by BotActivityPanel, BotSettingsRoot, BotLookAroundSection, use-bot-now, use-bot-group-items and the native-chat automation rows.
  • Snapshot reader: botItemLastRead reads a snapshot without subscribing.
  • Phone: it doesn't use this store.

When the store notifies:

  • Only when the value's identity changes, or on a failure transition.
  • A resumed read can notify twice: show with the merged named value at :52, then the landing if the pages below changed. That is the same 2-per-read bound the moved-first-page whole read already had.
  • Idle: 0/s before and after.
  • Under load: at most 2 reads/s per bot (500 ms gap), so at most 4 notifies/s per bot. Each one carries a new identity, and reads that change nothing notify no one.

orca:bots-changed census (17 renderer sites, unchanged):

  • Changed by this PR:
    • use-bot-host-read.ts:109: one read per bot, gated on visibility.
    • use-bot-items.ts:207: the chat-filtered list, with no visibility gate, as at base.
  • Unchanged, desktop: bot-mention-chats-read.ts:133, bot-tool-checks.ts:61, ComposioEventsCard.tsx:152, composio-client.ts:100, composio-key-client.ts:41, google-setup-run-store.ts:117, use-bot-item-view.ts:130, use-bot-group-transcript.ts:52, use-bot-tidy-up.ts:67, bot-access-requests.ts:155, bot-group-list.ts:39, bot-host-orca-account.ts:125, bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167, and the raw listener in use-webhook-data.ts:100.
  • Emitters:
    • main → preload bot-changes-bridge.ts (one parse) → emitBotsChangedWindowEvent;
    • paired hosts: runtime-client-ipc-bridge.ts:129.
  • Phone (mobile/, no file changed by this PR): host-bot-refresh.ts, use-host-bot-chat-trees.ts, host-worktree-refresh.ts, home-bots-query.ts, use-host-bots.ts, use-bot-access-requests.ts, use-host-screen-controller.ts, and the route read count behind use-phone-bot-items, use-phone-bot-chat-tree and use-mobile-bot-tidy-up.
  • Frame rate: 0/s idle before and after. Under load, at most 2/s per host, as at base. Change-free frames: 0 before and after.

Regression classes

  • Re-reading unchanged input: finding. A stuck mark re-pages the Closed depth on every unchanged whole read, and the rest of it on unchanged named reads.
  • No-op store write; update published when nothing changed: disproved. Unchanged reads keep the old identity and notify no one.
  • Whole snapshot per change: fixed by this PR (named reads).
  • Fixed-cadence poll, idle wakeups, eager imports: no matching code. The stuck mark adds work to the existing paired refresh but no wakeup.
  • Per-entity state: the WeakMap is keyed by value and goes with it. Store entries are dropped on the last unsubscribe.
  • Hot-path rescans: the resume filter and stop join are O(N) once per read (measured above).
  • Unbounded fan-out: none. Calls run one at a time per list.
  • Sync SQLite on main: none. The queries run on the DB worker.

Six questions

  1. Unused work before the gate: reviewed. Plain reads that are no longer live now skip the compare. The stuck mark bypasses the unchanged-first-page gate (finding).
  2. Ownership: reviewed. One store entry per bot; the chat-filtered list is one per filter and never stops.
  3. Thread: reviewed. The pages run SQLite on the DB worker, and main does the views. The loader's added work is about 0.24 ms per read at N = 1,600.
  4. Growth and progress: reviewed.
    • Resumed reads progress one page per read with no repeats.
    • Whole reads under sustained whole asks restart from the top and don't progress below the first page (observation).
    • The stuck mark repeats pages (finding).
  5. Execution host: reviewed for current hosts, older paired hosts (the stuck mark costs (1 + D) × the open list there) and the phone (unchanged). Live paired or SSH timing wasn't measured.
  6. Obsolete work: reviewed. live() and waiting() gate each next call, and an in-flight RPC finishes and is dropped.

Not assessed: live paired or SSH timing, and the real size of a summary row.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head bc43cee (hot-path, subscribe)

Verdict: no regression. The P1 from the scan of 3d409ce is fixed. A read that pages through to its depth now clears the stop mark (readThrough, src/shared/bots/bot-items-list-load.ts:183,187-190). After that, an unchanged whole read or named read costs 1 call again. Across every workload I modeled, the PR makes no more calls than base and returns fewer or equal rows. This PR adds no idle wakeups: 0/s before and after on main, the renderer and the daemon. Two small observations remain (below). Neither costs more than base, and neither blocks.

Method.

  • I read this head against the merge-base edf6acdf70b and against 3d409ce9287, the head of the previous scan.
  • I ran the committed src/shared loader by itself (tsx, outside the repo) against the test fixture's host, at both heads. The workloads were:
    • deterministic call logs for each read shape;
    • a virtual-time model of the read store. It runs one read at a time per bot, with 500 ms between read starts; a newer ask sets again, which is what waiting() reads.
  • Each model run is 60 s of notices, then 120 s of idle with a paired refresh (a whole ask) every 15 s.
  • "Rows" are rows in the host's answers. On main, each answered row costs about 2 DB-worker rows (viewRows).
  • I measured no app timing.

Surfaces. perf-surface-detect --pr 45990, rerun on this head, reports the same three surfaces and no others:

  • hot-path bots-items-owner-methods.ts
  • hot-path bots-items-write-support.ts
  • subscribe use-bot-host-read-state.ts:19

The newest commit doesn't touch those three files. It changes bot-items-list-load.ts, bot-host-read-store.ts and items/use-bot-items.ts, and adds bot-read-more-failed.ts.

Workload terms:

  • O: open items, 50 or 600.
  • Closed: 400 Closed items.
  • D: Closed pages loaded below the first. D ≤ 7 at 400 Closed; D = 19 means 1,000 Closed loaded.
  • k: items one notice names.
  • L: loaded items that link a Dispatch.
  • T: pages still owed below a stop mark.

The stop mark: set, read, cleared

  • Set at :162, only when a read stops after at least one page below its top (paged starts false at :155, so every stopped read moves down at least one page).
  • Read in two places:
    • named, Show more and plain asks (:47, then readOnBelow at :55);
    • a whole read whose first page is unchanged (:122-123).
  • Cleared on every path that ends the paging:
    • it pages to the depth (:183);
    • a page fails (:172), which truncates the value to the stop point, so nothing is owed;
    • the value no longer has a Closed cursor.

Every path that returns a marked value without paging still owes that tail, so keeping the mark is correct there:

  • readOnBelow when the read is no longer live (:65); that value isn't landed;
  • a failed Show more (:48-53, :116-120), which re-marks landed with the same cursor.

Reproduced (deterministic): 100 open, 200 Closed, D = 3, committed loader.

Step 3d409ce This head
Whole read that stops (newer ask waiting) first first, page@251 (at least one page below)
Named read of the item it already shows, then the resume uids1 + 3 pages, same identity uids1 + 2 pages, same identity
Whole read, unchanged (#1, #2) first + 3 pages, each time first, each time
Named read, unchanged uids1 + 3 pages uids1

Under steady asks, with all pages always waiting: one resumed read per notice advanced one page and repeated none (uids1,page@201, then uids1,page@151, then uids1). Then whole reads cost first only.

Steady notice streams (read-store model, O = 600; O = 50 gives the same calls)

"Calls" are calls during the 60 s stream. "Pages" is Closed page calls (distinct pages in brackets). "Idle" is calls during the 120 s idle (8 paired refreshes).

Ask stream Latency Rate D Base calls / rows / idle This head calls / rows / idle 3d409ce idle
Item notices (current host) 5 ms 1/s 0 / 3 / 19 60 / 44,200 / 8 · 240 / 176,800 / 32 · 1,200 / 884,000 / 160 60 / 5,909 / 8 · 63 / 6,059 / 8 · 79 / 6,859 / 8 8 · 8 · 8
Item notices 5 ms 2/s 0 / 3 / 19 120 / 83,200 · 480 / 332,800 · 2,400 / 1,664,000 120 / 5,969 · 123 / 6,119 · 139 / 6,919 (idle 8) 8
Item notices 500 ms 1/s 0 / 3 / 19 60 / 44,200 · 124 / 101,400 · 130 / 188,500 60 / 5,909 · 63 / 6,059 · 79 / 6,859 (idle 8) 8
Item notices 500 ms 2/s 0 / 3 / 19 120 / 83,200 · 124 / 101,400 · 130 / 188,500 120 / 5,969 · 120 / 6,119 · 120 / 6,919 (idle 8) 8
Whole asks, older paired host 5 ms 1/s 3 / 19 240 / 176,800 · 1,200 / 884,000 240 / 161,200 · 1,200 / 785,200 (idle 8) 8
Whole asks, older paired host 500 ms 1/s 3 / 19 124 / 101,400 · 130 / 188,500 122 / 84,500 · 130 / 94,900 (idle 8 · 16*) 8 · 16*
Whole asks, older paired host 500 ms 2/s 3 / 19 124 / 101,400 · 130 / 188,500 123 / 85,150 · 130 / 95,550 (idle 8 · 17*) 32 · 159
Whole asks only, current host 500 ms 2/s 3 / 19 124 / 101,400 · 130 / 188,500 123 / 47,950 · 130 / 48,750 (idle 8 · 17*) 32 · 159

* The extra idle calls are the stream's last read finishing its tail (8 pages, each read once, ending by t = 69 s). After that, every refresh is 1 call.

  • Item notices:
    • Each Closed page is read exactly once in the whole run (D pages, D distinct). Each notice costs 1 named call.
    • The 500 ms, 2/s rows are bounded by the link: 120 calls in 60 s at 500 ms each.
  • Whole asks:
    • When the first page moves, each read pages the loaded depth again, as base does, with the same call count.
    • On a current host, the pages carry only Closed rows (closedOnly).
    • On an older host, which ignores closedOnly, every page carries the open list too. Even so, rows stay at or under base, because a waiting ask stops the read after one page.
    • Every page was still reached at least once (19 distinct of 19).
  • The 3d409ce stuck mark is gone. Idle went from 32 / 159 calls to 8 / 17.

One page per call, with closedOnly. Every Closed page call in the logs above asked for one page with closedOnly (:166-170, closedLimit ≤ 50; :134, where the host's default is 50). The first page is {}: the open list plus 50 Closed rows. Named reads ask for at most 100 uids per call (:207-213). No call answered with the open list below the first page on a current host.

Observations (none is more work than base)

  1. Show more while a tail is owed re-reads the page it just appended.
    • Where: :130-137 (or :116) appends the page, then readOnBelow (:55, :123) pages from the mark down to the new depth, which includes that page.
    • Reproduced: at 100 open, 400 Closed and D = 3, after a stop, all three of these read page@301 twice:
      • Show more alone: page@301, page@401, page@351, page@301;
      • named read + Show more;
      • whole read + Show more.
    • Cost: 1 extra closedOnly call per Show more pressed while a tail is owed. That is 50 rows, about 101 DB rows and 50 views on main, and a round trip on a paired link.
    • It was there at 3d409ce for the named and plain shapes. This head adds it to the whole-read shape, which is now 5 calls, the same count as 3d409ce.
    • Base's Show more was 1 call carrying the open list (201 / 1,306 rows). The owed tail would otherwise be paid by the next read, so the total is under base.
    • Fix (unverified): page the owed tail before appending the Show more page, so the append reads from the tail's end.
  2. A named read to a host that ignores uids pages the owed tail twice.
    • Where: :94 falls back to a whole read, which resumes from the mark at :123, and then loadBotItemsList resumes from the same from again at :55.
    • Reproduced: uids1, first, page@201, page@151, page@201, page@151.
    • Not reachable today. Named asks only come from notices that carry itemUids or namesItems, and only hosts that answer uids send those; both were added in this PR. For that reason it isn't graded.
    • Fix: compute from after loadAsked returns, or skip the outer resume when the value is no longer marked.

Failed Show more (BotReadMoreFailed)

  • Named + Show more (:101-103), whole with an unchanged first page + Show more (:116-120), and a moved whole read whose page fails while more was asked (:173-175) now reject with what loaded.
    • The store lands it (bot-host-read-store.ts:142-144, one notify if the identity changed) and fails only the Show more waiters (they're told null).
    • The chat-filtered list does the same (use-bot-items.ts:183-184).
  • Reproduced: a failed Show more in a named + Show more read made uids1 + 1 failed call. landed was the merged value, still marked. The next named read resumed page@401, page@351, and the whole read after it cost first.
  • Cost: no retry loop or new call. The failure doesn't set failure, so it doesn't add a Retry read.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

Unchanged since b43ab06e5d5. The SQLite queries run on the bots DB worker; main joins links, builds the views and serializes the answer.

Call list queries, O = 50 / 600 Rows to main Views
Base, any call (a Closed page also carried the open list) 2 / 7 201 / 1,306 100 / 650
Head, whole read's first page (summary) 2 / 7 201 / 1,306 100 / 650, without the long texts
Head, named read (uids, :84-98) 1 / 1 2k / 2k k / k
Head, Closed page (closedOnly, :101-102) 1 / 1 101 / 101 50 / 50

Per trigger, base → head (400 Closed, D ≤ 7):

  • Item change: 1 + D calls carrying the open list → 1 named call, plus at most T owed pages (each read once).
    • At D = 7, O = 600: 8 calls, 14 queries, 10,448 rows → 1 call, 1 query, about 2 rows.
  • Worker notice: 1 + D whole calls → ⌈L/100⌉ named calls, and 0 when L = 0. Plus T owed pages.
  • Show more: 1 call carrying the open list → 1 closedOnly call. While a tail is owed: T + 1 + 1 repeat (observation 1).
  • Whole read, first page unchanged (paired refresh every 15–120 s, Retry, visibility return): 1 → 1 call, plus T owed pages once.
  • Whole read, first page moved: 1 + D calls each carrying the open list → 1 call + up to D closedOnly pages. It stops after at least one page when an ask waits.
  • Older paired host: its notices carry no uids, so every read is whole. The call count matches base; rows are at or under base (table above).
  • Older client or the phone on a current host: they take the base path. The only addition is one Set filter (stillOpen).

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult. A dozen agents may call the CLI every few seconds.
  • Change: changed([record]) passes the records it already holds, grouped by bot in O(k). There is no new store read, IPC or timer.
  • Notices: at most 100 uids per bot in each 500 ms notice window; past that, the notice reads whole.
  • Frames: the rate is unchanged from base. Each frame grows by at most 100 uids per bot.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19)

Store census. Unchanged by the newest commit. Each useSyncExternalStore mount adds one listener; there are two hooks, useBotHostRead and useBotHostReadState.

  • itemsRead: 3 listeners per mount. It's mounted by BotActivityPanel.tsx:102 and by use-bot-group-items.tsx:62 (one per group member).
  • chatTreeRead: 3 listeners per mount. It's mounted by BotActivityPanel.tsx:101, BotChatMentionTitle.tsx:22, use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead: 1 listener per mount. It's mounted by BotActivityPanel, BotSettingsRoot, BotLookAroundSection, use-bot-now, use-bot-group-items, NativeChatAutomationResultRow, NativeChatAutomationRunBody and NativeChatWaitRow.
  • Snapshot reader: botItemLastRead reads a snapshot without subscribing.
  • Chat-filtered list: useBotChatItems (use-bot-items-shown-list.ts:50) keeps its own state.
  • Phone: it doesn't use this store.

When the store notifies:

  • Only when the value's identity changes, or on a failure transition. land (:118-127) is the same check as before, now also used by BotReadMoreFailed.
  • A resumed read can notify twice: show with the merged named value, then the landing if the pages below changed. The whole-unchanged resume shows previous itself, so nobody is notified.
  • Idle: 0/s before and after.
  • Under load: at most 2 reads/s per bot (500 ms gap), so at most 4 notifies/s per bot. Unchanged reads notify no one.

orca:bots-changed census (unchanged by the newest commit):

  • Changed by this PR:
    • use-bot-host-read.ts:109: one read per bot, gated on visibility.
    • use-bot-items.ts:210: the chat-filtered list.
  • Unchanged, desktop: bot-mention-chats-read.ts:133, bot-tool-checks.ts:61, ComposioEventsCard.tsx:152, composio-client.ts:100, composio-key-client.ts:41, google-setup-run-store.ts:117, use-bot-item-view.ts:130, use-bot-group-transcript.ts:52, use-bot-tidy-up.ts:67, bot-access-requests.ts:155, bot-group-list.ts:39, bot-host-orca-account.ts:125, bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167, and the raw listener in use-webhook-data.ts.
  • Emitters:
    • main → preload bot-changes-bridge.ts (one parse) → app-lifetime-ipc-bridge.ts → emitBotsChangedWindowEvent;
    • paired hosts: runtime-client-ipc-bridge.ts:128.
  • Phone (mobile/, no file changed): host-bot-refresh.ts:61, use-host-bot-chat-trees.ts:111, host-worktree-refresh.ts:100, home-bots-query.ts:61-64, use-host-bots.ts, use-bot-access-requests.ts, use-host-screen-controller.ts:88, and the route read count (use-route-bot.ts) behind use-phone-bot-items, use-phone-bot-chat-tree and use-mobile-bot-tidy-up.
  • Frame rate: 0/s idle before and after. Under load, at most 2/s per host (the 500 ms notice window), as at base. Change-free frames: 0 before and after.

Regression classes

  • Re-reading unchanged input: matched and disproved. The mark now clears, and unchanged whole and named reads cost 1 call (reproduced). The one-page Show more repeat is observation 1.
  • No-op store write; update published when nothing changed: disproved. land keeps the identity check, and an unchanged whole resume shows previous itself.
  • Whole snapshot per change: fixed by this PR (named reads).
  • Fixed-cadence poll, new idle wakeups, eager imports: no matching code. bot-read-more-failed.ts is a 6-line class.
  • Per-entity state: the WeakMap is keyed by value and is freed with it.
  • Hot-path rescans: the resume filter and stop join are O(O + 50(1 + D)) once per read, about 0.24 ms at N = 1,600 (measured at 3d409ce; this commit adds only a WeakMap.delete).
  • Unbounded fan-out: none. Calls run one at a time per list.
  • Sync SQLite on main: none. The queries run on the DB worker.

Six questions

  1. Unused work before the gate: reviewed. The unchanged-first-page gate holds again once the mark clears.
  2. Ownership: reviewed. There is one store entry per bot. The chat-filtered list is one per filter and passes no waiting, so it never marks.
  3. Thread: reviewed. Pages run SQLite on the DB worker and main builds the views. The loader's added work is a WeakMap.delete and a catch wrapper per read.
  4. Growth and progress: reviewed. Every stop advances at least one page, each owed page is read once, and the tail finishes once asks calm (model: all pages reached at 2/s, 500 ms, D = 19).
  5. Execution host: reviewed for current hosts, older paired hosts (rows ≤ base) and the phone (unchanged). Live paired or SSH timing wasn't measured.
  6. Obsolete work: reviewed. live() and waiting() gate each next call. An in-flight RPC finishes and is dropped, and a non-live resume keeps the mark for the next read.

Not assessed: live paired or SSH timing, and the real size of a summary row.

…n items closed since, keeps the list when a page fails, and reads before Show more; named reads go fifty a call

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

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: 0f47703b-b8ac-49e8-96a0-0ba960c1de19
Commits

Reviewing files that changed from the base of the PR and between 3d409ce and bc43cee.

Files selected for processing: 6

  • src/renderer/src/components/bots/bot-host-read-store.ts
  • src/renderer/src/components/bots/items/use-bot-items.ts
  • src/shared/bots/bot-items-list-load.performance.test.ts
  • src/shared/bots/bot-items-list-load.test.ts
  • src/shared/bots/bot-items-list-load.ts
  • src/shared/bots/bot-read-more-failed.ts

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

Comment thread src/shared/bots/bot-items-list-load.ts Resolved
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 8c3ad84 (hot-path, subscribe)

Verdict: regression (P1), one finding. Worker notices now read the loaded worker-linked items 50 uids per call (bot-items-list-load.ts:238-245), and every one of those calls pays a fixed, fleet-wide worker read on Electron main. At the default depth (no Show more pressed), that is ⌈L/50⌉ fleet reads per worker notice where base paid 1. The newest commit doubled the count: it was ⌈L/100⌉ at bc43cee.

Everything else in the newest commit is clean:

  • readOwedThenMore removes the extra page read on a Show more pressed while a tail is owed (observation 1 of the last scan).
  • Going on from the list's end repeats no page.
  • A failed owed page keeps the list and makes no retry loop. It does cost one more call per later read while it keeps failing (observation 2 below).

Idle wakeups: 0/s before and after on main, the renderer and the daemon.

Method.

  • I read this head against the merge-base edf6acdf70b and against bc43cee, which the last scan graded clean.
  • I ran the committed src/shared loader by itself (tsx, outside the repo) at both heads, against the test fixture's host. The workloads were:
    • deterministic call logs for each read shape;
    • a virtual-time model of the read store: one read at a time per bot, 500 ms between read starts, and waiting() true once a newer ask is in.
  • Each model run is 60 s of notices, then 120 s of idle with a paired refresh (a whole ask) every 15 s.
  • Base figures are the merge-base's whole-read path, as in the earlier scans. On base, a worker notice is a whole read.
  • I measured no app timing. Main-process costs below are source-proven call counts.

Surfaces. perf-surface-detect --pr 45990, rerun on this head, reports the same three surfaces and no others:

  • hot-path bots-items-owner-methods.ts
  • hot-path bots-items-write-support.ts
  • subscribe use-bot-host-read-state.ts:19

Since bc43cee, the head changed bot-items-list-load.ts and its tests. It also changed two type-only lines (bot-host-read-store.ts:118,143 and use-bot-items.ts:184).

Workload terms:

  • O: open items, 50 or 600.
  • Closed: 400 Closed items. D = 19 uses 1,050.
  • D: Closed pages loaded below the first.
  • L: loaded items that link a Dispatch.
  • T: pages still owed below a stop mark.

Finding (P1): a worker notice pays the fleet-wide worker read once per 50 linked items

  • Where. src/shared/bots/bot-items-list-load.ts:239-245 (introduced by this PR's named reads; the batch size went from 100 to 50 in 8c3ad84). namedParts (:257-266) expands a worker notice to every loaded item that links a Dispatch.

  • What each call costs on the host. Each uids call to bots.items.owner.list (bots-items-owner-methods.ts:84-98) runs botItems.views, then readLinkedWorkers (bot-items-link-join.ts:58-66), then readWorkers (bot-work-runtime.ts:86-103), then readDispatchWorkers → projectDispatchFleet (session-workers-method.ts:81-100,131). Per call, that path runs:

    • readDispatchFleetEvidence (:131): the orchestration fleet agent-status snapshot, which projects every agent pane on this host and reads the orchestration DB through sync SQLite on main;
    • the agent-status rows by pane;
    • listWorkerTerminalResources and getWorkerAttentionFactsForDispatches, both sync SQLite on main;
    • a federated snapshot read;
    • ensureSessionWorkerRecords;
    • one more bot-items list, with its counts aggregate over the bot's items.

    Only the per-item lineage walks and workspace reads split across batches. The fleet-wide part is paid again in full for each batch.

  • Trigger. Worker phase changes (bot-change-notices.ts:124), Dispatch row changes and paired-server verdicts. They are coalesced to at most one notice per 500 ms per host, so up to 2 worker notices/s for a bot while its agents work.

  • Count per worker notice (fleet-wide reads = calls):

L (loaded worker-linked) Base, D = 0 / 3 / 7 / 19 bc43cee This head
0 1 / 4 / 8 / 20 0 0
≤ 50 1 / 4 / 8 / 20 1 1
120 1 / 4 / 8 / 20 2 3
600 (O = 600) 1 / 4 / 8 / 20 6 12
  • Model, worker notices, O = 600 (calls in the 60 s stream; rows answered including the 8 idle refreshes, as in earlier scans):
Latency Rate Base (D = 0 / 3 / 19) bc43cee L = 120 / 600 Head L = 120 / 600
5 ms 1/s 60 / 240 / 1,200 calls; 44,200 / 176,800 / 884,000 rows 120 / 360 calls 180 / 720 calls; 12,400 / 41,200 rows
5 ms 2/s 120 / 480 / 2,400 calls 240 / 720 calls 360 / 1,440 calls; 19,600 / 77,200 rows
500 ms 1–2/s 60–130 calls, link-bound; 44,200–188,500 rows 121 121, link-bound; 10,120 / 11,800 rows
  • The call counts are the same for every D, and no call carried the open list.
  • Rows go down. Head answers 600 summary rows per notice where base answered 1,306 full rows.
  • Fleet reads go up. At D = 0 and 5 ms, 2/s, head runs 24 fleet-wide reads/s for one bot at L = 600, and 6/s at L = 120. Base ran 2/s, and bc43cee 12/s and 4/s.
  • Each read is O(agent panes on this host), on main. At the reference fleet (a few hundred terminals, 100+ agents) that work grows with the fleet, and it grows again with L. Neither changes the output.
  • D = 0 is the common case: it is the list as opened.
  • User impact. More main-thread occupancy (sync orchestration SQLite plus the pane projection) for each burst of agent phase changes while a bot's Items list is open. The time per read is unmeasured.
  • Fix (unverified). Any one of these:
    • (a) Read whole when ⌈L/50⌉ > 1 + D. A whole read is 1 + D calls, the base count, and still returns summary rows with closedOnly pages.
    • (b) Compute readDispatchFleetEvidence once per worker read on the host. For example, pass evidence through projectDispatchFleet's existing read.evidence option, from a cache keyed to the agent-status generation.
    • (c) Keep the 50-row cap only where an answer-size cap applies (paired links), and take listPageMax locally. This halves the count but still exceeds base at D = 0 for L > 100.
  • Check that proves it. Extend bot-items-list-load.performance.test.ts ("reads the loaded items that link a worker…"): at D = 0 with L = 120 and L = 600, assert the worker-notice calls are ≤ 1 + D. Today the test hardcodes [50, 50, 50, 50], which is 4 calls at D = 1, where base made 2.

Newest commit's loader changes (deterministic, 100 open, 400 Closed, D = 3, after a read that stopped)

Step bc43cee This head
Show more while owed page@301, page@401, page@351, page@301 page@401, page@351, page@301 (no repeat)
Named + Show more while owed uids1 + 4 pages (1 repeat) uids1 + 3 pages
Whole (unchanged) + Show more while owed first + 4 pages (1 repeat) first + 3 pages
…then whole first first
60 items close in bulk, named read (start at the list's end) uids60, page@401 uids50, uids10, page@401; then whole = first; 260 Closed, no duplicates
Show more while owed, newer ask waits; then named; then whole page@301, page@401 · uids1, page@351, page@301 · first page@401, page@301 · uids1, page@351, page@301 · first (same single repeat)
Older host, named read while owed uids1, first + tail twice same (unreachable, as before)

The owed mark.

  • Set: only by a stop after at least one page (:186-190).
  • Cleared: by a read through to the depth (readThrough, :214).
  • Kept on a failed owed page (:198-202). It stays set exactly as long as that page keeps failing.
  • Retry behavior:
    • A failure there returns kept without throwing. It sets no failure, so no Retry read is added, and nothing reschedules.
    • Each later read (a notice ask or a paired refresh) tries the owed page once more. There is no loop.
    • Once the page succeeds, the next read pages the tail and clears the mark: first, page@401, page@351, then first.
    • At bc43cee, the same failure cleared the mark by cutting the list down to 100 Closed rows. This head keeps all 200.

One page per call, with closedOnly.

  • Across all 144 model runs and every deterministic log, every Closed page call asked for one page with closedOnly: true and closedLimit ≤ 50. None carried the open list on a current host. The first page is {}.
  • Named calls carry ≤ 50 uids.

Observation 2 (not graded): a page that keeps failing makes every later read repeat the owed pages above it

  • Where: :198-202. When the j-th owed page fails, the j − 1 pages read before it in that read are thrown away and kept is returned, still owed from start.
  • Reproduced: with the second owed page failing, each of 4 named reads ran uids1 + page@401 + page@351✗.
  • Cost while it keeps failing: j calls per read, at most T ≤ D. Under item notices at 2/s that is at most 2·D extra closedOnly calls/s. That is still under base's 1 + D calls per notice that carried the open list, and it isn't a loop.
  • Fix: on failure, return the joined pages read so far, marked owed at the failing cursor. This is the same as the waiting stop at :186-190, so the next read starts at the failed page.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125, unchanged since b43ab06e5d5)

The bot-items queries run on the bots DB worker. Main joins links and workers (sync orchestration SQLite), builds views and serializes.

Call list queries, O = 50 / 600 Rows to main Views Fleet-wide worker read
Base, any call (a Closed page also carried the open list) 2 / 7 201 / 1,306 100 / 650 full 1 if any row links a live Dispatch
Head, whole read's first page (summary) 2 / 7 201 / 1,306 100 / 650 summary 1 if linked
Head, named read (uids, ≤ 50) 1 / 1 ≤ 100 / ≤ 100 ≤ 50 1 if linked
Head, Closed page (closedOnly) 1 / 1 101 / 101 50 1 if linked

Per trigger, base → head (400 Closed, D ≤ 7, O = 600):

  • Item change (k = 1): 1 + D calls, each carrying the open list → 1 named call, plus at most T owed pages (each read once).
    • At D = 7: 8 calls, 14 queries, 10,448 rows → 1 call, 1 query, about 2 rows.
    • Model at 5 ms, 1/s: base 60 / 240 / 1,200 calls (D = 0 / 3 / 19); head 60 calls and 60 named rows, identical to bc43cee.
  • Worker notice: 1 + D → ⌈L/50⌉ (the finding).
  • Show more: 1 call carrying the open list → 1 closedOnly call. While a tail is owed, T + 1 calls with no repeat (the extra repeat is fixed).
  • Whole read, first page unchanged (paired refresh every 15–120 s, Retry, return to visible): 1 → 1, plus T owed pages once. While an owed page keeps failing: +j calls per read.
  • Whole read, first page moved: 1 + D calls, each carrying the open list → 1 + D closedOnly calls.
    • Model, current host, 500 ms, 2/s: base 124 / 130 calls and 101,400 / 188,500 rows (D = 3 / 19); head 121 / 121 stream calls and 47,950 / 48,750 rows.
    • Every Closed page was read once, with no repeats.
  • Older paired host (no uids, whole notices): same call count as base.
    • Model, 5 ms, 1/s, D = 19: 1,200 calls either way; base 884,000 rows vs head 785,200.
    • Head, 500 ms, 2/s: 121 calls, 95,550 rows.
  • Older client or the phone on a current host: base path. The only addition is the stillOpen filter.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult (a dozen agents calling the CLI every few seconds).
  • Change: changed([record]) groups the held records by bot in O(k). No new store read, IPC or timer.
  • Notices: at most 100 uids per bot in each 500 ms notice window; past that, the notice reads whole. A notice of 51–100 uids now costs 2 named calls instead of 1, against base's 1 + D.
  • Frames: same rate as base. Each frame grows by at most 100 uids per bot.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19)

The census is unchanged since bc43cee; only a type changed in the store.

Store listeners. Each useSyncExternalStore mount adds one listener (useBotHostRead / useBotHostReadState).

  • itemsRead: 3 per mount. It's mounted by BotActivityPanel.tsx:102 and by use-bot-group-items.tsx:62 (one per group member).
  • chatTreeRead: 3 per mount. It's mounted by BotActivityPanel.tsx:101, BotChatMentionTitle.tsx:22, use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead: 1 per mount. It's mounted by BotActivityPanel, BotSettingsRoot, BotLookAroundSection, use-bot-now, use-bot-group-items, NativeChatAutomationResultRow, NativeChatAutomationRunBody and NativeChatWaitRow.
  • No subscription: botItemLastRead reads a snapshot.
  • Own state: useBotChatItems (use-bot-items-shown-list.ts:50).
  • Phone: doesn't use this store.

When the store notifies:

  • Only when the value's identity changes, or on a failure transition (land, :118-127).
  • A failed owed page returns kept, so no notify.
  • A read that goes on below can notify twice: show, then the landing.
  • Idle: 0/s before and after.
  • Under load: at most 2 reads/s per bot, so at most 4 notifies/s per bot. Unchanged reads notify no one.

orca:bots-changed listeners:

  • Changed by the PR: use-bot-host-read.ts:109, use-bot-items.ts:210.
  • Unchanged, desktop: bot-mention-chats-read.ts:133, bot-tool-checks.ts:61, ComposioEventsCard.tsx:152, composio-client.ts:100, composio-key-client.ts:41, google-setup-run-store.ts:117, use-bot-item-view.ts:130, use-bot-group-transcript.ts:52, use-bot-tidy-up.ts:67, bot-access-requests.ts:155, bot-group-list.ts:39, bot-host-orca-account.ts:125, bot-host-per-bot-read.ts:142, bot-host-refresh.ts:167, and the raw listener in use-webhook-data.ts.
  • Emitters:
    • main → preload bot-changes-bridge.ts (one parse) → app-lifetime-ipc-bridge.ts → emitBotsChangedWindowEvent;
    • paired hosts: runtime-client-ipc-bridge.ts:128.
  • Phone (mobile/, no file changed): host-bot-refresh.ts, use-host-bot-chat-trees.ts, host-worktree-refresh.ts:39-102, use-host-worktree-catalog.ts:68-271, home-bots-query.ts, use-host-bots.ts, use-bot-access-requests.ts, use-host-screen-controller.ts:108, and the route reads behind use-phone-bot-items, use-phone-bot-chat-tree and use-mobile-bot-tidy-up.
  • Frame rate: 0/s idle before and after. Under load, at most 2/s per host (the 500 ms notice window), as at base. Change-free frames: 0.

Regression classes

  • Re-reading unchanged input: matched.
    • The Show more repeat is fixed.
    • A failing owed page repeats the pages above it on each read while it fails (observation 2).
    • Disproved for the steady state: an unchanged whole read is first only.
  • Subprocess/RPC per item, hot-path rescans: finding. One fleet-wide worker read per 50 linked items, per worker notice.
  • Sync SQLite on main: reached through that finding (orchestration DB). The bot-items queries stay on the DB worker.
  • No-op store write; update published when nothing changed: disproved. A failed owed page returns kept itself.
  • Fixed-cadence poll, new idle wakeups, eager imports, per-entity state: no matching code. The WeakMap is keyed by value.
  • Unbounded fan-out: none. Calls run one at a time per list.

Six questions

  1. Unused work before the gate: reviewed. The unchanged-first-page gate holds, and a failed owed page doesn't land.
  2. Ownership: finding. Fleet-wide worker evidence is rebuilt for each batch of one read.
  3. Thread: reviewed. The worker join is sync orchestration SQLite plus the pane projection on Electron main; the bot-items queries are on the DB worker.
  4. Growth and progress: reviewed.
    • Every stop advances at least one page, and the mark clears on success.
    • A persistently failing page makes no loop, but it repeats up to T pages per read (observation 2).
    • Worker reads grow with L/50 (the finding).
  5. Execution host: reviewed for current hosts, older paired hosts and the phone. At 500 ms the named calls are link-bound (121 calls/min). Live paired or SSH timing wasn't measured.
  6. Obsolete work: reviewed. live() and waiting() gate each next page. readNamed checks only live(), so one worker read's batches finish even when a newer ask waits.

Not assessed:

  • the time of one fleet-wide worker read at the reference fleet, and the size of a 100-row summary answer against the paired cap;
  • live paired or SSH timing.

… loaded pages; a failed page going on below a stopped read keeps the pages it read
…ges reads every loaded page, counting pages still owed
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head cd3a7ad (hot-path, subscribe)

Verdict: regression (P1), one finding. It is new in cd3a7ad, and the fix is small.

The newest commit fixes both items from the last scan:

  • Worker notices. A worker notice now costs at most 1 + D list calls, which is base's count. The last scan found ⌈L/50⌉, up to 12 at L = 600.
  • Failed owed page. A failed page while going on below a stopped read keeps the pages read before it, and the next read starts at the failing cursor (observation 2 of the last scan).

The new finding: when a named ask turns whole while a tail is owed, the owed pages are read twice in the same read. That can take a notice past base's 1 + D calls.

Idle wakeups: 0/s before and after on main, the renderer and the daemon.

Method.

  • I read this head against the merge-base edf6acdf70b and against 8c3ad84 (the last scan).
  • I ran the committed src/shared loader by itself (tsx, outside the repo) at this head and at 8c3ad84, against the test fixture's host, in two ways:
    • Deterministic call logs for every notice shape.
    • A virtual-time model of the read store. It runs one read at a time per bot, with 500 ms between read starts. Asks are merged up to 100 parts, and waiting() is true once a newer ask is in.
      • Each run is 60 s of notices at 2/s, then 120 s of idle with a whole ask every 15 s (the paired-host refresh).
      • "Base" in the model is the merge-base's read: every loaded page each time, and each page carries the open list.
  • I measured no app timing. Main-process costs are source-proven counts.

Surfaces. perf-surface-detect --pr 45990, rerun on this head, reports the same three surfaces and no others:

  • hot-path bots-items-owner-methods.ts
  • hot-path bots-items-write-support.ts
  • subscribe use-bot-host-read-state.ts:19

Since 8c3ad84 only src/shared/bots/bot-items-list-load.ts and its performance test changed. The two main files, the renderer, the preload bridge and mobile/ are unchanged since then.

Workload terms.

  • O: open items, 600 (also 50 for the per-call table).
  • Closed: 400 Closed items (1,100 for D = 19).
  • D: Closed pages loaded below the first.
  • L: loaded items that link a Dispatch.
  • k: items an item notice names.
  • T: pages still owed below a stop mark.

Finding (P1): a named ask that turns whole while a tail is owed reads the owed pages twice

  • Where. src/shared/bots/bot-items-list-load.ts:47-52 with :115-121. Introduced by cd3a7ad.
  • How it happens.
    1. loadBotItemsList reads the owed cursor from while the ask is still named.
    2. It calls loadAsked, and the new gate there turns the ask whole.
    3. The whole read then pages the owed tail itself, either through readOwedThenMore at :146-148 (first page unchanged) or through readBelow down the full depth (first page moved). The result is read through.
    4. Back in loadBotItemsList, readOwedThenMore(call, value, from, …) runs with the stale from and pages the same tail again.
  • Before this commit. At 8c3ad84 this path was reachable only through an older host's !named fallback, which current hosts never take.
  • Trigger. A worker notice with L > 50·(1 + D), arriving right after a read stopped for a newer ask. That is the loaded state under load: notices come at up to 2/s per bot (one 500 ms window per host). At O = 600, every D ≤ 10 qualifies. An item notice can't trigger it, because k ≤ 100 and a stop needs D ≥ 1.
  • Reproduced (deterministic, O = 600, a whole read stopped after one page below the first):
Case Calls Base 1 + D 8c3ad84
D = 3, T = 2, L = 600, first page moved first, @1051, @1001, @951, @1001, @951 = 6 (2 repeats) 4 14 (12 × uids50 + 2 pages)
D = 3, T = 2, L = 600, first page unchanged first, @1001, @951, @1001, @951 = 5 4 14
Same, with Show more 6 (… @1001, @951, @901) 5 15
D = 3, L = 250 6 4 7
D = 19, T = 18, L = 1,100 38 (18 repeats) 20 50
  • The final list is correct: 200 / 1,000 Closed rows, no duplicate uids. The next whole read is first alone.

  • In the stream model at 500 ms latency (D = 3, L = 600), reads that stop for a newer ask repeat one page each (3 calls per read where 2 suffice). The model is link-bound at 120 calls per minute either way.

  • Cost. Each repeated page is one closedOnly call. On the host that call is:

    • 1 list (counts aggregate plus a 51-row select);
    • 50 summary views;
    • one more fleet-wide worker read on main when a row on that page links a Dispatch (views → readLinkedWorkers → readDispatchWorkers → projectDispatchFleet). Closed items commonly keep their Dispatch link.

    So a notice costs up to 1 + D + T calls and fleet reads, where base paid 1 + D. At D = 19 that is 38 against 20. Rows stay below base (2,500 against 13,000), but the fleet-wide worker reads are the expensive part, and the repeated pages are work no output needs.

  • User impact. Extra main-thread occupancy (sync orchestration SQLite plus the pane projection) during agent bursts while a deep Items list is open. A second show also lands a list that is replaced a moment later. Time per read is unmeasured.

  • Fix (unverified). Decide whole before reading the owed mark, so the outer go-on doesn't run for an ask that became whole:

    const whole = ask.whole || (previous !== null && readsWhole(ask, previous)) // the :117-119 test, lifted out
    const from = previous && !whole ? unread.get(previous) : undefined
    if (!from) return loadAsked(call, previous, { ...ask, whole }, options)

    This also closes the same repeat on the older-host !named fallback at :125-126 (pre-existing and unreachable today).

  • Check that proves it. In bot-items-list-load.performance.test.ts, add a case: load D = 3, stop a whole read with waiting: () => true, then send a worker notice with L > 200. Assert at most 1 + D calls, and that no closedCursor is asked twice. Today it records 6 calls with @1001 and @951 twice.

Per-notice list calls (deterministic, O = 600; rows answered in parentheses)

Notice D Base (1 + D, each carrying the open list) 8c3ad84 This head
Worker, L = 0 0 / 3 / 19 1 / 4 / 20 0 0
Worker, L = 120 0 1 (650) 3 (120) 1 (first, 650)
Worker, L = 120 3 / 19 4 / 20 3 3 (uids50, uids50, uids20)
Worker, L = 600 0 1 12 1
Worker, L = 600 3 4 (2,600) 12 4 (first + 3 closedOnly, 800)
Worker, L = 600 19 20 (13,000) 12 12 (600)
Items, k = 1 0 / 3 / 19 1 / 4 / 20 1 1 (1 row)
Items, k = 60 0 1 2 1 (whole, 650)
Items, k = 60 3 / 19 4 / 20 2 2 (uids50, uids10)
Items, k = 100 0 1 2 1 (whole)
Items, k = 100 3 / 19 4 / 20 2 2
  • Without an owed tail, no notice exceeds 1 + D. With one, see the finding.
  • Every call in every log asked one Closed page with closedOnly: true and closedLimit ≤ 50, or at most 50 uids, or {} for the first page. Zero violations.

Stream model, 2 notices/s for 60 s (O = 600; calls in the stream, then the total including 8 idle refreshes)

Latency Notice Base D = 0 / 3 / 19 8c3ad84 D = 0 / 3 / 19 Head D = 0 / 3 / 19
5 ms Worker L = 120 120 / 480 / 2,400 360 / 360 / 360 120 / 360 / 360
5 ms Worker L = 600 120 / 480 / 2,400 1,440 / 1,440 / 1,440 120 / 480 / 1,440
5 ms Items k = 1 120 / 480 / 2,400 120 120
5 ms Items k = 60 or 100 120 / 480 / 2,400 240 120 / 240 / 240
500 ms any 120 (link-bound); total 128 / 156 / 300 120; total 128–140 120; total 128–140
  • Rows at 5 ms:
    • Base answers 78,000 / 294,000 / 1,446,000 rows for D = 0 / 3 / 19.
    • Head answers 120 rows (k = 1), 14,400 (worker L = 120, D ≥ 3) and 96,000 (worker L = 600, D = 3).
    • Where head reads whole at D = 0, it answers the base row count, but in summary rows.
  • Fleet reads per notice now match base or fall below it. The exception is the owed-tail repeat above.
  • At 500 ms everything is link-bound at 2 calls/s, as at base.

The owed mark and failed pages

  • Set: only by a stop after at least one page (:193-197), or by the new failed-page keep (:207-211).

  • Cleared: by a read through to the depth (readThrough, :224), including a whole read whose first page moved. The failure path at :213 clears it too.

  • A page that fails once (second owed page @951):

    • read 1: uids1, @1001, @951✗
    • read 2: uids1, @951 (resumes at the failing cursor; @1001 isn't read again)
    • later reads: uids1 only
    • a whole read: first only

    At 8c3ad84, read 2 re-read @1001.

  • A page that keeps failing: each later read tries @951 once. There's no retry loop, timer or failure state. Once it succeeds, the mark clears. The mark stays set exactly as long as that page keeps failing, at 1 call per read.

  • Rows: 200 Closed rows held throughout, with no duplicates.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125, unchanged since b43ab06e5d5)

The bot-items queries run on the bots DB worker. Main gets the rows, runs views (link join, worker read, summary), and serializes. Each list is a counts aggregate plus a select, and views reads the rows again by uid.

Call list queries, O = 50 / 600 Rows to main Views Fleet-wide worker read on main
Base, any call (a Closed page also carried the open list) 2 / 7 201 / 1,306 100 / 650 full 1 if any row links a Dispatch
Head, first page ({} + summary) 2 / 7 201 / 1,306 100 / 650 summary 1 if linked
Head, named (uids ≤ 50) 1 / 1 ≤ 100 ≤ 50 1 if linked
Head, Closed page (closedOnly) 1 / 1 101 50 1 if a row on it is linked

The worker read is the same each time it runs: readLinkedWorkers → readWorkers → readDispatchWorkers → projectDispatchFleet. That covers the fleet agent-status evidence over every agent pane on the host, plus listWorkerTerminalResources and getWorkerAttentionFactsForDispatches, all sync SQLite on main. It runs once per call, not once per row.

Per trigger, base → head (400 Closed, so D ≤ 7):

  • Item change, k = 1: 1 + D heavy calls → 1 named call.
    • At O = 600, D = 7: 8 calls, 14 queries, 10,448 rows and 8 fleet reads → 1 call, 1 query, 2 rows, ≤ 1 fleet read.
    • At O = 50: 8 calls and 1,608 rows → 1 call.
  • Item change, k = 60–100:
    • D = 0: 1 whole call, as at base, but with summary rows.
    • D ≥ 1: 2 named calls.
  • Worker notice:
    • L = 0: 0 calls.
    • L ≤ 50·(1 + D): ⌈L/50⌉ named calls.
    • Otherwise whole: 1 call when the first page is unchanged, 1 + D when it moved.
    • Fleet reads ≤ base, except the finding.
    • At O = 50: L ≤ 50, so 1 named call.
  • Show more: 1 call carrying the open list (7 queries, 1,306 rows at O = 600) → 1 closedOnly call (1 query, 101 rows). While a tail is owed: T + 1 calls, no repeat.
  • Whole read (the paired-host refresh every 15–120 s, Retry, return to visible):
    • first page unchanged: 1 + D → 1 call, plus T owed pages once;
    • first page moved: 1 + D heavy calls → 1 heavy and D closedOnly calls.
  • Older paired host (no namesItems or itemUids): notices read whole. The call count is base's, and an unchanged first page costs 1 call. The new gate never asks such a host for uids.
  • Older client, or the phone on a current host: base path, plus the stillOpen filter.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult (a dozen agents calling the CLI every few seconds).
  • Change: changed([record]) groups the held records by bot in O(k). No new store read, IPC or timer.
  • Notices: at most 100 uids per bot per 500 ms notice window; past that, the bot reads whole.
  • Frame rate: same as base. Each frame grows by at most 100 uids per bot.
  • Cost: a notice of 51–100 uids costs 2 named calls at D ≥ 1, and 1 whole call at D = 0.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19)

Store listeners. Each mount of useBotHostRead / useBotHostReadState adds one listener per useSyncExternalStore.

  • itemsRead: 3 per mount. Mounted by BotActivityPanel.tsx:102 and use-bot-group-items.tsx:62 (one per group member; BotGroupItemsPanel.tsx:99).
  • chatTreeRead: 3 per mount. Mounted by BotActivityPanel.tsx:101, BotChatMentionTitle.tsx:22, use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead: 1 per mount. Mounted by BotActivityPanel.tsx:99, BotSettingsRoot.tsx:118, BotLookAroundSection.tsx:72, use-bot-now.ts:24, use-bot-group-items.tsx:68, NativeChatAutomationResultRow.tsx:29, NativeChatAutomationRunBody.tsx:109 and NativeChatWaitRow.tsx:40.
  • No subscription: botItemLastRead reads a snapshot.
  • Own state: useBotChatItems (use-bot-items.ts, the chat-filtered list).
  • Phone: doesn't use this store.

When the store notifies:

  • Notify conditions: only on an identity change or a failure transition (land, bot-host-read-store.ts:118-127).
  • Failed owed page: returns a reused-equal value. When nothing below changed it is the same identity, so no notify.
  • Notifies per read: a read that goes on below can notify twice, show and then the landing. In the finding's path it can notify three times.
  • Idle: 0/s before and after.
  • Under load: at most 2 reads/s per bot, so at most 4–6 notifies/s per bot. Unchanged reads notify no one.

orca:bots-changed listeners:

  • Changed by the PR: use-bot-host-read.ts:109 and use-bot-items.ts:210.
  • Unchanged, desktop: bot-mention-chats-read.ts, bot-tool-checks.ts, ComposioEventsCard.tsx, composio-client.ts, composio-key-client.ts, google-setup-run-store.ts, use-bot-item-view.ts, use-bot-group-transcript.ts, use-bot-tidy-up.ts, bot-access-requests.ts, bot-group-list.ts, bot-host-orca-account.ts, bot-host-per-bot-read.ts, bot-host-refresh.ts, and the raw listener in use-webhook-data.ts.
  • Emitters:
    • main → preload bot-changes-bridge.ts (one parse) → app-lifetime-ipc-bridge.ts → emitBotsChangedWindowEvent (bots-changed-window-event.ts);
    • paired hosts: runtime-client-ipc-bridge.ts:128.
  • Phone (mobile/, no file changed): host-worktree-refresh.ts, use-host-worktree-catalog.ts, use-host-screen-controller.ts, host-bot-refresh.ts, use-host-bot-chat-trees.ts, home-bots-query.ts, use-host-bots.ts, use-bot-access-requests.ts, and the route reads behind use-phone-bot-items, use-phone-bot-chat-tree and use-mobile-bot-tidy-up.
  • Frame rate: 0/s idle before and after. Under load, at most 2/s per host (the 500 ms notice window), as at base. Change-free frames: 0.

Regression classes

  • Re-reading unchanged input: finding. The owed tail is paged twice when a named ask turns whole.
    • Disproved for the steady state: an unchanged whole read is first only.
    • Disproved for the failed-page resume: no page is repeated.
  • Subprocess/RPC per item, hot-path rescans: the last scan's finding is fixed. A worker notice costs ≤ 1 + D calls, with the finding as the exception.
  • Sync SQLite on main: reached through the fleet worker read, once per call. The bot-items queries stay on the DB worker.
  • No-op store write, update published when nothing changed: disproved. reuseEqualJson keeps identity.
  • Fixed-cadence poll, new idle wakeups, eager imports, per-entity state: no matching code. The WeakMap is keyed by value.
  • Unbounded fan-out: none. Calls run one at a time per list.

Six questions

  1. Unused work before the gate: reviewed. The unchanged-first-page gate holds, and the whole/named choice is made before any call.
  2. Ownership: reviewed. The worker evidence is still built once per call, but calls per notice are now ≤ base (except the finding).
  3. Thread: reviewed. The worker join is sync orchestration SQLite plus the pane projection on Electron main.
  4. Growth and progress: reviewed.
    • Every stop advances at least one page.
    • A failed owed page resumes at its cursor.
    • The mark clears on success.
    • There are no loops.
    • Repeats come only from the finding.
  5. Execution host: reviewed for current hosts, older paired hosts and the phone. At 500 ms the stream is link-bound, the same as base. Live paired or SSH timing wasn't measured.
  6. Obsolete work: reviewed. live() and waiting() gate each next page.

Not assessed:

  • the time of one fleet-wide worker read at the reference fleet;
  • live paired or SSH timing.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 671a3a5 (hot-path, subscribe)

Verdict: no regression. The P1 from the scan of cd3a7ad (owed pages read twice when a named ask turned whole) is fixed. In every case I ran, no notice costs more list calls than base's 1 + D (or 2 + D with Show more), no page is read twice in one read, and every call asks one Closed page with closedOnly and closedLimit ≤ 50, at most 50 uids, or {} for the first page.

Idle wakeups: 0/s before and after on main, the renderer and the daemon.

What changed since cd3a7ad. Only src/shared/bots/bot-items-list-load.ts and its performance test.

  • loadBotItemsList (:47-52) now decides named-vs-whole before it goes on below a stopped read. namedCostsMore (:105-121) counts ⌈named/50⌉ + ⌈owed rows/50⌉ against ⌈depth/50⌉ (= 1 + D; depth is at least 50, so this is never 0).
  • When the fallback runs, it returns from loadAsked(whole, pageUnmoved). The outer readOwedThenMore never runs, so the stale from can't page the tail a second time.
  • pageUnmoved reads every loaded page, which is base's 1 + D. That is needed for correctness: at cd3a7ad the whole fallback stopped at an unchanged first page, so a worker change on a Closed row below it was missed. My harness reproduced this (D = 3 or 19, L above the threshold, change on the deepest linked row: stale at cd3a7ad, fresh at head).
  • The old gate inside loadAsked is gone. The only remaining named entry into loadAsked is loadBotItemsList (:54, :56), and both run after the new gate.

Method.

  • I read this head against the merge-base edf6acdf70b and against cd3a7ad.
  • I ran the committed src/shared loader by itself (tsx, outside the repo) at both commits, against the test fixture's host (bot-items-list-load.test-fixture.ts). Three harnesses:
    1. Deterministic call logs. 98 cases per commit: D = 0 / 3 / 19 (400 Closed for D ≤ 3, 1,100 for D = 19), O = 600. Worker notices with L = 0 / 120 / 600 / 1,100 (linked open rows first, then Closed). Item notices with k = 1 / 60 / 100. Each case runs with no stop, with a whole read stopped after one page below the first (first page unchanged), and with that stop plus a moved first page, each with and without Show more. After each notice, the harness sends a k = 1 notice and then a whole read to check the owed mark.
    2. Random sequences. 300 histories × 25 reads (7,500 reads). Each mixes whole, worker and named (1–100 uids) asks, Show more, items closing, link changes, a waiting() that turns true after 1–4 calls on 40% of reads, and a call failure on 10%.
    3. Virtual-time stream model, as in the earlier scans. Notices come at 2/s for 60 s, then 120 s of idle with a whole ask every 15 s. One read at a time per bot, 500 ms between read starts, asks merged up to 100 parts, waiting() true once a newer ask is in. Run at 5 ms and 500 ms RPC latency. In the model, "base" reads every loaded page, each carrying the open list.
  • I measured no app timing. Main-process costs are source-proven counts.

Surfaces. perf-surface-detect --pr 45990, rerun on this head, reports the same three and no others:

  • hot-path src/main/runtime/rpc/methods/bots-items-owner-methods.ts
  • hot-path src/main/runtime/rpc/methods/bots-items-write-support.ts
  • subscribe src/renderer/src/components/bots/use-bot-host-read-state.ts:19

All three are unchanged since b43ab06. So are the preload bridge and mobile/. Their accounting below is restated from source at this head.

Workload terms.

  • O: open items.
  • D: loaded Closed pages below the first.
  • L: loaded items that link a Dispatch.
  • k: uids an item notice names.
  • T: pages still owed below a stop mark.

Per-notice list calls, O = 600 (deterministic; rows answered in parentheses)

"Stop" means the notice follows a whole read that stopped after one page below the first (T = D − 1). The cell shows calls at cd3a7ad → head. Base is 1 + D calls, each carrying the open list: 650 rows per call, so 2,600 at D = 3 and 13,000 at D = 19.

Notice D = 0 (base 1) D = 3 (base 4) D = 3, stop D = 19 (base 20) D = 19, stop
Worker, L = 0 0 → 0 0 → 0 2 → 2 (100) 0 → 0 18 → 18 (900)
Worker, L = 120 1 → 1 (650) 3 → 3 (120) 5 → 4 (800) 3 → 3 (120) 21 → 20 (1,600)
Worker, L = 600 1 → 1 4 → 4 (800) 6, 2 repeats → 4 (800) 12 → 12 (600) 30 → 20 (1,600)
Worker, L = 1,100 (800 / 1,100 loaded) 1 → 1 1, stale → 4 (800) 5, repeats → 4 1, stale → 20 (1,600) 37, repeats → 20
Items, k = 1 1 → 1 (1) 1 → 1 (1) 3 → 3 (101) 1 → 1 19 → 19 (901)
Items, k = 60 1 → 1 (650) 2 → 2 (60) 4 → 4 (160) 2 → 2 20 → 20 (960)
Items, k = 100 1 → 1 (650) 2 → 2 (100) 4 → 4 (200) 2 → 2 20 → 20 (1,000)
  • With Show more, every cell adds exactly 1 call (@next page), against base 2 + D. Head is over that in 0 cases, and cd3a7ad in 12.
  • Moved first page before the notice: the same counts as the stop column.
  • Head totals across all 98 cases:
    • 0 cases over base, 0 repeated cursors, 0 calls outside the shape rules.
    • 0 duplicate uids. Closed rows equal the loaded depth.
    • Every following k = 1 notice is uids1 alone, so the owed mark is clear.
    • Every following whole read is first alone (or first + D when the first page moved since).
  • cd3a7ad totals: 24 cases over base, including the repeats reported in the last scan.
  • Random sequences (7,500 reads): head has 0 reads over 1 + D (+1 with more), 0 repeated cursors, 0 bad calls, 0 duplicate uids and 0 histories with a stuck mark. cd3a7ad has 88 over (up to +7) and 35 repeats. After a final whole pageUnmoved read, both match the host's Closed order exactly.

Why the estimate can't undercount. The named path costs ⌈named/50⌉ calls plus the owed pages that readOwedThenMore reads, ⌈(depth(value) − loaded above start)/50⌉:

  • A named merge that adds newly Closed rows trims at the old depth, which moves the end up and cuts owed rows. When the end passes from, start = end and nothing is owed.
  • Removed Closed rows lower depth and loaded together.
  • With no cursor (rounded depth), the host stops the loop when no rows are left.

So the actual owed count is never above the previous-based estimate. When the estimate is high, the read falls back to whole at base's count.

The owed mark

  • Set only by a stop after at least one page (:211-215) or by a failed owed page (:225-229, at the failing cursor).
  • Cleared by any read through to depth (readThrough, :242). That includes the new whole fallback, which reads all loaded pages and never copies the old mark.
  • A page that keeps failing costs 1 call per read, with no timer or retry loop. It clears on the first success.
  • Proof the mark is never stuck: in 300 random histories with stops and failures, the second quiet k = 1 read was always uids1 alone.

Stream model, 2 notices/s for 60 s

Calls in the stream / total including the 8 idle refreshes.

Latency Notice Base, D = 0 / 3 / 19 Head, D = 0 / 3 / 19 Head max calls per read (cap 1 + D)
5 ms Worker L = 0 119 / 480 / 2,400 0 / 0 / 0 (8 total) 1
5 ms Worker L = 120 120 / 480 / 2,400 120 / 360 / 360 1 / 4 / 20
5 ms Worker L = 600 120 / 480 / 2,400 120 / 480 / 1,440 1 / 4 / 12
5 ms Worker L = 1,100 120 / 480 / 2,400 120 / 480 / 2,400 1 / 4 / 20
5 ms Items k = 1 120 / 480 / 2,400 120 / 120 / 120 1
5 ms Items k = 60 or 100 120 / 480 / 2,400 120 / 240 / 240 1 / 2 / 2
500 ms any 120 (link-bound); total 128 / 156 / 300 120; total 128–150 ≤ 1 + D
  • Over the cap: 0 reads over 1 + D at head in every run, and 0 bad calls. cd3a7ad had one read at 29 calls (cap 20) at 500 ms, worker L = 1,100, D = 19.
  • Rows at 5 ms, D = 19:
    • base 1,446,000;
    • head 120 (k = 1), 14,400 (L = 120), 72,000 (L = 600), 192,000 (L = 1,100, whole every read, as many calls as base).
  • At D = 0 a whole read answers base's row count, in summary rows.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

The bot-items queries run on the bots DB worker. Main receives the rows and runs botItems.views (bot-items-runtime.ts:235). That does the link join and then readLinkedWorkers (bot-items-link-join.ts:58) → readDispatchWorkers → projectDispatchFleet (session-workers-method.ts:119). That is a fleet agent-status projection over every agent pane on the host, plus listWorkerTerminalResources and the attention facts, all sync SQLite on Electron main. It runs once per call when any row in the answer links a Dispatch, not once per row.

Call list queries, O = 50 / 600 Rows to main, O = 50 / 600 Views Fleet worker read on main
Base, every call (a Closed page also carried the open list) 2 / 7 201 / 1,306 100 / 650 full 1 if any row links a Dispatch
Head, first page ({}, summary) 2 / 7 201 / 1,306 100 / 650 summary 1 if linked
Head, named (uids ≤ 50) 1 / 1 ≤ 100 ≤ 50 1 if linked
Head, Closed page (closedOnly) 1 / 1 101 50 1 if a row on it is linked

Per trigger, base → head, 400 Closed (D ≤ 7):

Trigger O = 50 O = 600
Item change, k = 1 1 + D calls (D = 7: 8 calls, 1,608 rows, 8 fleet reads) → 1 call, 1 query, 2 rows, ≤ 1 fleet read 1 + D (D = 7: 8 calls, 14 queries, 10,448 rows, 8 fleet reads) → 1 call, 1 query, 2 rows, ≤ 1 fleet read
Item change, k = 60–100 D = 0: 1 whole call; else 2 named calls (or 1 + D whole if fewer) same
Item change after a stop ⌈k/50⌉ + T, or 1 + D whole if fewer same
Worker notice L = 0: 0; L ≤ 50 → 1 named call L = 0: 0; else min(⌈L/50⌉ + ⌈owed/50⌉, 1 + D); fleet reads ≤ base
Show more 1 call with the open list (2 queries, 201 rows) → 1 closedOnly (1 query, 101 rows); while owed, T + 1, no repeat 7 queries, 1,306 rows → 1 query, 101 rows
Whole read (paired-host refresh every 15–120 s, Retry, return to visible) first page unchanged: 1 + D → 1 (+T owed once); moved: 1 + D heavy → 1 heavy + D closedOnly same
  • Older paired host (notices without itemUids / namesItems): every notice is a whole ask, at base's call count. An unchanged first page costs 1 call. Named asks come only from a current host's notice fields (bot-change-scope.ts:206-207, 243-247), so readNamed's older-host null at :143-144 is unreachable today.
  • Phone on a current host, and older desktop clients: the base path, plus the stillOpen filter.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult (a dozen agents calling the CLI every few seconds).
  • Work: botItems.changed([record]) groups records by bot in O(k). No store read, IPC or timer is added.
  • Notices: the 500 ms notice window carries at most 100 uids per bot. Past that, the bot reads whole.
  • Frame rate: same as base.
  • Reader cost: priced in the table above. The gate keeps a 51–100 uid notice at ≤ 1 + D calls.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19), unchanged since b43ab06

Store listeners (one per useSyncExternalStore per mount):

  • itemsRead: 3 per mount, from BotActivityPanel.tsx:102 and use-bot-group-items.tsx:62 (one per group member).
  • chatTreeRead: 3 per mount, from BotActivityPanel.tsx:101, BotChatMentionTitle.tsx:22, use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead: 1 per mount, from BotActivityPanel.tsx:99, BotSettingsRoot.tsx:118, BotLookAroundSection.tsx:72, use-bot-now.ts:24, use-bot-group-items.tsx:68, NativeChatAutomationResultRow.tsx:29, NativeChatAutomationRunBody.tsx:109 and NativeChatWaitRow.tsx:40.
  • useBotChatItems (use-bot-items.ts) keeps its own state.
  • The phone doesn't use this store.

Notify rate:

  • The store notifies only on an identity change or a failure transition (bot-host-read-store.ts:118-127). reuseEqualJson keeps identity for unchanged reads.
  • At this head a read notifies at most twice (show, then the landing). The whole fallback returns before readOwedThenMore, so the third notify the last scan found is gone.
  • Idle: 0/s before and after.
  • Under load: at most 2 reads/s per bot, so ≤ 4 notifies/s per bot. Unchanged reads: 0.

orca:bots-changed listeners. 27 non-test files reference it at both base and head.

  • Changed by this PR: use-bot-host-read.ts and use-bot-items.ts.
  • Unchanged, desktop: bot-mention-chats-read.ts, bot-tool-checks.ts, ComposioEventsCard.tsx, composio-client.ts, composio-key-client.ts, google-setup-run-store.ts, use-bot-item-view.ts, use-bot-group-transcript.ts, use-bot-tidy-up.ts, BotCloudSignInNotice.tsx, BotGroupReplyPicker.tsx, bot-access-requests.ts, bot-group-list.ts, bot-host-listing.ts, bot-host-orca-account.ts, bot-host-per-bot-read.ts, bot-host-refresh.ts, and the raw listener in use-webhook-data.ts.
  • Emit path: main → preload bot-changes-bridge.ts (one parse) → app-lifetime-ipc-bridge.ts → emitBotsChangedWindowEvent. Paired hosts emit through runtime-client-ipc-bridge.ts:128.
  • Phone (mobile/, unchanged): host-worktree-refresh.ts, use-host-worktree-catalog.ts, use-host-screen-controller.ts, plus the bot routes' host refresh reads.
  • Frame rate: 0/s idle before and after. Under load, at most 2/s per host (the 500 ms window), as at base. Change-free frames: 0.

Regression classes

  • Re-reading unchanged input: the last finding is fixed. Head has 0 repeated cursors in 98 deterministic cases and 7,500 random reads. An unchanged whole read is first alone.
  • Subprocess/RPC per item: disproved. Calls per notice are ≤ 1 + D (+1 with more) in every run.
  • Sync SQLite on main: reached through the fleet worker read, once per call, never more often than at base. The bot-items queries stay on the DB worker.
  • No-op store write, update published when nothing changed: disproved. Identity is kept, and an unchanged read notifies 0 times.
  • Hot-path rescans: namedCostsMore filters the held rows once per read on the renderer (≤ 1,700 rows at D = 19, ≤ 2 reads/s per bot). That is negligible and not repeated per call.
  • Fixed-cadence poll, new idle wakeups, eager imports, per-entity state, unbounded fan-out: no matching code. The WeakMap is keyed by value, and calls run one at a time per list.

Six questions

  1. Unused work before the gate: reviewed. The whole/named decision, including owed pages, is made before any call.
  2. Ownership: reviewed. The worker evidence is built once per call, and calls per trigger are ≤ base.
  3. Thread: reviewed. The worker join is sync orchestration SQLite plus the pane projection on Electron main, once per call.
  4. Growth and progress: reviewed.
    • Every stop advances at least one page.
    • A failed owed page resumes at its cursor.
    • The mark clears on success.
    • There is no loop or timer.
    • No page is repeated.
  5. Execution host: reviewed for current hosts, older paired hosts and the phone. At 500 ms the stream is link-bound, the same as base.
  6. Obsolete work: reviewed. live() and waiting() gate each next page.

Not assessed:

  • the time of one fleet-wide worker read at the reference fleet;
  • live paired or SSH timing.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. A bot's Items list re-read far more than it showed. One item comment made the list re-read every item with full text, plus every Closed page the owner had loaded with Show more, each page carrying the whole open list again: 6 reads of about 1.3 MB per update with 600 open items.

What changes for users. The list looks the same. An item change now reads only that item, as a summary row; Show more reads only the next Closed page; loaded Closed pages are not re-read on updates. A worker's state change reads only the loaded items that link a worker, fifty per call, and reads every loaded page instead when that would take fewer calls; no notice costs more list calls than before. Two small visible differences, both in the PR body: an opened item's description, done-means and close note appear when the item's own read lands, and Show more in one view of a bot (its panel, a group panel) also deepens Closed in its other open views.

Fixed during review (in order): Closed pages folded into the list's one serialized read so pages and updates cannot race; whole reads page a page per call (no answer larger than before, which a paired connection's answer-size cap needs) and stop at an unchanged first page, as before; worker changes read the loaded worker-linked items, picked when the read starts, with no reverse lineage lookup on the host (a design review chose this over host-side naming, which kept missing follow-up and reused-terminal cases); older paired hosts and clients keep working (they never get by-uid reads); a list read to its end keeps room for the pages it took; a failed page below a whole read's first page keeps that fresh page; a failed Show more page keeps a named update and still reports its failure; reads stop once no view shows the list; a whole read that re-reads the loaded Closed pages stops after a page when a newer update is waiting, so that update is not held behind it, and the next read goes on from where it stopped, each page read once; a reply no view shows any more is not compared; named reads go fifty items per call so no answer is larger than a Closed page.

Verified.

  • Regression audit on the final head merged onto main (16caf81): SAFE. Earlier audit rounds found a delayed update behind a long Closed re-read, a comparison of replies no view shows, and Show more failures reported as success; all three are fixed above.
  • Performance scan on the final head: no regression (comment above, verdict=clean): no notice exceeds the base's list calls and no page is read twice, across 98 fixed cases and 7,500 random reads.
  • Typecheck, lint, the changed-code quality gate and the tests the change touches pass on the final head.
  • Benchmark (Linux, production build, hidden window; 60 item comments at one per second; Closed paged to the end), on f09321f; the commits after it change the loader's paging and failure paths, not the item-change path it measures:
base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Main handler time for list reads, per 60 s 1.9 s 0.08 s 10.0 s 0.07 s
Show more to the end (5 pages) 1.0 MB 0.18 MB 6.6 MB 0.18 MB
First list read when the panel opens 205 KB 76 KB 1,323 KB 452 KB

Benchmark: head=f09321f4484df4621041525442a10af8dd30d9b0 gate=PASS build=bf0b4079518cd0b062317c85c15e7796b353c5e8 (the head plus a render-probe commit used only for measuring) listeners=bot Home Items panel (bot list read, Activity tab), main RPC probe on bots.items.owner.list

Deferred (follow-ups, none a regression):

  • The phone app's Items list still re-reads its whole list and every loaded Closed page on each change; the same fix applies there.
  • An opened item re-reads on every items or workers notice of its bot, even when the notice names other items.
  • A worker change reads every loaded worker-linked item, not only those whose worker changed; naming the changed Dispatch in the notice would narrow it.
  • A pull-request or issue link's state on a row no longer refreshes as a side effect of other items changing (it refreshes on a whole read).
  • With two views of one bot open, Next/Prev in one can skip Closed rows that Show more in the other loaded.
  • If an opened item's own read fails, it shows without its description.
  • A page that fails while going on below a stopped read shows no error; the rows stay and are read on the next read.
  • Show more on a list with pages still owed reads those first, so it can take a few calls.
  • With an older paired host under a steady stream of updates, Closed rows below page 2 stay stale until the stream pauses (they then settle).
  • A worker on a deep Closed row that changes while the window is hidden stays stale after it comes back until a notice for it arrives (as before).

… Show more lands; tests bound the drain loop and check whole-read page limits
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. A bot's Items list re-read far more than it showed. One item comment made the list re-read every item with full text, plus every Closed page the owner had loaded with Show more, each page carrying the whole open list again: 6 reads of about 1.3 MB per update with 600 open items.

What changes for users. The list looks the same. An item change now reads only that item, as a summary row; Show more reads only the next Closed page; loaded Closed pages are not re-read on updates. A worker's state change reads only the loaded items that link a worker, fifty per call, and reads every loaded page instead when that would take fewer calls; no notice costs more list calls than before. Two small visible differences, both in the PR body: an opened item's description, done-means and close note appear when the item's own read lands, and Show more in one view of a bot (its panel, a group panel) also deepens Closed in its other open views.

Fixed during review (in order): Closed pages folded into the list's one serialized read so pages and updates cannot race; whole reads page a page per call (no answer larger than before, which a paired connection's answer-size cap needs) and stop at an unchanged first page, as before; worker changes read the loaded worker-linked items, picked when the read starts, with no reverse lineage lookup on the host (a design review chose this over host-side naming, which kept missing follow-up and reused-terminal cases); older paired hosts and clients keep working (they never get by-uid reads); a list read to its end keeps room for the pages it took; a failed page below a whole read's first page keeps that fresh page; a failed Show more page keeps a named update and still reports its failure; reads stop once no view shows the list; a whole read that re-reads the loaded Closed pages stops after a page when a newer update is waiting, so that update is not held behind it, and the next read goes on from where it stopped, each page read once; a reply no view shows any more is not compared; named reads go fifty items per call so no answer is larger than a Closed page.

Verified.

  • Regression audit on the final head merged onto main (6342986): SAFE. Earlier audit rounds found a delayed update behind a long Closed re-read, a comparison of replies no view shows, and Show more failures reported as success; all three are fixed above.
  • Performance scan on 671a3a5 (the final head changes only a chat list's failure flag and tests): no regression (comment above, verdict=clean): no notice exceeds the base's list calls and no page is read twice, across 98 fixed cases and 7,500 random reads.
  • Typecheck, lint, the changed-code quality gate and the tests the change touches pass on the final head.
  • Benchmark on the final head (Linux, production build, hidden window; 60 item comments at one per second; Closed paged to the end; base columns from the same harness on the merge-base):
base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Main handler time for list reads, per 60 s 1.9 s 0.11 s 10.0 s 0.10 s
Show more to the end (5 pages) 1.0 MB 0.17 MB 6.6 MB 0.17 MB
First list read when the panel opens 205 KB 74 KB 1,323 KB 443 KB

Benchmark: head=0a889c97e1476da35108c7c457e5879e31b35b79 gate=PASS build=28bae55675fc0cb5c040f0ca95a140254227a23d (the head plus a render-probe commit used only for measuring) listeners=bot Home Items panel (bot list read, Activity tab), main RPC probe on bots.items.owner.list

Deferred (follow-ups, none a regression):

  • The phone app's Items list still re-reads its whole list and every loaded Closed page on each change; the same fix applies there.
  • An opened item re-reads on every items or workers notice of its bot, even when the notice names other items.
  • A worker change reads every loaded worker-linked item, not only those whose worker changed; naming the changed Dispatch in the notice would narrow it.
  • A pull-request or issue link's state on a row no longer refreshes as a side effect of other items changing (it refreshes on a whole read).
  • With two views of one bot open, Next/Prev in one can skip Closed rows that Show more in the other loaded.
  • If an opened item's own read fails, it shows without its description.
  • A page that fails while going on below a stopped read shows no error; the rows stay and are read on the next read.
  • Show more on a list with pages still owed reads those first, so it can take a few calls.
  • With an older paired host under a steady stream of updates, Closed rows below page 2 stay stale until the stream pauses (they then settle).
  • A worker on a deep Closed row that changes while the window is hidden stays stale after it comes back until a notice for it arrives (as before).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 0a889c9 (hot-path, subscribe)

Verdict: no regression. The newest commit adds no reads, re-renders or wakeups. When a chat-filtered list's read lands but its Show more page fails, the commit lets the next notice read named instead of whole. That can only lower calls. Everything else is unchanged from the clean scan of 671a3a5, and those counts still hold.

Idle wakeups: 0/s before and after on main, the renderer and the daemon.

What changed since 671a3a5

git diff 671a3a5 0a889c9 touches three files:

  • src/renderer/src/components/bots/items/use-bot-items.ts:180-185 (runtime)
  • src/shared/bots/bot-items-list-load.performance.test.ts (test only)
  • src/shared/bots/bot-items-list-load.test.ts (test only)

The merge-base is still edf6acdf70b. The preload bridge, mobile/, the store, the loader and both main-process files are byte-identical to 671a3a5.

The useBotChatItems catch branch for BotReadMoreFailed (use-bot-items.ts:180-185):

  • Trigger: a read that asked for Show more, where the asked part landed and only the extra Closed page failed. The loader throws BotReadMoreFailed with a value it has fully read (bot-items-list-load.ts:95, 152, 170, 233). This happens at most once per Show more click that fails. There is no timer and no retry loop.
  • Population: one per mounted chat-filtered Items list (the chat filter or a group's panel). Owner and lifetime are unchanged: one effect per [hostId, id, chats, attempt].
  • Work:
    • land(error.landed) was already a no-op when not live (:162). Moving it inside if (live) changes nothing. It also already skipped a same-identity value, so it causes at most one setRead.
    • missed = false is a closure local, so it causes no render.
    • setFailed(false) bails out when failed is already false. It commits once only when it clears a visible failure, which is required output.
    • This is the same work the success branch does (:170-175).
  • Bound: ≤ 1 setRead and ≤ 1 setFailed per failed Show more. Before the change it was ≤ 1 setRead. No RPC, listener, timer or IPC is added. finally → start() is unchanged, and it starts a read only when an ask is waiting (:151).
  • Effect on later reads: before this commit, missed kept whatever an earlier failure had set. If it was true, the next notice read whole: 1 + D calls, each carrying the open list. Now botReadLoadAsk(…, hasGoodValue = last && !missed) (bot-host-read-asks.ts:32-38) lets the next item notice read named: ⌈k/50⌉ calls, capped at 1 + D by the loader's gate. That is equal or fewer calls, and the value it builds on is a complete read, so nothing goes stale.

Tests:

  • The drain loop is now capped at 20 pages and must end with no cursor.
  • The performance contract checks that a whole pageUnmoved read of 150 loaded rows asks closedLimit 50 per call below the first.

Neither changes runtime code.

Surfaces

I reran perf-surface-detect --pr 45990 on this head. It reports the same three surfaces and no others:

  • hot-path src/main/runtime/rpc/methods/bots-items-owner-methods.ts
  • hot-path src/main/runtime/rpc/methods/bots-items-write-support.ts
  • subscribe src/renderer/src/components/bots/use-bot-host-read-state.ts:19

All three are unchanged since b43ab06.

Hot path 1: bots.items.owner.list (bots-items-owner-methods.ts:68-125)

  • Where the work runs: the queries run on the bots DB worker. Main runs botItems.views and, when any answered row links a Dispatch, one fleet worker read per call. That read is sync SQLite plus the pane projection on Electron main.
  • Workload terms: O = open items, 400 Closed, D = loaded Closed pages below the first (≤ 7), k = uids an item notice names, L = loaded items that link a Dispatch, T = pages still owed below a stop.
Trigger Base, O = 50 Head, O = 50 Base, O = 600 Head, O = 600
Item change, k = 1 1 + D calls (D = 7: 8 calls, 1,608 rows, ≤ 8 fleet reads) 1 call, 1 query, 2 rows, ≤ 1 fleet read 1 + D (D = 7: 8 calls, 14 queries, 10,448 rows, ≤ 8 fleet reads) 1 call, 1 query, 2 rows, ≤ 1 fleet read
Item change, k = 60–100 1 + D 2 named calls, or 1 + D whole if that is fewer 1 + D same as O = 50
Worker notice 1 + D L = 0: 0 calls; else min(⌈L/50⌉ + owed pages, 1 + D) 1 + D same as O = 50
Show more 1 call carrying the open list (2 queries, 201 rows) 1 closedOnly call (1 query, 101 rows) 7 queries, 1,306 rows 1 query, 101 rows
Whole read (refresh, Retry, return to visible) 1 + D heavy first page unchanged: 1 (+T owed once); moved: 1 heavy + D closedOnly 1 + D heavy same as O = 50

Per call:

Call Queries, O = 50 / 600 Rows to main, O = 50 / 600 Views
Base, every call (each Closed page also carried the open list) 2 / 7 201 / 1,306 full
Head, first page 2 / 7 201 / 1,306 summary
Head, named (≤ 50 uids) 1 / 1 ≤ 100 ≤ 50
Head, closedOnly page 1 / 1 101 50

Benchmark on this head (author-reported, newest status comment):

  • 1 list read per update.
  • List bytes over 60 updates: 0.06 MB at O = 50 and 0.05 MB at O = 600.
  • Main handler time for list reads: 0.11 s and 0.10 s per 60 s.

Hot path 2: owner writes and writeResult (bots-items-owner-methods.ts:199,227,258, bots-items-write-support.ts:78)

  • Trigger: each owner comment, status change or snooze, and each agent write through writeResult.
  • Work: botItems.changed([record]) groups records by bot in O(k). It adds no store read, IPC or timer.
  • Notices: the 500 ms notice window carries ≤ 100 uids per bot. Past that, the bot reads whole.
  • Main-process work per write: the same at O = 50 and O = 600, and the same as base. The reader cost is in the table above.

Subscribe: read.subscribe (use-bot-host-read-state.ts:19)

Store listeners (one per useSyncExternalStore per mount):

  • itemsRead: BotActivityPanel.tsx:102 and use-bot-group-items.tsx:62 (one per group member).
  • chatTreeRead: BotActivityPanel.tsx:101, BotChatMentionTitle.tsx:22, use-bot-now.ts:31 and use-bot-chat-tree.ts:126.
  • activityRead: BotActivityPanel.tsx:99, BotSettingsRoot.tsx:118, BotLookAroundSection.tsx:72, use-bot-now.ts:24, use-bot-group-items.tsx:68, NativeChatAutomationResultRow.tsx:29, NativeChatAutomationRunBody.tsx:109 and NativeChatWaitRow.tsx:40.
  • useBotChatItems keeps its own state, with one onBotsChanged listener per mounted filtered list. That is unchanged by this commit.
  • The phone doesn't use this store.

Notify rate:

  • The store notifies only on an identity change or a failure transition. reuseEqualJson keeps identity for unchanged reads.
  • A read notifies at most twice (show, then the landing).
  • Idle: 0/s before and after.
  • Under load: ≤ 2 reads/s per bot, so ≤ 4 notifies/s per bot. Unchanged reads: 0.

orca:bots-changed listeners:

  • Count: the same set at base and head.
  • Changed by this PR: use-bot-host-read.ts and use-bot-items.ts.
  • Unchanged, desktop: bot-mention-chats-read.ts, bot-tool-checks.ts, ComposioEventsCard.tsx, composio-client.ts, composio-key-client.ts, google-setup-run-store.ts, use-bot-item-view.ts, use-bot-group-transcript.ts, use-bot-tidy-up.ts, BotCloudSignInNotice.tsx, BotGroupReplyPicker.tsx, bot-access-requests.ts, bot-group-list.ts, bot-host-listing.ts, bot-host-orca-account.ts, bot-host-per-bot-read.ts, bot-host-refresh.ts, and the raw listener in use-webhook-data.ts.
  • Emit path: main → preload bot-changes-bridge.ts (one parse) → app-lifetime-ipc-bridge.ts → emitBotsChangedWindowEvent. Paired hosts emit through runtime-client-ipc-bridge.ts:128.
  • Phone (mobile/, unchanged): host-worktree-refresh.ts, use-host-worktree-catalog.ts, use-host-screen-controller.ts, and the bot routes' host refresh reads.
  • Frame rate: 0/s at idle before and after. Under load, ≤ 2/s per host (the 500 ms window), as at base. Change-free frames: 0.

Base vs head, per trigger

Trigger Base Head
Item change 1 + D calls, each with the open list and full bodies k ≤ 50: 1 named call
Worker notice 1 + D 0 calls when nothing loaded links a Dispatch; else ≤ 1 + D
Show more 1 call carrying the open list 1 closedOnly call; a failed Show more now clears missed, so the next notice reads named
Whole read 1 + D heavy 1 when the first page is unchanged

Regression classes

  • No-op store write: disproved. setFailed(false) bails out when already false, and land checks identity.
  • Update published when nothing changed: disproved for the same reasons.
  • Re-reading unchanged input: the commit lowers this. After a failed Show more the next read is named rather than whole.
  • Subprocess or RPC per item: no matching code. Calls stay ≤ 1 + D per notice (+1 with Show more).
  • Fixed-cadence poll, new idle wakeups, per-entity state, unbounded fan-out, eager imports: no matching code in the delta.

Six questions

  1. Unused work before the gate: reviewed. The catch branch does no work before live.
  2. Ownership: reviewed. There is one effect and one listener per mounted filtered list, unchanged.
  3. Thread: reviewed. The delta is renderer state only. The main-process costs are above and unchanged.
  4. Growth and progress: reviewed. There is no loop or timer, and the drain test now bounds pages.
  5. Execution host: reviewed. Current hosts, older paired hosts and the phone are unchanged by the delta.
  6. Obsolete work: reviewed. After unmount, live is false and the branch does nothing.

Method: source read of this head against 671a3a5 and the merge-base edf6acdf70b. I measured no app timing, so the main-process costs above are source-proven counts plus the author-reported benchmark.

Not assessed:

  • the time of one fleet-wide worker read at the reference fleet;
  • live paired or SSH timing.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. A bot's Items list re-read far more than it showed. One item comment made the list re-read every item with full text, plus every Closed page the owner had loaded with Show more, each page carrying the whole open list again: 6 reads of about 1.3 MB per update with 600 open items.

What changes for users. The list looks the same. An item change now reads only that item, as a summary row; Show more reads only the next Closed page; loaded Closed pages are not re-read on updates. A worker's state change reads only the loaded items that link a worker, fifty per call, and reads every loaded page instead when that would take fewer calls; no notice costs more list calls than before. Two small visible differences, both in the PR body: an opened item's description, done-means and close note appear when the item's own read lands, and Show more in one view of a bot (its panel, a group panel) also deepens Closed in its other open views.

Fixed during review (in order): Closed pages folded into the list's one serialized read so pages and updates cannot race; whole reads page a page per call (no answer larger than before, which a paired connection's answer-size cap needs) and stop at an unchanged first page, as before; worker changes read the loaded worker-linked items, picked when the read starts, with no reverse lineage lookup on the host (a design review chose this over host-side naming, which kept missing follow-up and reused-terminal cases); older paired hosts and clients keep working (they never get by-uid reads); a list read to its end keeps room for the pages it took; a failed page below a whole read's first page keeps that fresh page; a failed Show more page keeps a named update and still reports its failure; reads stop once no view shows the list; a whole read that re-reads the loaded Closed pages stops after a page when a newer update is waiting, so that update is not held behind it, and the next read goes on from where it stopped, each page read once; a reply no view shows any more is not compared; named reads go fifty items per call so no answer is larger than a Closed page.

Verified.

  • Regression audit on the final head merged onto main (6342986): SAFE. Earlier audit rounds found a delayed update behind a long Closed re-read, a comparison of replies no view shows, and Show more failures reported as success; all three are fixed above.
  • Performance scan on the final head: no regression (comment above, verdict=clean): no notice exceeds the base's list calls and no page is read twice, across 98 fixed cases and 7,500 random reads.
  • Typecheck, lint, the changed-code quality gate and the tests the change touches pass on the final head.
  • Benchmark on the final head (Linux, production build, hidden window; 60 item comments at one per second; Closed paged to the end; base columns from the same harness on the merge-base):
base, 50 open head, 50 open base, 600 open head, 600 open
List reads per update 6 1 6 1
List bytes over 60 updates 73.8 MB 0.06 MB 475 MB 0.05 MB
Main handler time for list reads, per 60 s 1.9 s 0.11 s 10.0 s 0.10 s
Show more to the end (5 pages) 1.0 MB 0.17 MB 6.6 MB 0.17 MB
First list read when the panel opens 205 KB 74 KB 1,323 KB 443 KB

Benchmark: head=0a889c97e1476da35108c7c457e5879e31b35b79 gate=PASS build=28bae55675fc0cb5c040f0ca95a140254227a23d (the head plus a render-probe commit used only for measuring) listeners=bot Home Items panel (bot list read, Activity tab), main RPC probe on bots.items.owner.list

Deferred (follow-ups, none a regression):

  • The phone app's Items list still re-reads its whole list and every loaded Closed page on each change; the same fix applies there.
  • An opened item re-reads on every items or workers notice of its bot, even when the notice names other items.
  • A worker change reads every loaded worker-linked item, not only those whose worker changed; naming the changed Dispatch in the notice would narrow it.
  • A pull-request or issue link's state on a row no longer refreshes as a side effect of other items changing (it refreshes on a whole read).
  • With two views of one bot open, Next/Prev in one can skip Closed rows that Show more in the other loaded.
  • If an opened item's own read fails, it shows without its description.
  • A page that fails while going on below a stopped read shows no error; the rows stay and are read on the next read.
  • Show more on a list with pages still owed reads those first, so it can take a few calls.
  • With an older paired host under a steady stream of updates, Closed rows below page 2 stay stale until the stream pauses (they then settle).
  • A worker on a deep Closed row that changes while the window is hidden stays stale after it comes back until a notice for it arrives (as before).

@brennanb2025
brennanb2025 merged commit 7f4c81e into main Nov 21, 2026
112 of 115 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