Skip to content

Cache compiled SQL for static thread event reads - #8369

Merged
ymichael merged 1 commit into
mainfrom
slopcop/issue-8362
Nov 30, 2026
Merged

ymichael merged 1 commit into
mainfrom
slopcop/issue-8362

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

Six stable thread-event read paths rebuilt Drizzle queries and prepared synchronous SQLite statements on every invocation instead of using the existing per-connection compiled-query cache. An investigator-authored regression reproduces this on trusted main in two clean checkouts: six preparation-budget failures, with the already-cached sequence lookup passing as a control.

Reproduction and root-cause report

What changed

  • Reuse parameterized statements for singleton high-water marks and accepted-input reads, active-turn branches, earlier-stop branches, no-exclusion provider identity reads, and unfiltered request-row ordering variants.
  • Preserve multi-thread batching, non-empty provider exclusions, and non-null request filters on their existing dynamic paths.
  • Add real-SQLite coverage for fresh results after writes, changing thread bindings, populated branches, and reuse across transactions.
  • Change only the database subsystem: 2 files, 435 changed text lines (346 additions + 89 deletions). No dependency, schema, stored-data, protocol, permission, packaging, or release-process changes.

How you verified

  • Before: pnpm exec turbo run test --filter=@bb/db -- --testNamePattern='reuses compiled.*fresh bindings' fails on six intended preparation assertions and passes the cached control; repeated in a second clean checkout at b0ddaad731565d7e4de68d824120d802fc78f7d5.
  • After: the focused regression passes all seven cases; pnpm exec turbo run test typecheck --filter=@bb/db passes 73 test files, 769 tests, plus typechecking and the query-plan guard.
  • Empty-thread measurement: each affected path drops from 500 preparations for 500 calls to one preparation. Absolute timings are environment-specific; see the report artifacts.
  • git diff --check passes; git diff --numstat origin/main verifies the line count and absence of binary changes.
  • The broad monorepo build encountered pre-existing missing plugin SDK runtime artifacts in the GitHub plugin; the relevant database checks pass.

Fixes #8362

AGENT GENERATED

@ymichael
ymichael merged commit 4aec2b7 into main Nov 30, 2026
35 checks passed
@ymichael
ymichael deleted the slopcop/issue-8362 branch November 30, 2026 20:44
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

Six stable thread-event read paths rebuilt Drizzle queries and prepared
synchronous SQLite statements on every invocation instead of using the
existing per-connection compiled-query cache. An investigator-authored
regression reproduces this on trusted main in two clean checkouts: six
preparation-budget failures, with the already-cached sequence lookup
passing as a control.

[Reproduction and root-cause
report](https://get-bb.github.io/reports/issues/8362.html)

## What changed

- Reuse parameterized statements for singleton high-water marks and
accepted-input reads, active-turn branches, earlier-stop branches,
no-exclusion provider identity reads, and unfiltered request-row
ordering variants.
- Preserve multi-thread batching, non-empty provider exclusions, and
non-null request filters on their existing dynamic paths.
- Add real-SQLite coverage for fresh results after writes, changing
thread bindings, populated branches, and reuse across transactions.
- Change only the database subsystem: **2 files, 435 changed text
lines** (346 additions + 89 deletions). No dependency, schema,
stored-data, protocol, permission, packaging, or release-process
changes.

## How you verified

- Before: `pnpm exec turbo run test --filter=@bb/db --
--testNamePattern='reuses compiled.*fresh bindings'` fails on six
intended preparation assertions and passes the cached control; repeated
in a second clean checkout at
`a8c32288cf24894fbe85cb3a9ca0469c7a997ed6`.
- After: the focused regression passes all seven cases; `pnpm exec turbo
run test typecheck --filter=@bb/db` passes **73 test files, 769 tests**,
plus typechecking and the query-plan guard.
- Empty-thread measurement: each affected path drops from 500
preparations for 500 calls to one preparation. Absolute timings are
environment-specific; see the report artifacts.
- `git diff --check` passes; `git diff --numstat origin/main` verifies
the line count and absence of binary changes.
- The broad monorepo build encountered pre-existing missing plugin SDK
runtime artifacts in the GitHub plugin; the relevant database checks
pass.

Fixes get-bb#8362

> AGENT GENERATED
<!-- slopcop:rule=new-issue-autopilot run=run_6gc7f9pnmx27hm5c
sha=issue-8362 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 turn and event-state queries in events.ts block the main event loop 13×–47× longer by recompiling SQL on every call

2 participants