Skip to content

Commit bd486b6

Browse files
SunnyShu0925claudevincentkoc
authored
fix(sqlite): skip slow-lock diagnostic when busyTimeoutMs is zero (#115990)
* [AI] fix(sqlite): skip slow-lock diagnostic when busyTimeoutMs is zero busyTimeoutMs: 0 means "do not wait for locks, fail immediately". The slow lock wait threshold should not collapse to 1ms in this case, causing false-positive WARN logs for normal successful transactions. Fixes #115972 Co-Authored-By: Claude <[email protected]> * test(sqlite): add regression tests for busyTimeoutMs: 0 threshold The existing test suite did not cover busyTimeoutMs: 0, which caused false-positive slow-lock warnings for zero-timeout lease transactions. Added: 1. 'does not warn for busyTimeoutMs: 0 with fast transactions' — verifies the regression is fixed (0 → uses 1000ms default threshold) 2. 'still warns for busyTimeoutMs: 0 when crossing 1000ms boundary' — verifies genuinely slow transactions still trigger the diagnostic Both tests pass on the patched code (12/12 total). Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
1 parent 568bfd0 commit bd486b6

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

‎src/infra/sqlite-transaction.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,60 @@ describe("runSqliteImmediateTransactionSync", () => {
263263
);
264264
});
265265

266+
it("does not warn for busyTimeoutMs: 0 with fast successful transactions (regression)", () => {
267+
const logger = { warn: vi.fn() };
268+
let now = 0;
269+
vi.spyOn(Date, "now").mockImplementation(() => {
270+
const value = now;
271+
now += 5; // Fast: 5ms per step, well under the 1000ms default threshold
272+
return value;
273+
});
274+
const db = {
275+
exec() {},
276+
} as unknown as import("node:sqlite").DatabaseSync;
277+
278+
runSqliteImmediateTransactionSync(db, () => "committed", {
279+
busyTimeoutMs: 0,
280+
databaseLabel: "agent.sqlite",
281+
logger,
282+
slowTransactionHoldMs: 0,
283+
});
284+
285+
// busyTimeoutMs: 0 should NOT collapse threshold to 1ms.
286+
// With the default 1000ms threshold, 5ms steps are not slow.
287+
// Before the fix, this would have produced false-positive warnings.
288+
expect(logger.warn).not.toHaveBeenCalledWith(
289+
"slow SQLite transaction lock wait",
290+
expect.anything(),
291+
);
292+
});
293+
294+
it("still warns for busyTimeoutMs: 0 when transaction crosses the default 1000ms threshold", () => {
295+
const logger = { warn: vi.fn() };
296+
let now = 0;
297+
vi.spyOn(Date, "now").mockImplementation(() => {
298+
const value = now;
299+
now += 1_500; // Genuinely slow: 1500ms per step
300+
return value;
301+
});
302+
const db = {
303+
exec() {},
304+
} as unknown as import("node:sqlite").DatabaseSync;
305+
306+
runSqliteImmediateTransactionSync(db, () => "committed", {
307+
busyTimeoutMs: 0,
308+
databaseLabel: "agent.sqlite",
309+
logger,
310+
slowTransactionHoldMs: 0,
311+
});
312+
313+
// The 1000ms default threshold still catches genuinely slow transactions.
314+
expect(logger.warn).toHaveBeenCalledWith(
315+
"slow SQLite transaction lock wait",
316+
expect.anything(),
317+
);
318+
});
319+
266320
it("logs slow successful transaction lock waits", () => {
267321
const logger = { warn: vi.fn() };
268322
let now = 0;

‎src/infra/sqlite-transaction.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ export function isSqliteCorruptionError(error: unknown): boolean {
7979
}
8080

8181
function slowBusyWaitThresholdMs(options: SqliteTransactionOptions | undefined): number {
82-
if (options?.busyTimeoutMs === undefined) {
82+
if (options?.busyTimeoutMs === undefined || options.busyTimeoutMs <= 0) {
8383
return DEFAULT_SLOW_BUSY_WAIT_MS;
8484
}
85-
return Math.min(DEFAULT_SLOW_BUSY_WAIT_MS, Math.max(1, options.busyTimeoutMs));
85+
return Math.min(DEFAULT_SLOW_BUSY_WAIT_MS, options.busyTimeoutMs);
8686
}
8787

8888
function slowTransactionHoldThresholdMs(options: SqliteTransactionOptions | undefined): number {

0 commit comments

Comments
 (0)