Skip to content

Cache prepared statements for event persistence and pruning - #8449

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

ymichael merged 1 commit into
mainfrom
slopcop/issue-8437

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

Fixed-shape event and pruning writes bypassed the database's per-connection prepared-query cache. Each persisted event synchronously prepared its insert and pruning marker again, even on warm connections and across successive transactions. The verified reproduction report records matching failures in two clean trusted-main checkouts.

What changed

  • Cache the strict and duplicate-tolerant event insert variants, binding every event field at execution time.
  • Cache pending and policy-specific pruning inserts while retaining revision increments and transaction-shared statement reuse.
  • Add four real-database regression cases covering different threads and payloads, duplicate imports, and root/transaction connections.

The change stays in packages/db: 3 files, 215 changed text lines (189 additions + 26 deletions). No dependency, generated file, migration, stored-data rewrite, or public protocol/API change.

How you verified

  • Before the fix, all four new regression cases fail on unchanged trusted main; a second clean checkout reproduces identical warm prepare counts of 12 / 18 / 6 / 6.
  • After the fix, all four cases pass with zero warm prepares, while checking stored payloads, duplicate suppression, and pruning revisions.
  • pnpm exec turbo run test --filter=@bb/db -- --run test/data/event-write-preparation.test.ts test/data/events.test.ts test/data/thread-pruning.test.ts test/data/retained-event-outputs.test.ts test/data/resolved-item-pruning-resume.test.ts: 163 tests passed.
  • pnpm exec turbo run typecheck --filter=@bb/db and git diff --check origin/main: passed.
  • Broad database suite: 785 tests passed, but the queued-message suite's existing correlated-subquery query-plan guard fails. The same guard failure reproduces on unchanged main in the second checkout, with all 47 queued-message tests passing. It is not changed or suppressed here.
  • The broad build encounters an existing GitHub plugin SDK-dist build-order failure. Scoped database dependency build, typecheck, and relevant tests succeed.

Fixes #8437

AGENT GENERATED

@ymichael
ymichael merged commit f631fe1 into main Dec 1, 2026
35 checks passed
@ymichael
ymichael deleted the slopcop/issue-8437 branch December 1, 2026 05:15
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

Fixed-shape event and pruning writes bypassed the database's
per-connection prepared-query cache. Each persisted event synchronously
prepared its insert and pruning marker again, even on warm connections
and across successive transactions. The [verified reproduction
report](https://get-bb.github.io/reports/issues/8437.html) records
matching failures in two clean trusted-main checkouts.

## What changed

- Cache the strict and duplicate-tolerant event insert variants, binding
every event field at execution time.
- Cache pending and policy-specific pruning inserts while retaining
revision increments and transaction-shared statement reuse.
- Add four real-database regression cases covering different threads and
payloads, duplicate imports, and root/transaction connections.

The change stays in `packages/db`: **3 files, 215 changed text lines
(189 additions + 26 deletions)**. No dependency, generated file,
migration, stored-data rewrite, or public protocol/API change.

## How you verified

- Before the fix, all four new regression cases fail on unchanged
trusted main; a second clean checkout reproduces identical warm prepare
counts of **12 / 18 / 6 / 6**.
- After the fix, all four cases pass with **zero** warm prepares, while
checking stored payloads, duplicate suppression, and pruning revisions.
- `pnpm exec turbo run test --filter=@bb/db -- --run
test/data/event-write-preparation.test.ts test/data/events.test.ts
test/data/thread-pruning.test.ts
test/data/retained-event-outputs.test.ts
test/data/resolved-item-pruning-resume.test.ts`: **163 tests passed**.
- `pnpm exec turbo run typecheck --filter=@bb/db` and `git diff --check
origin/main`: passed.
- Broad database suite: **785 tests passed**, but the queued-message
suite's existing correlated-subquery query-plan guard fails. The same
guard failure reproduces on unchanged main in the second checkout, with
all 47 queued-message tests passing. It is not changed or suppressed
here.
- The broad build encounters an existing GitHub plugin SDK-dist
build-order failure. Scoped database dependency build, typecheck, and
relevant tests succeed.

Fixes get-bb#8437

> AGENT GENERATED
<!-- slopcop:rule=new-issue-autopilot run=run_lrnsnylkmx45zyay
sha=issue-8437 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: insertStoredEventRow and markThreadPruningWork re-prepare static SQL on every single event write

2 participants