Skip to content

Cache prepared statements for thread indexing and startup reads - #8451

Merged
ymichael merged 1 commit into
mainfrom
slopcop/issue-8438
Dec 1, 2026
Merged

ymichael merged 1 commit into
mainfrom
slopcop/issue-8438

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

Four fixed-shape thread queries bypassed the existing connection-level prepared-statement cache. Search segment upserts/deletes, startup-context reads, and fork-history checks rebuilt SQL and prepared a SQLite statement on every invocation, including inside transactions.

Report: https://get-bb.github.io/reports/issues/8438.html

What changed

  • Reuse stable prepared builders with parameter bindings for the four queries in packages/db/src/data/threads.ts.
  • Extend the existing prepared-query contract tests for warm calls, changing bindings, connection isolation, direct/transactional writes, timestamps, and rollbacks.
  • Preserve search trimming/deletion behavior and lookup predicates. Leave batch indexing unchanged.
  • Change 215 total text lines across two files (174 additions, 41 deletions), all within the existing database subsystem. No dependency, generated-file, schema, migration, stored-data, protocol, public API, or CLI changes.

How you verified

  • Added the focused regression before the production fix: four failures and eleven passes on unchanged trusted main. Repeated the final regression in two clean detached checkouts at e611693952d5aa8e92162c68628cd3871e58249f; both fail for the expected extra compilation/preparation calls.
  • Before: each warmed read performed ten compilations and ten prepares; each three-cycle write case performed twelve of each. After: zero warmed compiler/preparation calls.
  • pnpm exec turbo run test --filter=@bb/db -- test/prepared-queries.test.ts test/data/thread-search.test.ts test/data/thread-search-ranking.test.ts test/data/events.test.ts test/data/threads.test.ts test/data/thread-lifecycle.test.ts: 188 tests pass across six files.
  • Database typecheck and type-aware lint pass via pnpm exec turbo run test typecheck lint:type-aware --filter=@bb/db.
  • The broader database run has 785 passing assertions but two unrelated queue-suite query-plan guard failures. Both failures repeat against unchanged trusted production code (51 assertions pass); no queue code or allowlist is changed.
  • The baseline full-monorepo build stops because the unrelated GitHub plugin cannot find built Plugin SDK runtime entries. Scoped database test dependencies build successfully.
  • git diff --check passes; numstat confirms 215 changed text lines, two files, and no binaries.

Fixes #8438

AGENT GENERATED

@ymichael
ymichael merged commit 7014a83 into main Dec 1, 2026
35 checks passed
@ymichael
ymichael deleted the slopcop/issue-8438 branch December 1, 2026 05:14
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…bb#8451)

🚨 **SLOP COP** 🚨 · `new-issue-autopilot`

## Human comments

## What was wrong

Four fixed-shape thread queries bypassed the existing connection-level
prepared-statement cache. Search segment upserts/deletes,
startup-context reads, and fork-history checks rebuilt SQL and prepared
a SQLite statement on every invocation, including inside transactions.

Report: https://get-bb.github.io/reports/issues/8438.html

## What changed

- Reuse stable prepared builders with parameter bindings for the four
queries in `packages/db/src/data/threads.ts`.
- Extend the existing prepared-query contract tests for warm calls,
changing bindings, connection isolation, direct/transactional writes,
timestamps, and rollbacks.
- Preserve search trimming/deletion behavior and lookup predicates.
Leave batch indexing unchanged.
- Change 215 total text lines across two files (174 additions, 41
deletions), all within the existing database subsystem. No dependency,
generated-file, schema, migration, stored-data, protocol, public API, or
CLI changes.

## How you verified

- Added the focused regression before the production fix: four failures
and eleven passes on unchanged trusted main. Repeated the final
regression in two clean detached checkouts at
`90ef6dc66ba20ce4d6b7db9d6b974d1e87e6a457`; both fail for the expected
extra compilation/preparation calls.
- Before: each warmed read performed ten compilations and ten prepares;
each three-cycle write case performed twelve of each. After: zero warmed
compiler/preparation calls.
- `pnpm exec turbo run test --filter=@bb/db --
test/prepared-queries.test.ts test/data/thread-search.test.ts
test/data/thread-search-ranking.test.ts test/data/events.test.ts
test/data/threads.test.ts test/data/thread-lifecycle.test.ts`: 188 tests
pass across six files.
- Database typecheck and type-aware lint pass via `pnpm exec turbo run
test typecheck lint:type-aware --filter=@bb/db`.
- The broader database run has 785 passing assertions but two unrelated
queue-suite query-plan guard failures. Both failures repeat against
unchanged trusted production code (51 assertions pass); no queue code or
allowlist is changed.
- The baseline full-monorepo build stops because the unrelated GitHub
plugin cannot find built Plugin SDK runtime entries. Scoped database
test dependencies build successfully.
- `git diff --check` passes; numstat confirms 215 changed text lines,
two files, and no binaries.

Fixes get-bb#8438

> AGENT GENERATED

<!-- slopcop:rule=new-issue-autopilot run=run_cu8mm078mx45zxwl
sha=issue-8438 kind=summary -->

Co-authored-by: SawyerHood <[email protected]>
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.

db: hot-path thread search indexing and startup lookups in threads.ts recompile SQL on every call

2 participants