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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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/.

Notes

shipped production is serving it deploy fc37ec0

opened this

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_ROWS events, counted from the table before and after rather than from changes, 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 exactly BATCH_ROWS rows.
  • Cap: asking for BATCH_ROWS * 4 still deletes exactly BATCH_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 10 passed 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 --fix rewrapped the new comments; that is committed.
  • bun x tsc --noEmit is clean.

To try it: bun test ./test/retention-events.test.ts -t "chunk at a time".

🤖 Generated with Claude Code

Closes #15146

commented

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_ROWS events, counted from the table before and after rather than from changes, 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 exactly BATCH_ROWS rows.
  • Cap: asking for BATCH_ROWS * 4 still deletes exactly BATCH_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 10 passed 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 --fix rewrapped the new comments; that is committed.
  • bun x tsc --noEmit is clean.

To try it: bun test ./test/retention-events.test.ts -t "chunk at a time".

🤖 Generated with Claude Code

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs