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(resume): check board readiness without a write lock [I1,L3,P4]

Corey Olson3a8bd96dee01
diff --git a/src/board-access.js b/src/board-access.js
index c6bbd810..5709ffe6 100644
--- a/src/board-access.js
+++ b/src/board-access.js
@@ -1,6 +1,8 @@
import { boardWriteHolderText } from './board-write-lock.js';
/** Name a board this process cannot write, such as one inside a read-only agent sandbox [I1,P4]. */
-import { dirname } from 'node:path';
+import { randomUUID } from 'node:crypto';
+import { closeSync, openSync, unlinkSync } from 'node:fs';
+import { dirname, join } from 'node:path';
import { AGENT_SHELL_MARKERS } from './person.js';
import { Refused } from './refused.js';
@@ -31,6 +33,23 @@ export function boardNotWritable(file, error, environment = process.env) {
`Cannot write the board in "${folder}". Give the agent write access to that folder, the repo's .git/pullboard, or run the command outside the sandbox.`);
}
+/**
+ * Check the write capability an agent needs after resume, without changing board data or taking its SQLite lock.
+ * Opening the file for writing and creating one temporary sibling exercise actual sandbox permissions, including
+ * journal creation; mode bits or access() alone cannot establish that capability. The sibling is removed immediately.
+ */
+export function requireBoardWriteAccess(file) {
+ try {
+ const board = openSync(file, 'r+');
+ closeSync(board);
+ const probe = join(dirname(file), `.write-access-${randomUUID()}`);
+ const handle = openSync(probe, 'wx', 0o600);
+ try { closeSync(handle); } finally { unlinkSync(probe); }
+ } catch (error) {
+ throw boardNotWritable(file, error);
+ }
+}
+
/**
* Replace SQLite's bare lock error with the board path and elapsed wait when the wait expires.
*
diff --git a/src/commands/resume.js b/src/commands/resume.js
index c2443fb2..85c3e3c4 100644
--- a/src/commands/resume.js
+++ b/src/commands/resume.js
@@ -12,6 +12,7 @@ import {
backgroundViewLine,
} from '../background-view.js';
import * as store from '../board.js';
+import { requireBoardWriteAccess } from '../board-access.js';
import {
briefFiles,
} from '../brief.js';
@@ -140,6 +141,7 @@ export async function resumeHere(io, view, diagnostics = false, { json = false }
const ordered = keylessBookkeeping(sendOrdered);
const initialBaseline = withBoardRead(ctx, board => {
whoAmI(ctx, board);
+ requireBoardWriteAccess(ctx.file);
return initialSpecApprovalBaseline(ctx, board, 'recordHealthFindings');
});
if (initialBaseline) {
diff --git a/test/machine-home.test.js b/test/machine-home.test.js
index eb987e04..dc37e045 100644
--- a/test/machine-home.test.js
+++ b/test/machine-home.test.js
@@ -1,7 +1,7 @@
/** @pullboard-test-input source-tree */
/** Real machine-storage permission refusals preserve the shared queue location [I1,C7,Q4]. */
import assert from 'node:assert/strict';
-import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { appendFileSync, chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { after, test } from 'node:test';
import { createE2eHelpers } from './e2e-helpers.js';
@@ -142,3 +142,24 @@ test('a Codex agent that cannot write the board is told the Codex step that gran
assert.equal(error.next, `restart Codex with that folder writable: codex --add-dir '${folder}'; to keep it in ~/.codex/config.toml, a permission profile takes ${JSON.stringify(folder)} = "write" in its [permissions.<active-profile>.filesystem] table, and only settings without a profile use writable_roots under [sandbox_workspace_write]; then run the command again`);
} finally { unlockBoard(folder); }
});
+
+test('resume checks both board-file and journal-folder write capability without leaving a probe [I1,L3,P4]', () => {
+ for (const blocked of ['file', 'folder']) {
+ const p = project();
+ const folder = join(p.repo, '.git', 'pullboard');
+ const file = join(folder, 'board.sqlite');
+ assert.equal(p.run(p.repo, 'resume').code, 0, 'resume succeeds before access is removed');
+ const before = readFileSync(file);
+ chmodSync(blocked === 'file' ? file : folder, blocked === 'file' ? 0o444 : 0o555);
+ try {
+ if (blocked === 'file') assert.throws(() => appendFileSync(file, ''), { code: 'EACCES' });
+ else assert.throws(() => writeFileSync(join(folder, 'permission-sentinel'), ''), { code: 'EACCES' });
+ const result = p.run(p.repo, 'resume', '--json');
+ assert.notEqual(result.code, 0, `${blocked}: ${result.out}${result.err}`);
+ assert.equal(JSON.parse(result.out).error.code, 'BOARD_NOT_WRITABLE', `${blocked} permission has its own real refusal`);
+ assert.equal(readFileSync(file).equals(before), true, 'the readiness check changes no board bytes');
+ } finally { chmodSync(blocked === 'file' ? file : folder, blocked === 'file' ? 0o644 : 0o755); }
+ assert.equal(p.run(p.repo, 'resume').code, 0, 'the named permission repair restores readiness');
+ assert.deepEqual(readdirSync(folder).filter(name => name.startsWith('.write-access-')), [], 'successful and refused checks leave no probe');
+ }
+});