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(relay): guard decision answers in sealed shouts [H16,B26]
Corey Olson2dddf59ba4d9
diff --git a/src/relay-sender.js b/src/relay-sender.jsindex a362c0a9..6b52d521 100644--- a/src/relay-sender.js+++ b/src/relay-sender.js@@ -1,4 +1,4 @@-/** Compare sealed actors with the relay's independently authenticated sender [H2,H16]. */+/** Compare sealed actors with the relay's independently authenticated sender [H2,H16,B26]. */import { Refused } from './refused.js';/** Read only the actor field used by each public engine operation; unknown operations fail closed. */@@ -20,6 +20,9 @@ export function relaySenderProblem(move, sender, kind) {(sender.kind === 'agent' && (typeof sender.agent !== 'string' || !sender.agent.length || sender.agent.length > 256))) {return new Refused('RELAY_SENDER', 'this relay record has no authenticated sender; restore attribution before replaying it');}+ if (move?.operation === 'shout' && move.args?.[0]?.answers != null) {+ return new Refused('RELAY_ANSWER', 'a sealed shout cannot answer or pass a decision; use pullboard answer <id> "<answer>" or pullboard pass <id> --note "<reason>" so the decision rules are checked');+ }if (sender.kind === 'person') return null;if (kind === 'snapshot' || move?.operation === 'recordRowDecisions' || move?.operation === 'answerDecision' && move.args?.[1]?.asPerson ||move?.operation === 'shout' && move.args?.[0]?.request || relayMoveActor(move) === 'person') {diff --git a/test/engine.test.js b/test/engine.test.jsindex be7e5a66..2598c416 100644--- a/test/engine.test.js+++ b/test/engine.test.js@@ -117,6 +117,54 @@ test('missing relay senders are refused deterministically without poisoning a laassert.deepEqual(exportBoard(one).tables, exportBoard(two).tables);});+test('sealed shouts cannot bypass addressee, already answered or person decision rules [H16,B26]', t => {+ const questions = [];+ const { copies } = engineCopies(t, source => {+ const lanes = ['web'];+ questions.push(store.shout(source, { from: 'coordinator', to: 'person', text: 'Person decision', decision: true, lanes }));+ questions.push(store.shout(source, { from: 'coordinator', to: 'web-2', text: 'Another agent decision', decision: true, lanes }));+ const closed = store.shout(source, { from: 'coordinator', to: 'web-1', text: 'Already answered decision', decision: true, lanes });+ store.answerDecision(source, closed, { agentId: 'web-1', text: 'Original answer', lanes });+ questions.push(closed);+ questions.push(store.shout(source, { from: 'web-1', to: 'coordinator', text: 'Needs passing', decision: true, lanes }));+ });+ for (const board of copies) {+ const original = exportBoard(board);+ let sequence = 0;+ for (const sender of [{ kind: 'agent', userId: 'fixture-user', agent: 'web-1' }, { kind: 'person', userId: 'fixture-user' }]) {+ for (const answers of questions.slice(0, 3)) {+ const move = prepareEngineMove(board, 'shout', [{ from: 'web-1', to: 'coordinator', text: 'Bypass attempted', answers, lanes: ['web'] }], { id: 'bypass-' + ++sequence });+ const refused = applyRelayMove(board, move, { sequence, at: CLAIM_AT, kind: 'move', sender });+ assert.equal(refused.error?.code, 'RELAY_ANSWER');+ assert.match(refused.error.next, /pullboard answer.*pullboard pass/);+ assert.deepEqual(exportBoard(board).tables.shout, original.tables.shout);+ assert.deepEqual(exportBoard(board).tables.item, original.tables.item);+ }+ }+ const agentSender = { kind: 'agent', userId: 'fixture-user', agent: 'web-1' };+ for (const [index, expected] of ['NOT_YOUR_DECISION', 'NOT_YOUR_DECISION', 'ALREADY_ANSWERED'].entries()) {+ const move = prepareEngineMove(board, 'answerDecision', [questions[index], { agentId: 'web-1', text: 'Guarded attempt', lanes: ['web'] }], { id: 'answer-' + ++sequence });+ assert.equal(applyRelayMove(board, move, { sequence, at: CLAIM_AT, kind: 'move', sender: agentSender }).error.code, expected);+ assert.deepEqual(exportBoard(board).tables.shout, original.tables.shout);+ }+ assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [questions[0]]);+ const permitted = prepareEngineMove(board, 'answerDecision', [questions[0], { agentId: 'coordinator', asPerson: true, text: 'Person answered', lanes: ['web'], channel: 'view' }], { id: 'person-answer' });+ assert.equal(Boolean(applyRelayMove(board, permitted, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: { kind: 'person', userId: 'fixture-user' } }).error), false);+ assert.deepEqual(store.openDecisions(board, 'person'), []);+ const personSender = { kind: 'person', userId: 'fixture-user' };+ const pass = prepareEngineMove(board, 'passDecision', [questions[3], { agentId: 'coordinator', note: 'Needs the person', lanes: ['web'] }], { id: 'guarded-pass' });+ const passed = applyRelayMove(board, pass, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: personSender });+ assert.equal(Boolean(passed.error), false);+ assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [passed.result]);+ const response = prepareEngineMove(board, 'answerDecision', [passed.result, { agentId: 'coordinator', asPerson: true, text: 'Passed decision answered', lanes: ['web'] }], { id: 'passed-answer' });+ assert.equal(Boolean(applyRelayMove(board, response, { sequence: ++sequence, at: CLAIM_AT, kind: 'move', sender: personSender }).error), false);+ assert.deepEqual(store.openDecisions(board, 'person'), []);+ assert.deepEqual(store.openDecisions(board, 'coordinator'), []);+ assert.ok(exportBoard(board).tables.shout.some(row => row.shout_answers === questions[3] && row.shout_from === 'person'), 'guarded person answers reach the original asker');+ }+ assert.deepEqual(exportBoard(copies[0]).tables, exportBoard(copies[1]).tables);+});+test('a relay refusal receipt failure rolls back its log and cursor together [H2,H16]', t => {const { copies, item } = engineCopies(t);const board = copies[0];diff --git a/test/relay-sealed.test.js b/test/relay-sealed.test.jsindex 48afe0bd..62b3efd3 100644--- a/test/relay-sealed.test.js+++ b/test/relay-sealed.test.js@@ -4,6 +4,7 @@ import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';import { spawn, spawnSync } from 'node:child_process';import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';+import { createServer } from 'node:http';import { join, resolve } from 'node:path';import { test } from 'node:test';import { serveRelay } from '../relay/service.js';@@ -104,6 +105,155 @@ function replayClient(root, env, ...args) {});}+/** Keep each client on its own replay path by blocking checkpoint publication, forwarding all reads to the real relay. */+async function independentReplayOrigin(t, origin) {+ const proxy = createServer(async (request, response) => {+ if (request.method === 'PUT' && request.url.endsWith('/state')) {+ response.writeHead(403, { 'content-type': 'application/json' });+ response.end(JSON.stringify({ version: 1, error: { code: 'HUMAN_REQUIRED', message: 'fixture checkpoint publication disabled' } }));+ return;+ }+ try {+ const reply = await fetch(origin + request.url, { headers: { authorization: request.headers.authorization ?? '' } });+ response.writeHead(reply.status, { 'content-type': 'application/json' });+ response.end(Buffer.from(await reply.arrayBuffer()));+ } catch {+ response.writeHead(502, { 'content-type': 'application/json' });+ response.end(JSON.stringify({ version: 1, error: { code: 'RELAY_UNAVAILABLE', message: 'fixture relay unavailable' } }));+ }+ });+ await new Promise((done, fail) => { proxy.once('error', fail); proxy.listen(0, '127.0.0.1', done); });+ t.after(() => new Promise(done => proxy.close(done)));+ return 'http://127.0.0.1:' + proxy.address().port;+}++/** Capture a real linked command's warnings and structured refusal without changing its exit status. */+function replayResult(root, env, ...args) {+ return new Promise((done, fail) => {+ const child = spawn(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), ...args, '--json'], { cwd: root, env, stdio: ['ignore', 'pipe', 'pipe'] });+ let stdout = '', stderr = '';+ const timer = setTimeout(() => child.kill('SIGKILL'), 25000);+ child.stdout.setEncoding('utf8').on('data', part => { stdout += part; });+ child.stderr.setEncoding('utf8').on('data', part => { stderr += part; });+ child.once('error', error => { clearTimeout(timer); fail(error); });+ child.once('close', code => {+ clearTimeout(timer);+ if (code === null) return fail(new Error('isolated relay command did not finish'));+ try { done({ document: JSON.parse(stdout), stderr, status: code }); }+ catch { fail(new Error('isolated relay read did not return JSON')); }+ });+ });+}++test('sealed agent shout cannot answer a person decision on either independent client [H16,B26]', async t => {+ const box = await fixture(t);+ const source = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));+ let document, question, forged, ordinary, answer;+ try {+ const lane = store.getItem(source, 1).item_lane;+ assert.equal(store.register(source, { lane: 'remote', path: join(box.directory, 'remote') }), 'remote-1');+ question = store.shout(source, {+ from: 'coordinator', to: 'person', text: 'Approve this change?', decision: true, lanes: [lane],+ });+ checkpointSequence(source, 0);+ // This is intentionally a raw authenticated-agent shout, not answerDecision.+ // The relay must reject its answer relation before insertShout can close the question.+ forged = prepareEngineMove(source, 'shout', [{+ from: 'remote-1', to: 'coordinator', text: 'Forged approval', answers: question, lanes: [lane],+ }]);+ ordinary = prepareEngineMove(source, 'shout', [{+ from: 'remote-1', to: 'all', text: 'Ordinary agent observation', lanes: [lane],+ }]);+ answer = prepareEngineMove(source, 'answerDecision', [question, {+ agentId: 'coordinator', asPerson: true, text: 'Approved by the person', lanes: [lane],+ }]);+ document = JSON.parse(JSON.stringify(exportBoard(source)));+ } finally { store.closeBoard(source); }++ const remote = await box.auth.issueToken(box.person.token, { board: box.id, agent: 'remote-1' });+ const roots = [box.root, join(box.directory, 'second-client')];+ const homes = [box.home, join(box.directory, 'second-home')];+ const envs = homes.map(home => ({ ...box.env, HOME: home, PULLBOARD_HOME: home }));+ mkdirSync(roots[1]); mkdirSync(homes[1], { mode: 0o700 });+ assert.equal(spawnSync('git', ['init', '-q', '-b', 'main'], { cwd: roots[1], env: envs[1] }).status, 0);+ await replayClient(roots[1], envs[1], 'init');+ const native = join(box.directory, 'native.json');+ writeFileSync(native, JSON.stringify(document), { mode: 0o600 });+ await replayClient(roots[1], envs[1], 'import', native);+ for (let i = 0; i < roots.length; i++) {+ const keyDirectory = join(homes[i], 'relay-keys');+ mkdirSync(keyDirectory, { mode: 0o700 });+ writeFileSync(join(keyDirectory, box.id + '.key'), box.key.toString('base64url') + '\n', { mode: 0o600 });+ const url = await independentReplayOrigin(t, box.origin);+ writeFileSync(join(roots[i], '.git/pullboard/relay.json'), JSON.stringify({+ version: 1, mode: 'ordered', board: box.id, url, repository: 'fixture/repository',+ token: box.person.token, sequence: 0, cursor: document.tables.event.at(-1).event_id,+ }) + '\n', { mode: 0o600 });+ }++ /** Send a production-sealed move using its actual authenticated relay credential. */+ async function upload(move, sequence, token = remote.token) {+ const sealed = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(move)), {+ boardId: box.id, kind: 'move', sequence,+ })).toString('base64url');+ const reply = await box.call(box.path + '/moves', {+ method: 'POST', token, body: { sequence, sealed },+ });+ assert.equal(reply.status, 200);+ return reply;+ }+ const snapshot = Buffer.from(await sealMove(box.key, new TextEncoder().encode(JSON.stringify(document)), {+ boardId: box.id, kind: 'snapshot', sequence: 0,+ })).toString('base64url');+ assert.equal((await box.call(box.path + '/state', {+ method: 'PUT', token: box.person.token, body: { sequence: 0, sealed: snapshot },+ })).status, 200);+ const forgedUpload = await upload(forged, 1);+ assert.equal(forgedUpload.body.event.sender.agent, 'remote-1');+ await upload(ordinary, 2);++ const refusedReplicas = [];+ for (let i = 0; i < roots.length; i++) {+ const result = await replayResult(roots[i], envs[i], 'export');+ assert.equal(result.status, 0);+ const doc = result.document;+ const q = doc.tables.shout.find(row => row.shout_id === question);+ assert.ok(q && q.shout_decision, 'the person decision remains present');+ assert.equal(doc.tables.shout.some(row => row.shout_answers === question), false, 'the refused agent record did not answer it');+ assert.equal(doc.tables.shout.at(-1).shout_text, 'Ordinary agent observation', 'ordinary agent shouts remain allowed');+ const refusal = doc.tables.event.find(row => row.event_kind === 'relay_refused' && row.event_by === 'remote-1');+ assert.equal(JSON.parse(refusal.event_detail).code, 'RELAY_ANSWER');+ assert.equal(doc.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value, '2');+ const board = store.openBoard(join(roots[i], '.git/pullboard/board.sqlite'));+ try { assert.deepEqual(store.openDecisions(board, 'person').map(row => row.shout_id), [question]); }+ finally { store.closeBoard(board); }+ refusedReplicas.push(doc.tables);+ }+ assert.deepEqual(refusedReplicas[0], refusedReplicas[1], 'both clients independently replay the refusal and allowed shout');+ const beforeAnswer = refusedReplicas[0];++ // A valid, sealed person decision preserves the existing guarded answer path.+ await upload(answer, 3, box.person.token);+ const answered = [];+ for (let i = 0; i < roots.length; i++) {+ const result = await replayResult(roots[i], envs[i], 'export');+ assert.equal(result.status, 0);+ const doc = result.document;+ assert.equal(doc.tables.shout.some(row => row.shout_answers === question && row.shout_text === 'Approved by the person'), true);+ assert.equal(doc.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value, '3');+ assert.deepEqual(doc.tables.event.slice(0, beforeAnswer.event.length), beforeAnswer.event, 'the guarded answer preserves every earlier event row');+ assert.deepEqual(doc.tables.shout.slice(0, beforeAnswer.shout.length), beforeAnswer.shout, 'the guarded answer preserves earlier shout IDs and raw rows');+ const board = store.openBoard(join(roots[i], '.git/pullboard/board.sqlite'));+ try { assert.deepEqual(store.openDecisions(board, 'person'), []); }+ finally { store.closeBoard(board); }+ answered.push(doc.tables);+ }+ assert.deepEqual(answered[0], answered[1], 'both clients apply the actual guarded person answer identically');+ const retained = await box.call(box.path + '/state');+ assert.equal(retained.body.state.sequence, 0);+ assert.equal(retained.body.state.sealed, snapshot, 'both clients independently replayed rather than importing a published checkpoint');+});+test('two real clients refuse forged relay actors and person-only requests while advancing identically [H2,H16]', async t => {const box = await fixture(t);const source = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));