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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(core): name unwritable machine storage [I1,C7]
Corey Olson323255776f33
diff --git a/src/machine-home.js b/src/machine-home.jsindex ff5efdba..878c3790 100644--- a/src/machine-home.js+++ b/src/machine-home.js@@ -1,9 +1,24 @@/** Resolve the per-account directory for machine-wide Pullboard state. */import { userInfo } from 'node:os';import { join, resolve } from 'node:path';+import { Refused } from './refused.js';/** Use the OS account home unless a caller explicitly selects a private machine pool. */export function machineHome() {const override = process.env.PULLBOARD_MACHINE_HOME;return override ? resolve(override) : join(userInfo().homedir, '.pullboard');}++/** Name inaccessible machine storage without disguising corruption or other database failures. */+export function withMachineHomeWrite(directory, work) {+ try { return work(); }+ catch (error) {+ const sqliteCode = error.code === 'ERR_SQLITE_ERROR' ? error.errcode & 0xff : null;+ if (['EACCES', 'EPERM', 'EROFS', 'SQLITE_CANTOPEN', 'SQLITE_READONLY'].includes(error.code)+ || sqliteCode === 14 || sqliteCode === 8) {+ throw new Refused('MACHINE_HOME_NOT_WRITABLE',+ `Cannot write machine home "${directory}". Give the agent write access to that directory (the access pullboard init grants), or run the command outside the sandbox.`);+ }+ throw error;+ }+}diff --git a/src/projects.js b/src/projects.jsindex efbade79..4cb267e9 100644--- a/src/projects.js+++ b/src/projects.js@@ -8,6 +8,7 @@ import { basename, join, resolve } from 'node:path';import { randomUUID } from 'node:crypto';import { DatabaseSync } from 'node:sqlite';import { loadConfig } from './config.js';+import { withMachineHomeWrite } from './machine-home.js';/*** The registry file.@@ -66,23 +67,25 @@ function openRegistryLock(file) {*/function withRegistry(mutate) {const file = registryFile();- mkdirSync(join(file, '..'), { recursive: true });- const database = openRegistryLock(file);- try {- const state = readRegistry();- const result = mutate(state.projects, state.readable);- database.exec('COMMIT');- return result;- } catch (error) {+ return withMachineHomeWrite(join(file, '..'), () => {+ mkdirSync(join(file, '..'), { recursive: true });+ const database = openRegistryLock(file);try {- database.exec('ROLLBACK');- } catch {- // A failed commit may already have ended the transaction.+ const state = readRegistry();+ const result = mutate(state.projects, state.readable);+ database.exec('COMMIT');+ return result;+ } catch (error) {+ try {+ database.exec('ROLLBACK');+ } catch {+ // A failed commit may already have ended the transaction.+ }+ throw error;+ } finally {+ database.close();}- throw error;- } finally {- database.close();- }+ });}/**diff --git a/src/resources.js b/src/resources.jsindex 7f505336..b9023962 100644--- a/src/resources.js+++ b/src/resources.js@@ -5,7 +5,7 @@ import { basename, dirname, join, resolve } from 'node:path';import { randomUUID } from 'node:crypto';import { DatabaseSync } from 'node:sqlite';import { repoInfo } from './git.js';-import { machineHome } from './machine-home.js';+import { machineHome, withMachineHomeWrite } from './machine-home.js';import { Refused } from './refused.js';const LEASE_MS = 20_000;@@ -64,7 +64,12 @@ function canonicalResourceFile(file) {}/** Open and initialize the small durable queue database. */-function open(file) {+function open(file, machine = false) {+ return machine ? withMachineHomeWrite(machineHome(), () => openQueue(file)) : openQueue(file);+}++/** Initialize a queue, leaving machine-storage error translation to its caller. */+function openQueue(file) {mkdirSync(dirname(file), { recursive: true });const db = new DatabaseSync(file);db.exec('PRAGMA busy_timeout = 10000');@@ -236,7 +241,7 @@ export async function takeResource(options) {if (landing && itemCheck) throw new Refused('BAD_RESOURCE_PRIORITY', 'a gate slot cannot be both a landing and an item check');if (diagnostic && (landing || itemCheck)) throw new Refused('BAD_RESOURCE_PRIORITY', 'a diagnostic slot cannot also be a landing or an item check');const file = databaseFile(scope, root);- const db = open(file);+ const db = open(file, scope === 'machine');let pool;try { pool = canonicalResourceFile(file); }catch (error) { db.close(); throw error; }@@ -354,7 +359,7 @@ export function inheritedGateSlot({ root = process.cwd(), browser = false } = {}if (canonicalResourceFile(markedPool) !== pool) return null;if (process.env[GATE_SLOT_HELD_ENV] !== '1') throw new Refused('GATE_SLOT_MARKER_INVALID', 'the inherited gate lease is missing its legacy held marker; start the child with gateSlotEnvironment(lease)');if (!token) throw new Refused('GATE_SLOT_TOKEN_REQUIRED', 'the inherited gate pool marker has no lease token; restart the child with gateSlotEnvironment(lease)');- const db = open(pool);+ const db = open(pool, true);let holder;try {holder = update(db, () => db.prepare("SELECT browser FROM holder WHERE name = 'gate' AND token = ?").get(token));@@ -373,7 +378,7 @@ export function inheritedGateSlot({ root = process.cwd(), browser = false } = {}export function setResourceCapacity({ name, capacity, scope = 'machine', root = process.cwd(), persist = () => {} }) {if (typeof name !== 'string' || !name.trim() || name.trim() !== name) throw new Refused('BAD_RESOURCE_NAME', 'resource name must be nonempty trimmed text');if (!Number.isSafeInteger(capacity) || capacity < 1) throw new Refused('BAD_RESOURCE_CAPACITY', 'resource capacity must be a positive integer');- const db = open(databaseFile(scope, root));+ const db = open(databaseFile(scope, root), scope === 'machine');try {return update(db, () => {const state = snapshot(db, name);@@ -389,7 +394,7 @@ export function setResourceCapacity({ name, capacity, scope = 'machine', root =/** List resources and prune leases whose process died or lease expired. */export function listResources({ scope = 'machine', root = process.cwd() } = {}) {- const db = open(databaseFile(scope, root));+ const db = open(databaseFile(scope, root), scope === 'machine');try {return update(db, () => db.prepare('SELECT name, capacity FROM resource ORDER BY name').all().map(({ name, capacity }) => ({ name, capacity, ...snapshot(db, name) })));} finally { db.close(); }diff --git a/test/machine-home.test.js b/test/machine-home.test.jsnew file mode 100644index 00000000..51df3167--- /dev/null+++ b/test/machine-home.test.js@@ -0,0 +1,67 @@+/** Real machine-storage permission refusals preserve the shared queue location [I1,C7,Q4]. */+import assert from 'node:assert/strict';+import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { after, test } from 'node:test';+import { createE2eHelpers } from './e2e-helpers.js';++const { sandbox, project, cleanup } = createE2eHelpers();+after(cleanup);++/** Check the named refusal, its actual blocked directory and both usable next steps. */+function refused(result, directory) {+ const output = result.out + result.err;+ assert.notEqual(result.code, 0, output);+ assert.match(output, /MACHINE_HOME_NOT_WRITABLE/u);+ assert.ok(output.includes(directory), output);+ assert.match(output, /write access to that directory/u);+ assert.match(output, /run the command outside the sandbox/u);+ assert.doesNotMatch(output, /unable to open database file/iu);+}++test('an unwritable machine home is refused by name [I1,C7,Q4]', async (t) => {+ await t.test('resume names a blocked project registry when refreshing its metadata', () => {+ const box = sandbox();+ box.env.PULLBOARD_MACHINE_HOME = box.env.PULLBOARD_HOME;+ const p = project(undefined, box);+ const home = p.env.PULLBOARD_MACHINE_HOME;+ const folder = join(home, 'relay-machine');+ mkdirSync(folder, { mode: 0o700 });+ writeFileSync(join(folder, 'state.json'), JSON.stringify({ v: 2, autoLink: true,+ owner: null, machine: 'machine-fixture', devices: [], excluded: [], pending: null,+ revocations: [], approvals: [] }), { mode: 0o600 });+ const config = join(p.repo, 'pullboard.json');+ writeFileSync(config, JSON.stringify({ ...JSON.parse(readFileSync(config, 'utf8')), name: 'Renamed project' }));+ // A real metadata refresh must create its SQLite lock in the now-blocked directory.+ rmSync(join(home, 'projects.json.lock.sqlite'));+ chmodSync(home, 0o500);+ try {+ assert.throws(() => writeFileSync(join(home, 'permission-sentinel'), ''), { code: 'EACCES' });+ refused(p.run(p.repo, 'resume'), home);+ } finally { chmodSync(home, 0o700); }+ });+ await t.test('the pool override is independent of the writable project registry', () => {+ const p = project();+ const home = p.env.PULLBOARD_MACHINE_HOME;+ assert.notEqual(home, p.env.PULLBOARD_HOME);+ mkdirSync(home, { recursive: true });+ rmSync(join(home, 'resources.sqlite'), { force: true });+ chmodSync(home, 0o500);+ try {+ refused(p.run(p.repo, 'resources'), home);+ assert.equal(existsSync(join(home, 'resources.sqlite')), false);+ } finally { chmodSync(home, 0o700); }+ assert.equal(p.run(p.repo, 'resources').code, 0, 'restoring write access restores the real pool');+ });+ await t.test('a blocked parent names the requested missing machine home', () => {+ const p = project();+ const parent = join(p.dir, 'blocked-parent');+ mkdirSync(parent);+ p.env.PULLBOARD_MACHINE_HOME = join(parent, 'new-machine-home');+ chmodSync(parent, 0o500);+ try {+ refused(p.run(p.repo, 'resources'), p.env.PULLBOARD_MACHINE_HOME);+ assert.equal(existsSync(p.env.PULLBOARD_MACHINE_HOME), false);+ } finally { chmodSync(parent, 0o700); }+ });+});diff --git a/test/machine.test.js b/test/machine.test.jsindex 34cf542e..eb889650 100644--- a/test/machine.test.js+++ b/test/machine.test.js@@ -27,6 +27,7 @@ const NOT_MOVES = {ALREADY_JOINED: 'registering who is asking, before any move',BAD_ROUTE: 'registering who is asking, before any move',ONE_COORDINATOR: 'registering who is asking, before any move',+ MACHINE_HOME_NOT_WRITABLE: 'machine-wide storage must be writable before a command runs',BAD_MACHINE_SETTINGS: 'machine-wide settings checked before a command runs',BAD_GATE_SLOTS: 'machine-wide gate capacity checked before a command runs',BAD_BROWSER_SLOTS: 'machine-wide browser capacity checked before a command runs',