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): a read never migrates an older board [C7]

Corey Olsonbc992eff8351
diff --git a/src/api.js b/src/api.js
index 0a5ef02b..a343c7d5 100644
--- a/src/api.js
+++ b/src/api.js
@@ -665,10 +665,13 @@ function withBoard(root, read, isMain) {
const info = repoInfo(root);
loadConfig(info.root);
const file = join(info.commonDir, 'pullboard', 'board.sqlite');
- // A read takes no write lock and runs no migration (#1047); a read that writes after all runs again on a write open.
- const current = store.openCurrentBoardReadOnly(file);
- if (current) try { return read(current, info); } catch (error) { if (!store.writeRefused(error)) throw error; } finally { store.closeBoard(current); }
- const board = store.openBoard(file, undefined, { isMain: isMain !== false && codeIsFromMain() });
+ // A read takes no write lock and never migrates (#1047): main code reads an older board as it is,
+ // branch code keeps the schema guard, and a read that writes after all runs again on a write open.
+ const opened = store.openBoardForRead(file);
+ const main = () => isMain !== false && codeIsFromMain();
+ if (opened && (opened.current || main())) try { return read(opened, info); } catch (error) { if (!store.writeRefused(error)) throw error; } finally { store.closeBoard(opened); }
+ else if (opened) store.closeBoard(opened);
+ const board = store.openBoard(file, undefined, { isMain: main() });
try { return read(board, info); } finally { store.closeBoard(board); }
}
diff --git a/src/board-migrate.js b/src/board-migrate.js
index d5f7e6c0..752bb9b0 100644
--- a/src/board-migrate.js
+++ b/src/board-migrate.js
@@ -102,6 +102,11 @@ export function recordSchemaStamp(db, digest) {
db.exec(`PRAGMA application_id = ${schemaStamp(db, digest)}`);
}
+/** True when a read met a board older than this code: a column or table it does not have yet. */
+export function schemaMissing(error) {
+ return /no such (?:column|table)/u.test(error?.message ?? '');
+}
+
/** True when SQLite refused a write because the board was opened read-only. */
export function writeRefused(error) {
return (error?.errcode & 0xff) === 8;
diff --git a/src/board-read.js b/src/board-read.js
index 0a641abd..4bb31af3 100644
--- a/src/board-read.js
+++ b/src/board-read.js
@@ -1,11 +1,14 @@
/** The read-only board open for commands that only read, kept beside cli.js's withBoard [C7]. */
import * as store from './board.js';
import { withBoard } from './cli.js';
+import { Refused } from './refused.js';
/**
- * withBoard for a command that only reads: the board opens read-only, without the write lock or a
- * migration (#1047). A board that needs a migration, or work that writes after all (a first
- * coordinator registration), runs again through withBoard; SQLite refused the write, so nothing ran twice.
+ * withBoard for a command that only reads: the board opens read-only, without the write lock, and a
+ * read never migrates it (#1047). A board this code has not migrated is read as it is; only the next
+ * command that writes upgrades it. Branch code keeps withBoard's schema guard, which never migrates
+ * a shared board either. Work that writes after all (a first coordinator registration) runs again
+ * through withBoard on a current board; SQLite refused the write, so nothing ran twice.
*
* @template T
* @param {any} ctx
@@ -13,8 +16,14 @@ import { withBoard } from './cli.js';
* @returns {T}
*/
export function withBoardRead(ctx, work) {
- const board = store.openCurrentBoardReadOnly(ctx.file, ctx.clock);
- if (!board) return withBoard(ctx, work);
+ const board = store.openBoardForRead(ctx.file, ctx.clock);
+ if (board && !board.current && !ctx.allowSchemaUpgrade) store.closeBoard(board);
+ if (!board || (!board.current && !ctx.allowSchemaUpgrade)) return withBoard(ctx, work);
try { return withBoard(ctx, work, board); }
- catch (error) { if (store.writeRefused(error)) return withBoard(ctx, work); throw error; }
+ catch (error) {
+ if (board.current && store.writeRefused(error)) return withBoard(ctx, work);
+ if (!store.writeRefused(error) && !store.schemaMissing(error)) throw error;
+ throw new Refused('BOARD_SCHEMA_BEHIND', 'this board was made by an older pullboard and a read never upgrades it',
+ 'run a command that changes the board, such as pullboard shout or pullboard add, which upgrades it; then run this again');
+ }
}
diff --git a/src/board.js b/src/board.js
index eef7181a..ef0baa83 100644
--- a/src/board.js
+++ b/src/board.js
@@ -36,7 +36,7 @@ import {
recordSchemaStamp,
schemaDigest,
} from './board-migrate.js';
-export { writeRefused } from './board-migrate.js';
+export { schemaMissing, writeRefused } from './board-migrate.js';
import {
briefFiles,
briefSections,
@@ -257,17 +257,15 @@ const SCHEMA = `
const SCHEMA_DIGEST = schemaDigest(SCHEMA, EVENT_LOG_VERSION);
/**
- * Open the board for a command that only reads: read-only, with no write lock and no migration, so
- * a writer holding the lock never stalls it (#1047). Null when there is no board yet or it needs a
- * migration, which only a write open runs.
+ * Open an existing board for a command that only reads: read-only, with no write lock and no
+ * migration, so a writer holding the lock never stalls it (#1047). `current` says whether this
+ * code's migration has run on it; only a write open migrates. Null when there is no board yet.
*/
-export function openCurrentBoardReadOnly(file, clock = systemClock) {
+export function openBoardForRead(file, clock = systemClock) {
if (file === ':memory:' || !existsSync(file)) return null;
const db = openBoardReadOnly(file);
- let current = false;
- try { current = boardIsCurrent(db, SCHEMA_DIGEST, SCHEMA_VERSION); }
- finally { if (!current) db.close(); }
- return current ? { db, clock, readOnly: true } : null;
+ try { readEventLogVersion(db); return { db, clock, readOnly: true, current: boardIsCurrent(db, SCHEMA_DIGEST, SCHEMA_VERSION) }; }
+ catch (error) { db.close(); throw error; }
}
/** Open an existing board without migrations, waiting for the same locks as openBoard. */
diff --git a/test/api.test.js b/test/api.test.js
index 249a06b9..f1d9af71 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -229,8 +229,9 @@ test('[A5] board opens upgrade older event logs and refuse future event logs bef
const release = join(box.dir, 'installed-release');
mkdirSync(release);
for (const name of ['bin', 'src', 'package.json']) cpSync(resolve(import.meta.dirname, '..', name), join(release, name), { recursive: true });
- const older = spawnSync(process.execPath, [join(release, 'bin/pullboard.js'), 'status', '--json'], { cwd: box.repo, env: box.env, encoding: 'utf8' });
- assert.equal(older.status, 0, older.stderr);
+ // Only a command that writes upgrades a board; a read never does (#1047).
+ const older = spawnSync(process.execPath, [join(release, 'bin/pullboard.js'), 'shout', 'all', 'board upgrade', '--json'], { cwd: box.repo, env: box.env, encoding: 'utf8' });
+ assert.equal(older.status, 0, older.stderr + older.stdout);
assert.equal(readEventLogVersion(file), String(EVENT_LOG_VERSION), 'an installed release opens an older event log and upgrades its marker in place');
});
@@ -377,7 +378,8 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
const olderInstalled = new DatabaseSync(dbFile);
olderInstalled.exec('ALTER TABLE item DROP COLUMN item_files; PRAGMA user_version = 1');
olderInstalled.close();
- const installedRun = spawnSync(process.execPath, [join(installed, 'bin/pullboard.js'), 'status', '--json'], {
+ // Only a command that writes upgrades a board; a read never does (#1047).
+ const installedRun = spawnSync(process.execPath, [join(installed, 'bin/pullboard.js'), 'shout', 'app', 'board upgrade', '--json'], {
cwd: repo, env: box.env, encoding: 'utf8',
});
assert.equal(installedRun.status, 0, installedRun.stderr + installedRun.stdout);
@@ -390,7 +392,7 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
const older = new DatabaseSync(dbFile);
older.exec('ALTER TABLE item DROP COLUMN item_files; PRAGMA user_version = 1');
older.close();
- const upgraded = runFixture(repo, 'status', '--json');
+ const upgraded = runFixture(repo, 'shout', 'app', 'board upgrade', '--json');
assert.equal(upgraded.status, 0, upgraded.stderr + upgraded.stdout);
const migrated = new DatabaseSync(dbFile, { readOnly: true });
assert.equal(migrated.prepare('PRAGMA user_version').get().user_version, 2);
@@ -451,7 +453,7 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
const olderForHook = new DatabaseSync(dbFile);
olderForHook.exec('ALTER TABLE item DROP COLUMN item_files; PRAGMA user_version = 1');
olderForHook.close();
- const mainFromHook = spawnSync(process.execPath, [join(repo, 'bin/pullboard.js'), 'status', '--json'], {
+ const mainFromHook = spawnSync(process.execPath, [join(repo, 'bin/pullboard.js'), 'shout', 'app', 'board upgrade', '--json'], {
cwd: linked, env: inheritedLinked, encoding: 'utf8',
});
assert.equal(mainFromHook.status, 0, mainFromHook.stderr + mainFromHook.stdout);
diff --git a/test/board-read-lock.test.js b/test/board-read-lock.test.js
index 010d2ba0..fbe98373 100644
--- a/test/board-read-lock.test.js
+++ b/test/board-read-lock.test.js
@@ -1,5 +1,5 @@
/** @pullboard-test-input source-tree */
-/** @pullboard-test-loads src/cli.js src/board.js src/board-migrate.js src/commands/status.js src/commands/show.js */
+/** @pullboard-test-loads src/cli.js src/board.js src/board-migrate.js src/board-read.js src/commands/status.js src/commands/show.js */
/** A read command opens the board read-only, so a writer holding the lock never stalls it [C7]. */
import assert from 'node:assert/strict';
import { performance } from 'node:perf_hooks';
@@ -97,10 +97,18 @@ test('a read answers while a writer holds the lock [C7]', async (t) => {
db.close();
const release = join(box.dir, 'release');
for (const path of ['src', 'bin', 'package.json']) cpSync(resolve(import.meta.dirname, '..', path), join(release, path), { recursive: true });
- const write = runFixtureChild(process.execPath, [join(release, 'bin', 'pullboard.js'), 'add', 'web', 'Footer', '--specs', 'G1', '--criterion', 'renders'],
- { cwd: box.repo, env: box.env, encoding: 'utf8' });
+ const released = (...argv) => runFixtureChild(process.execPath, [join(release, 'bin', 'pullboard.js'), ...argv], { cwd: box.repo, env: box.env, encoding: 'utf8' });
+ /** The board's PRAGMA user_version, read without touching it. */
+ const version = () => {
+ const board = store.openBoardReadOnly(file);
+ try { return board.prepare('PRAGMA user_version').get().user_version; } finally { board.close(); }
+ };
+ // A read on the older board answers as it is and leaves it older, even from code that may migrate.
+ const read = released('status');
+ assert.equal(read.status, 0, read.failure ?? read.stderr);
+ assert.match(read.stdout, /board: 1 open/u);
+ assert.equal(version(), 1, 'status never migrates the board');
+ const write = released('add', 'web', 'Footer', '--specs', 'G1', '--criterion', 'renders');
assert.equal(write.status, 0, write.failure ?? write.stderr);
- const migrated = store.openBoardReadOnly(file);
- try { assert.equal(migrated.prepare('PRAGMA user_version').get().user_version, store.SCHEMA_VERSION); }
- finally { migrated.close(); }
+ assert.equal(version(), store.SCHEMA_VERSION, 'the next write command migrates it');
});