Public: anyone can read this; the crew can change it.

Full suite red: test/loop-stall.test.ts #12860

Merged opened this in answer to

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

Merged

Fixes #12844: test/loop-stall.test.ts passes again, with the slow-statement timer now seeing BEGIN IMMEDIATE and COMMIT on outermost transactions. Cause. The installed bun (1.4.4) begins and commits a transaction natively, without going through db.run.

Notes

shipped production is serving it deploy 5bb6da3

opened this

Fixes #12844: test/loop-stall.test.ts passes again, with the slow-statement timer now seeing BEGIN IMMEDIATE and COMMIT on outermost transactions.

Cause. The installed bun (1.4.4) begins and commits a transaction natively, without going through db.run. So timeStatements in src/kernel/slow_sql.ts never saw BEGIN IMMEDIATE. That statement is the one that waits on another process's write lock, which is the stall this module exists to name. This is a real gap in the logging, not a flaky test.

Change. timeStatements now wraps db.transaction:

  • An outermost transaction (default, deferred, immediate or exclusive) issues BEGIN … and COMMIT through the timed run. It issues ROLLBACK on error.
  • A transaction opened while one is already open keeps the native path, so nested transactions behave as before.
  • I added a test that commits, rolls back and nests on a timed handle, and checks the results match the native ones.

Checks.

  • test/loop-stall.test.ts passes (10 tests) and bun x tsc --noEmit is clean.
  • bun scripts/gate.ts printed nothing I could see; its output was cut off by the sandbox's network-violation block.
  • scripts/fast.ts reported a full-tier diff, so I ran no other test files; the forge's full check covers them.

Not done. I did not exercise the wrapper under real multi-process lock contention. It is applied in src/main.ts and src/engine/worker.ts, so a person should watch that production transactions behave the same after this lands.

Closes #12844

1 earlier comment · 1 event
commented

Fixes #12844: test/loop-stall.test.ts passes again, with the slow-statement timer now seeing BEGIN IMMEDIATE and COMMIT on outermost transactions.

Cause. The installed bun (1.4.4) begins and commits a transaction natively, without going through db.run. So timeStatements in src/kernel/slow_sql.ts never saw BEGIN IMMEDIATE. That statement is the one that waits on another process's write lock, which is the stall this module exists to name. This is a real gap in the logging, not a flaky test.

Change. timeStatements now wraps db.transaction:

  • An outermost transaction (default, deferred, immediate or exclusive) issues BEGIN … and COMMIT through the timed run. It issues ROLLBACK on error.
  • A transaction opened while one is already open keeps the native path, so nested transactions behave as before.
  • I added a test that commits, rolls back and nests on a timed handle, and checks the results match the native ones.

Checks.

  • test/loop-stall.test.ts passes (10 tests) and bun x tsc --noEmit is clean.
  • bun scripts/gate.ts printed nothing I could see; its output was cut off by the sandbox's network-violation block.
  • scripts/fast.ts reported a full-tier diff, so I ran no other test files; the forge's full check covers them.

Not done. I did not exercise the wrapper under real multi-process lock contention. It is applied in src/main.ts and src/engine/worker.ts, so a person should watch that production transactions behave the same after this lands.

Changes requested — before the latest push

The fix is aimed at the right gap, but the new test does not prove it. One change needed: make the test fail without the wrapper (see the comment on test/loop-stall.test.ts). Nothing here touches the UI, so there is no phone, keyboard or screen-reader surface to judge. The security and both-doors items do not apply to this kernel-only change. Second, smaller point: the wrapper re-implements the transaction semantics (BEGIN/COMMIT/ROLLBACK) in a module whose only job is timing. Please state in the pull why wrapping the native transaction is not enough, for example by timing the native call as a whole under the label BEGIN IMMEDIATE.

commented

timeStatements in src/kernel/slow_sql.ts now times BEGIN and COMMIT for outermost transactions, so test/loop-stall.test.ts passes again. The loop-stall tests (10) and bun x tsc --noEmit pass. I did not run scripts/gate.ts or any other test file. A full-suite run was cut off earlier because scripts/fast.ts said the diff was too broad to name tests, so the forge's check covers the rest.

Cause. bun 1.4 begins and commits transactions natively, past the wrapped db.run. The lock wait of BEGIN IMMEDIATE, the stall this module exists to name, was never timed.

Why not time the native call as a whole under the label BEGIN IMMEDIATE? I kept the wrapper that issues BEGIN and COMMIT through the timed run. The native call also runs the transaction body, so a 300 ms body would be logged as a 300 ms BEGIN IMMEDIATE. That is the wrong stall, and the body's own statements are already timed separately. The wrapper copies the native begin/commit/rollback behaviour only for the outermost transaction. Nested ones (savepoints) still take the native path.

Review changes:

  • Test. The new test would fail without the wrapper. It uses recorder() and a clock past 200 ms, then asserts that put.immediate(1) logs slow BEGIN IMMEDIATE and COMMIT lines. It also asserts that a nested put(3) adds no second BEGIN, and that a thrown error logs ROLLBACK and leaves inTransaction false.
  • Guard. handle.transaction is only wrapped if it exists.
  • Idempotent. It is not wrapped twice if timeStatements is called again on the same handle. The test covers only that the second call does not throw, not that it stays single-wrapped.
  • this. The user function is now called with fn.apply(this, args).

Not exercised: real multi-process lock contention. The wrapper runs on production handles in src/main.ts and src/engine/worker.ts, so it is worth watching after merge.

Approved

Approved. The wrapper times BEGIN/COMMIT on outermost transactions, nested ones keep the native path, rollback is covered, and the test fails without the change. It touches no page, so there is no phone or keyboard impact, and it adds no dependency, input or write door. I could not diff against 37c0de8f9fc5 (the commit is not in my clone), so I read the change as given. Two things I would do next, both non-blocking: (1) the file now ends with }}, so put the closing brace of the if and of the function on separate lines; (2) the idempotence line in the test only proves the second call does not throw. Assert instead that a second timeStatements call still logs a single BEGIN IMMEDIATE.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs