Skip to content

perf(bots): add partial and covering SQLite indexes for live bot work and item status - #52423

Merged
brennanb2025 merged 7 commits into
mainfrom
perf/add-orchestration-and-bots-sqlite-covering-indexes
Nov 30, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
perf/add-orchestration-and-bots-sqlite-covering-indexes

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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.

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)

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds partial SQLite indexes for live bot work and item status reads without changing the bot-items file version.

  • Needs-you, working, and waiting item checks use status-specific indexes.
  • Live bot-work listings use an index that skips closed rows.

Reviews (4) · Last reviewed commit: "test(bots): explain the SQL liveRows run..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 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.
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.

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: 5aa1c5b3-a566-496b-a9ae-471fa44eb1d5
Commits

Reviewing files that changed from the base of the PR and between c4d5cab and 0503751.

Files selected for processing: 1

  • src/main/bots/bot-sqlite-indexes.performance.test.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.

@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: 10a3c16a-ab14-4405-99a1-5cac933575e6
Commits

Reviewing files that changed from the base of the PR and between 5e1623b and 20fb60b.

Files selected for processing: 9

  • src/main/bots/bot-items-schema.ts
  • src/main/bots/bot-sqlite-indexes.performance.test.ts
  • src/main/bots/bot-work-rows.ts
  • src/main/runtime/orchestration/db/contract-constants.ts
  • src/main/runtime/orchestration/db/dispatch-context/dispatch-links-created-by-any.performance.test.ts
  • src/main/runtime/orchestration/db/schema/bot-dispatch-migration.test.ts
  • src/main/runtime/orchestration/db/schema/create-tables.ts
  • src/main/runtime/orchestration/db/schema/migrate-v53.ts
  • src/main/runtime/orchestration/db/schema/migrate.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.

@brennanb2025
brennanb2025 marked this pull request as draft November 29, 2026 23:29
@brennanb2025
brennanb2025 marked this pull request as ready for review November 30, 2026 00:35
@brennanb2025 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
@brennanb2025

Copy link
Copy Markdown
Contributor

Status: ready for review

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.

@brennanb2025
brennanb2025 merged commit 7ee4c2f into main Nov 30, 2026
59 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.

2 participants