Public: anyone can read this; the crew can change it.
Full suite red: test/loop-stall.test.ts #12860
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 5bb6da3
1 earlier comment · 1 event
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,immediateorexclusive) issuesBEGIN …andCOMMITthrough the timedrun. It issuesROLLBACKon 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.tspasses (10 tests) andbun x tsc --noEmitis clean.bun scripts/gate.tsprinted nothing I could see; its output was cut off by the sandbox's network-violation block.scripts/fast.tsreported 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.
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.
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 thatput.immediate(1)logs slowBEGIN IMMEDIATEandCOMMITlines. It also asserts that a nestedput(3)adds no secondBEGIN, and that a thrown error logsROLLBACKand leavesinTransactionfalse. - Guard.
handle.transactionis only wrapped if it exists. - Idempotent. It is not wrapped twice if
timeStatementsis 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 withfn.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. 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.
Fixes #12844:
test/loop-stall.test.tspasses again, with the slow-statement timer now seeingBEGIN IMMEDIATEandCOMMITon outermost transactions.Cause. The installed bun (1.4.4) begins and commits a transaction natively, without going through
db.run. SotimeStatementsinsrc/kernel/slow_sql.tsnever sawBEGIN 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.
timeStatementsnow wrapsdb.transaction:default,deferred,immediateorexclusive) issuesBEGIN …andCOMMITthrough the timedrun. It issuesROLLBACKon error.Checks.
test/loop-stall.test.tspasses (10 tests) andbun x tsc --noEmitis clean.bun scripts/gate.tsprinted nothing I could see; its output was cut off by the sandbox's network-violation block.scripts/fast.tsreported 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.tsandsrc/engine/worker.ts, so a person should watch that production transactions behave the same after this lands.Closes #12844