You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(bots): add partial and covering SQLite indexes for live bot work and item status - #52423
People who use bots keep a growing history of finished bot work. Some lookups that run while you work, like "which bot items need me" or "what is this bot working on", read through that whole history to find a few live rows. After this change they jump straight to the live rows, so those lookups stay fast as history grows. Nothing looks different.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$189
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$189
Prod
2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$14
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$14
What Changed
bot-work.sqlite: adds idx_bot_work_live_bot ON bot_work (bot_id) WHERE closed_at IS NULL for live-row reads.
bot-items.sqlite: idx_items_needs_you is replaced by a covering idx_items_needs_you_covering, and partial idx_items_working / idx_items_waiting indexes are added. They run after the migration steps on every open instead of as a new step.
Why
Index-only changes don't need a version: CREATE INDEX IF NOT EXISTS / DROP INDEX IF EXISTS on open converge every file. A new bot-items step would make the file open read-only in the previous release, since that store treats any newer step count as written by a newer Orca.
Linked Issue
N/A (maintainer perf change).
Visual Proof
N/A: storage indexes only, no UI or behavior change.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
bot-sqlite-indexes.performance.test.ts asserts the live-work and item-status query plans use the new indexes and never scan the table, and that a shipped bot-items file gains them without changing its user_version.
Performance
Live bot work and bot item status lookups read only the index instead of the whole table, so their cost no longer grows with closed history. Each open runs a few no-op IF EXISTS / IF NOT EXISTS statements. The first open after upgrade builds the indexes once; these tables are small.
Risk
Level: Low. An older build opening these files keeps reading and writing normally, and its queries use the same partial indexes. Revert is a plain revert; leftover indexes are harmless.
AI Disclosure
Review
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)
No actionable comments were generated in the recent review.
Walkthrough
The bot-work schema adds a partial index for rows with no close time. Bot-item migration runs SQL that replaces the needs-you index and adds indexes for working and waiting items. Tests check query plans, item reads, and that migration preserves schema version 4 and existing item status.
Merge Risk: Minimal · up to 05037
This change adds database indexes so live bot-work and bot-item status lookups stay fast as history grows, without changing behavior. No outstanding issues remain, and the earlier test cleanup and coverage concerns were addressed. It is ready to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "perf(bots): add partial and covering SQLite indexes for live bot work and item status" matches the main change. The changeset adds a partial index on bot_id for live bot_work rows, a coveri…
Description check
The description fills in the template's main sections: ELI5, What Changed, Why, Linked Issue (N/A with a maintainer reason), Visual Proof (N/A with reason), Testing, Performance, Risk with level and r…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "perf(bots): add partial and covering SQLite indexes for live bot work and item status" matches the main change. The changeset adds a partial index on bot_id for live bot_work rows, a covering needs_you index, and partial working/waiting indexes for bot items. The title is specific and concise, so the check passes.
Full details: Description check
Explanation
The description fills in the template's main sections: ELI5, What Changed, Why, Linked Issue (N/A with a maintainer reason), Visual Proof (N/A with reason), Testing, Performance, Risk with level and revert path, and the checklist. The Performance section gives a reason. The description is mostly complete. The AI Disclosure and Review sections are empty, but the template marks AI Disclosure as optional for internal contributors. The Linked Issue reason is given as a maintainer change, which fits the template's special case.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
brennanb2025
changed the title
perf(db): add covering and partial SQLite indexes for orchestration and bots
perf(bots): add partial and covering SQLite indexes for live bot work and item status
Nov 30, 2026
Problem: bot lookups like "items that need me", "what is this bot working on" and "items waiting on a usage limit" read through all closed history to find a few live rows. After this change they read only partial indexes over live rows, so their cost tracks live work, not history.
Changed during review:
The bot-items indexes are applied on every open instead of as a new migration step, so the previous release keeps the file writable.
The orchestration creator-pane index change was dropped: its new column order made the recent-activity query's cost grow with history.
The live bot-work index is keyed by bot only.
Deferred (minor): the upgrade test checks one of the three item indexes by name. Older migration steps still name the replaced needs-you index, which only matters if a future step copies them without IF EXISTS.
Verified: CI green on all platforms. Plan checks at 10k and 100k rows give identical results through the new indexes. Downgrade, reopen and data-safety review found no issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
People who use bots keep a growing history of finished bot work. Some lookups that run while you work, like "which bot items need me" or "what is this bot working on", read through that whole history to find a few live rows. After this change they jump straight to the live rows, so those lookups stay fast as history grows. Nothing looks different.
What Changed
bot-work.sqlite: addsidx_bot_work_live_bot ON bot_work (bot_id) WHERE closed_at IS NULLfor live-row reads.bot-items.sqlite:idx_items_needs_youis replaced by a coveringidx_items_needs_you_covering, and partialidx_items_working/idx_items_waitingindexes are added. They run after the migration steps on every open instead of as a new step.Why
Index-only changes don't need a version:
CREATE INDEX IF NOT EXISTS/DROP INDEX IF EXISTSon open converge every file. A new bot-items step would make the file open read-only in the previous release, since that store treats any newer step count as written by a newer Orca.Linked Issue
N/A (maintainer perf change).
Visual Proof
N/A: storage indexes only, no UI or behavior change.
Testing
bot-sqlite-indexes.performance.test.tsasserts the live-work and item-status query plans use the new indexes and never scan the table, and that a shipped bot-items file gains them without changing itsuser_version.Performance
Live bot work and bot item status lookups read only the index instead of the whole table, so their cost no longer grows with closed history. Each open runs a few no-op
IF EXISTS/IF NOT EXISTSstatements. The first open after upgrade builds the indexes once; these tables are small.Risk
Level: Low. An older build opening these files keeps reading and writing normally, and its queries use the same partial indexes. Revert is a plain revert; leftover indexes are harmless.
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)