Skip to content

perf: narrow Send anyway's event read; memoize Google settings' last-visited bot - #47978

Merged
Jinwoo-H merged 1 commit into
mainfrom
perf/send-anyway-range-read-and-google-bot-memo
Nov 24, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
perf/send-anyway-range-read-and-google-bot-memo

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Two small performance follow-ups. No behavior or UI change.

STA-17703: Send anyway read the item's whole history inside the write

skippedQuestionsOf (src/main/bots/bot-item-waiting-ask-keep.ts) replayed every event of the item to find which lines the answer skips. It now reads the events from the ask onward, plus earlier asks. Earlier asks are still needed: their question lines decide whether a later comment like Earlier question → Yes answers the current ask's first open line by order. A plain id >= ask read would change the skipped lines in that case.

Test: bot-items-open-questions.test.ts adds that case (earlier ask, later ask, a comment answering the earlier one, then Send anyway). It passes with this change and fails with a plain id >= ask read.

STA-17704: Google settings recomputed the last-visited bot on every store update

useLastVisitedBot (use-google-setup-start.tsx) looped over the host's bots in a store selector on every app-store update. The selector is now memoized: it is rebuilt when the host's bot list changes and recomputes only when lastVisitedAtByWorktreeId changes. Same pattern as createBotHomesSelector in bot-catalog.ts.

Checks run locally: the changed test file, tc:web, tc:node, oxlint/oxfmt on the changed files, and the whole-hot-map and layout-writer ratchets.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

Performance

Both changes do less work. Send anyway's write no longer decodes or replays the rows before the ask in JS; SQLite filters them to earlier asks. Measured per Send anyway click (rows returned in parentheses):

item events before after
117 0.13 ms (117) 0.02 ms (7)
1,161 1.18 ms (1,161) 0.17 ms (49)
11,601 12.2 ms (11,601) 2.3 ms (466)

The OR json_extract filter still scans the item's events in SQLite, so cost still grows with the item's history, about 2.3 ms at 11.6k events, once per click. Left as is: a two-step read (events since the ask first, earlier asks only when needed) would cut it further but adds a branch for little gain.

The Google settings selector skips its loop on store updates that leave visit times unchanged.

Risk

Level: Low

The riskiest part is the narrowed read changing which lines Send anyway records as skipped; the added test covers the one case where earlier events still matter. Nothing saved changes shape. Back out with a plain revert.

…e settings' last-visited bot

Send anyway now reads the events from its ask onward plus earlier asks (whose
question lines still decide pairing), instead of the item's whole history inside
the write. Google settings reworks the host's last-visited bot only when visit
times or the host's bot list change, not on every store update.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The skipped-question query now loads events from the specified ask onward and earlier comments with a non-null ask field. A regression test checks that an answer from an earlier question set does not consume questions from a later set. The last-visited bot hook now memoizes its selector and caches the selected bot ID until the visit-map reference changes.

Merge Risk: Minimal · up to 23c93

The change narrows a database read and memoizes a selector without altering behavior. No concrete defects were found. Add the required Performance section to the PR description so the description check passes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names both changes in the PR: narrowing the event read behind Send anyway (STA-17703) and memoizing the Google settings last-visited bot selector (STA-17704). It is specific and uses the con…
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 covers the core content a reviewer needs. It names both changes (STA-17703 and STA-17704), explains the mechanism, and gives the reason for keeping earlier asks in the read. It names t…
Full details: Title check

Explanation

The title names both changes in the PR: narrowing the event read behind Send anyway (STA-17703) and memoizing the Google settings last-visited bot selector (STA-17704). It is specific and uses the conventional perf: prefix. Its length (80 characters, 11 words) is acceptable, though it is somewhat long.

Full details: Description check

Explanation

The description covers the core content a reviewer needs. It names both changes (STA-17703 and STA-17704), explains the mechanism, and gives the reason for keeping earlier asks in the read. It names the regression test and states the local checks run. It includes a Performance section with measurements and a Risk section with a level and a back-out plan. It is missing several template sections: ELI5, a Linked Issue (the template requires one for outside contributors; the two STA tickets are not linked as issues, and the Fixes line is absent), Visual Proof (the template asks for N/A with a reason when there is no UI change, and this is not written), the Testing checkbox list, the Review and Agent skill upstream boundary sections, the AI Disclosure section, and the Checklist. The Performance section's first line does not follow the requested 'None, because ...' form, though the detailed measurements are useful. Because the core content is present, the description is mostly complete.

Finishing Touches

Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a05bf293-2938-4fbf-94dc-cf62f5b0abe9
Commits

Reviewing files that changed from the base of the PR and between 422ec83 and 23c93ae.

Files selected for processing: 3

  • src/main/bots/bot-item-waiting-ask-keep.ts
  • src/main/bots/bot-items-open-questions.test.ts
  • src/renderer/src/components/bots/google/use-google-setup-start.tsx

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

@Jinwoo-H
Jinwoo-H merged commit 4139d30 into main Nov 24, 2026
55 of 56 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