Skip to content

Cache fixed-shape lifecycle database queries - #8366

Merged
ymichael merged 3 commits into
mainfrom
slopcop/issue-8365
Nov 30, 2026
Merged

ymichael merged 3 commits into
mainfrom
slopcop/issue-8365

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

Three synchronous lifecycle reads rebuilt their fixed-shape Drizzle queries and prepared SQLite statements on every call, unlike the existing cached lookups. Two clean checkouts reproduced ten extra SQL compilations and preparations for ten warm reads of each affected query.

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

What changed

Use stable builders, scalar placeholders, and the existing connection-scoped prepared-query cache for host lookup, thread-status lookup, and active-host thread listing. Preserve query filters, projections, signatures, and live database reads. Extend the existing prepared-query regression table and cover parameter rebinding, connection isolation, filtering, and updated database state.

Scope: 157 changed text lines (126 additions + 31 deletions), 3 files, all in @bb/db. No dependencies, generated files, migrations, stored-data changes, public protocols, or public API changes.

How you verified

  • Trusted base: b0ddaad731565d7e4de68d824120d802fc78f7d5.
  • Before repair: pnpm exec turbo run test --filter=@bb/db -- prepared-queries fails the three affected cases in both clean checkouts; five existing cases pass. Each failed case makes ten warm SQL compilations and ten warm SQLite preparations.
  • After repair: the same focused regression passes all eight cases.
  • pnpm exec turbo run test typecheck --filter=@bb/db: 72 test files, 766 tests pass; typecheck passes.
  • Formatting check and git diff --check pass. Text-only diff, below the simple-fix size and file limits.
  • Exact reported timing ratios are not asserted; the regression measures repeated compilation and preparation directly.

Fixes #8365

AGENT GENERATED

@blacksmith-sh

This comment has been minimized.

ymichael and others added 2 commits November 30, 2026 13:57
# Conflicts:
#	packages/db/test/prepared-queries.test.ts
The test compared a cold first disconnect against a warm second one, and
a one-active-thread host against a multi-thread host. Those take
different statement paths, so the counts only matched while every query
on the path was uncached. Run an unmeasured disconnect first and give
the small host two active threads so both measured hosts take the same
path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 3cbb078 into main Nov 30, 2026
35 checks passed
@ymichael
ymichael deleted the slopcop/issue-8365 branch November 30, 2026 22:11
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
🚨 **SLOP COP** 🚨 · `new-issue-autopilot`

## Human comments

## What was wrong

Three synchronous lifecycle reads rebuilt their fixed-shape Drizzle
queries and prepared SQLite statements on every call, unlike the
existing cached lookups. Two clean checkouts reproduced ten extra SQL
compilations and preparations for ten warm reads of each affected query.

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

## What changed

Use stable builders, scalar placeholders, and the existing
connection-scoped prepared-query cache for host lookup, thread-status
lookup, and active-host thread listing. Preserve query filters,
projections, signatures, and live database reads. Extend the existing
prepared-query regression table and cover parameter rebinding,
connection isolation, filtering, and updated database state.

Scope: **157 changed text lines** (126 additions + 31 deletions), **3
files**, all in `@bb/db`. No dependencies, generated files, migrations,
stored-data changes, public protocols, or public API changes.

## How you verified

- Trusted base: `a8c32288cf24894fbe85cb3a9ca0469c7a997ed6`.
- Before repair: `pnpm exec turbo run test --filter=@bb/db --
prepared-queries` fails the three affected cases in both clean
checkouts; five existing cases pass. Each failed case makes ten warm SQL
compilations and ten warm SQLite preparations.
- After repair: the same focused regression passes all eight cases.
- `pnpm exec turbo run test typecheck --filter=@bb/db`: 72 test files,
766 tests pass; typecheck passes.
- Formatting check and `git diff --check` pass. Text-only diff, below
the simple-fix size and file limits.
- Exact reported timing ratios are not asserted; the regression measures
repeated compilation and preparation directly.

Fixes get-bb#8365

> AGENT GENERATED

<!-- slopcop:rule=new-issue-autopilot run=run_zjs0pdu6mx27hkzp
sha=issue-8365 kind=summary -->

---------

Co-authored-by: SawyerHood <[email protected]>
Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[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: getNonDestroyedHost, getThreadStatus, and listActiveHostThreads block the main event loop 7×–116× longer by recompiling SQL on every call

2 participants