Public: anyone can read this; the crew can change it.
The 5,000-row prune test proves the write lock is short without a wall-clock bound that fails under load #15149
Check · Review · Land · Live done — Landed and live in production.
The 5,000-row prune test in test/retention-events.test.ts no longer depends on a strict lockMs < 50 stopwatch, which failed at 63 ms on a busy shard (#15145). It now proves the write lock is short by checking what pruneEvents actually does in each transaction. Only the test changed; nothing in src/.
shipped production is serving it deploy fc37ec0
The 5,000-row prune test in test/retention-events.test.ts no longer depends on a strict lockMs < 50 stopwatch, which failed at 63 ms on a busy shard (#15145). It now proves the write lock is short by checking what pruneEvents actually does in each transaction. Only the test changed; nothing in src/.
During the batch the test wraps db.transaction and db.query, and checks for every transaction:
- Rows: it removes at most
CHUNK_ROWSevents, counted from the table before and after rather than fromchanges, which also counts the webhook deliveries that cascade with them. - Statements: it runs exactly one
DELETE. - Lock: it starts outside any other transaction and leaves none open, so the lock is let go between chunks.
- Totals: the batch makes
ceil(BATCH_ROWS / CHUNK_ROWS)transactions that together delete exactlyBATCH_ROWSrows. - Cap: asking for
BATCH_ROWS * 4still deletes exactlyBATCH_ROWS.
One timing check stays, only to catch a chunk getting badly slow: the best of three batches must be under 250 ms. A comment says why: delays from load only ever add time, so the fastest run drops them.
I checked that the guard fails for real regressions by changing the code temporarily, then restoring it:
- One 5,000-row transaction per batch: the test fails, expecting 250 transactions and getting 1.
- A batch cap ten times higher: the test fails, expecting 5000 rows deleted and getting 14900.
How I ran it:
bun test ./test/retention-events.test.ts --rerun-each 10passed 110 of 110 while a second copy of the same run went on beside it. That neighbour was this suite again, not a different one.bun scripts/gate.ts --fixrewrapped the new comments; that is committed.bun x tsc --noEmitis clean.
To try it: bun test ./test/retention-events.test.ts -t "chunk at a time".
🤖 Generated with Claude Code
Test-only change. The test now proves the lock is short by what pruneEvents does: one DELETE per transaction, at most CHUNK_ROWS rows each, ceil(BATCH_ROWS/CHUNK_ROWS) transactions, lock released between them, and a cap check at BATCH_ROWS*4. The one clock check left is best-of-three against a 250 ms ceiling, with the reason in a comment. Nothing in src/ changed, the wrappers are restored in a finally, and no new dependency or docs are needed. I read the diff against src/system/retention_events.ts and did not run the suite.
The 5,000-row prune test in
test/retention-events.test.tsno longer depends on a strictlockMs < 50stopwatch, which failed at 63 ms on a busy shard (#15145). It now proves the write lock is short by checking whatpruneEventsactually does in each transaction. Only the test changed; nothing insrc/.During the batch the test wraps
db.transactionanddb.query, and checks for every transaction:CHUNK_ROWSevents, counted from the table before and after rather than fromchanges, which also counts the webhook deliveries that cascade with them.DELETE.ceil(BATCH_ROWS / CHUNK_ROWS)transactions that together delete exactlyBATCH_ROWSrows.BATCH_ROWS * 4still deletes exactlyBATCH_ROWS.One timing check stays, only to catch a chunk getting badly slow: the best of three batches must be under 250 ms. A comment says why: delays from load only ever add time, so the fastest run drops them.
I checked that the guard fails for real regressions by changing the code temporarily, then restoring it:
How I ran it:
bun test ./test/retention-events.test.ts --rerun-each 10passed 110 of 110 while a second copy of the same run went on beside it. That neighbour was this suite again, not a different one.bun scripts/gate.ts --fixrewrapped the new comments; that is committed.bun x tsc --noEmitis clean.To try it:
bun test ./test/retention-events.test.ts -t "chunk at a time".🤖 Generated with Claude Code
Closes #15146