Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(board): name exhausted lock waits [C7,B3]

Corey Olson6459de2dd240
diff --cc src/approved-rows.js
index 4bebc72e,da30b922..3d468fb6
--- a/src/approved-rows.js
+++ b/src/approved-rows.js
@@@ -2,10 -2,9 +2,9 @@@
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
- import { DatabaseSync } from 'node:sqlite';
import { spawnSync } from 'node:child_process';
import { parseSpec, SIGNOFFS_FILE } from './spec.js';
- import { rowDecisions } from './board.js';
-import { openBoardReadOnly, rowDecisions } from './board.js';
++import { boardBusyError, openBoardReadOnly, rowDecisions } from './board.js';
import { hasSignerFile, verifySignedRecords } from './signature.js';
import { Refused } from './refused.js';
import { CONFIG_FILE, configFromSource } from './config.js';
@@@ -38,9 -37,9 +37,11 @@@ function rowSourceAt(root, revision, fi
/** Read the shared decision index without opening the board's migrator or changing its evidence. */
function boardApprovals(file) {
if (!file || !existsSync(file)) return [];
- const db = new DatabaseSync(file, { readOnly: true });
- const db = openBoardReadOnly(file);
-- try { return rowDecisions({ db }); }
-- finally { db.close(); }
++ const startedAt = Date.now();
++ let db;
++ try { db = openBoardReadOnly(file); return rowDecisions({ db }); }
++ catch (error) { throw boardBusyError(file, startedAt, error); }
++ finally { db?.close(); }
}
/** Verify staged receipts using staged trust files anchored to the already committed opt-in. */
diff --cc src/board.js
index b79770fa,1a71583b..1f214cde
--- a/src/board.js
+++ b/src/board.js
@@@ -152,6 -135,18 +152,20 @@@ const SCHEMA =
);
`;
+ /** Open an existing board without migrations, waiting for the same locks as openBoard. */
+ export function openBoardReadOnly(file) {
- const db = new DatabaseSync(file, { readOnly: true });
++ const startedAt = Date.now();
++ let db;
+ try {
- db.exec('PRAGMA busy_timeout = 10000');
++ db = new DatabaseSync(file, { readOnly: true });
++ db.exec(`PRAGMA busy_timeout = ${BOARD_BUSY_TIMEOUT_MS}`);
+ return db;
+ } catch (error) {
- db.close();
- throw error;
++ try { db?.close(); } catch {}
++ throw boardBusyError(file, startedAt, error);
+ }
+ }
+
/**
* Open, or create, the board at `file`. Tests pass `:memory:`.
*
@@@ -168,17 -163,12 +182,16 @@@ export function openBoard(file, clock
let boardVersion = 0;
let logVersion = 0;
if (existsSync(file)) {
- const current = openBoardReadOnly(file);
+ const startedAt = Date.now();
+ let current;
try {
- current = new DatabaseSync(file, { readOnly: true });
- current.exec(`PRAGMA busy_timeout = ${BOARD_BUSY_TIMEOUT_MS}`);
++ current = openBoardReadOnly(file);
boardVersion = current.prepare('PRAGMA user_version').get().user_version;
logVersion = readEventLogVersion(current);
+ } catch (error) {
+ throw boardBusyError(file, startedAt, error);
} finally {
- current.close();
+ current?.close();
}
if (SCHEMA_VERSION > boardVersion) {
throw new Refused(
diff --cc src/cli.js
index dafdd966,3a484167..9794ca2d
--- a/src/cli.js
+++ b/src/cli.js
@@@ -2739,18 -2738,14 +2738,17 @@@ async function readStdin(stdin)
return Buffer.concat(chunks).toString('utf8');
}
- /** Read hook identity and landing facts without migrating the shared board from newer source. */
+ /** Wait up to the board's shared busy timeout while reading hook facts, without migrating its schema. */
function hookRead(ctx, read) {
if (!existsSync(ctx.file)) return null;
- const db = store.openBoardReadOnly(ctx.file);
+ const startedAt = Date.now();
+ let db;
try {
- db = new DatabaseSync(ctx.file, { readOnly: true });
- db.exec(`PRAGMA busy_timeout = ${store.BOARD_BUSY_TIMEOUT_MS}`);
++ db = store.openBoardReadOnly(ctx.file);
return read({ db, clock: ctx.clock });
- }
- finally { db.close(); }
+ } catch (error) {
+ throw store.boardBusyError(ctx.file, startedAt, error);
+ } finally { db?.close(); }
}
/**
diff --cc src/doctor.js
index cc2b035d,8a46e64e..bb643db7
--- a/src/doctor.js
+++ b/src/doctor.js
@@@ -6,8 -6,7 +6,7 @@@ import { tryGit } from './git.js'
import { checkAtCommit, submissionPaths, dependencySnapshots } from './trusted-policy.js';
import { BLANKS, STATES, storeTriggers } from './machine.js';
- import { EVENT_LOG_VERSION, readEventLogVersion, SCHEMA_VERSION } from './board.js';
-import { EVENT_LOG_VERSION, openBoardReadOnly, readEventLogVersion, SCHEMA_VERSION } from './board.js';
++import { boardBusyError, EVENT_LOG_VERSION, openBoardReadOnly, readEventLogVersion, SCHEMA_VERSION } from './board.js';
import { staleFrozenItems, staleItemFinding } from './approved-rows.js';
import { loadSpec } from './spec.js';
import { loadDoctrine } from './doctrine.js';
@@@ -35,8 -34,8 +34,10 @@@ export function doctrineProblems(root,
*/
export function doctorProblems(file, root, tryGit, config, { isMain = true } = {}) {
if (!existsSync(file)) return [finding('BOARD_MISSING', 'board file is missing', 'run pullboard status to create a new board')];
- const db = new DatabaseSync(file, { readOnly: true });
- const db = openBoardReadOnly(file);
++ const startedAt = Date.now();
++ let db;
try {
++ db = openBoardReadOnly(file);
const schemaProblems = versionProblems(db, isMain);
if (schemaProblems.length) return schemaProblems;
const eventProblems = [];
@@@ -65,8 -64,8 +66,10 @@@
...(layout.itemAudit ? submissionProblems(db, root) : []),
...(layout.itemAudit && config ? staleFrozenItems(db.prepare('SELECT * FROM item ORDER BY item_id').all(), loadSpec(root, config).rows, loadDoctrine(root, config).rows).map(staleItemFinding) : []),
];
++ } catch (error) {
++ throw boardBusyError(file, startedAt, error);
} finally {
-- db.close();
++ db?.close();
}
}