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(relay): refuse person moves before relay I/O [H2,H9,H16]

Corey Olsonafe06bfdc9f3
diff --git a/src/relay.js b/src/relay.js
index 66d515d5..e5c461b6 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -864,6 +864,9 @@ export async function relayOperation(root, operation, args, io, command, applyLo
return locked(file, async () => {
const state = loadLink(file);
if (!state || state.unlinking) throw new Refused('RELAY_UNLINK_PENDING', 'finish unlinking this device with pullboard relay off before sending a move');
+ if (credentialActor({ operation, args, personRequest: io?.personRequest }) === 'person') {
+ throw new Refused('HUMAN_REQUIRED', 'send this person action from the paired phone');
+ }
if (state.recovery) throw new Refused('RELAY_RECOVERY_PENDING', `finish the saved recovery for sequence ${state.recovery.skip} before sending a linked move`);
let moves = CHECKPOINT_MOVES.get(io);
if (!moves) { moves = new Set(); CHECKPOINT_MOVES.set(io, moves); }
diff --git a/test/relay-credential.test.js b/test/relay-credential.test.js
index f81131f3..62c8b314 100644
--- a/test/relay-credential.test.js
+++ b/test/relay-credential.test.js
@@ -1,6 +1,7 @@
/** Real transport proves credential selection follows every public operation class [H2,H9,H16]. */
import assert from 'node:assert/strict';
-import { readFileSync } from 'node:fs';
+import { readFileSync, writeFileSync } from 'node:fs';
+import { createServer } from 'node:http';
import { test } from 'node:test';
import { ENGINE_OPERATIONS } from '../src/engine.js';
import { ENGINE_VERSION } from '../src/machine.js';
@@ -89,3 +90,82 @@ test('every current operation selects its native actor credential without a seco
}
}
});
+
+test('a person-only move is refused before the relay is asked [H2,H9,H16]', async (t) => {
+ const box = await relayClientFixture(t);
+ await box.link();
+
+ /** Return one move's relay-call trace from the real linked CLI environment. */
+ async function orderedMove(operation, args, io = {}) {
+ return box.script(`
+ import { relayOperation } from ${JSON.stringify(new URL('../src/relay.js', import.meta.url).href)};
+ const io = ${JSON.stringify(io)};
+ io.err = () => {};
+ try { await relayOperation(process.cwd(), ${JSON.stringify(operation)}, ${JSON.stringify(args)}, io); console.log(JSON.stringify({ code: null })); }
+ catch (error) { console.log(JSON.stringify({ code: error.code ?? error.name })); }
+ `);
+ }
+
+ const orderedCases = [
+ ['register', [{ lane: box.lane, path: '/private/person-refusal-machine-control' }], {}, null],
+ ['addItem', [{ by: 'coordinator', lane: box.lane, title: 'person refusal agent control' }], {}, null],
+ ['applyRowDecisions', [{ agentId: 'coordinator', events: [] }], {
+ personRequest: { id: 'closed-person-request', executor: 'coordinator', phase: 'execute', digest: '0'.repeat(64) },
+ }, 'PERSON_REQUEST_CLOSED'],
+ ];
+ for (const [operation, args, io, expected] of orderedCases) {
+ const before = box.calls.length;
+ const result = await orderedMove(operation, args, io);
+ assert.equal(result.code, 0, `${operation} control runs in the real linked fixture`);
+ assert.equal(result.document.code, expected, `${operation} retains its native outcome`);
+ const calls = box.calls.slice(before);
+ const catchUp = calls.findIndex(call => call.method === 'GET' && call.path.includes('/events?after='));
+ assert.notEqual(catchUp, -1, `${operation} reads the relay event prefix before its outcome`);
+ if (operation !== 'applyRowDecisions') {
+ const move = calls.findIndex(call => call.method === 'POST' && call.path.endsWith('/moves'));
+ assert.ok(move > catchUp, `${operation} catches up before sending its move`);
+ } else {
+ assert.ok(calls.some(call => call.method === 'GET' && call.path.includes('/events?after=')),
+ 'a person-request execution still follows the machine catch-up path');
+ }
+ }
+
+ const arrivals = [];
+ const blackhole = createServer(request => {
+ arrivals.push({ method: request.method, path: request.url });
+ request.resume();
+ // Deliberately never answer; closing the socket makes a broken guard fail promptly.
+ request.socket.destroy();
+ });
+ t.after(() => {
+ blackhole.closeAllConnections();
+ blackhole.close();
+ });
+ await new Promise(resolve => blackhole.listen(0, '127.0.0.1', resolve));
+ const state = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ state.url = `http://127.0.0.1:${blackhole.address().port}`;
+ writeFileSync(box.linkFile, JSON.stringify(state), { mode: 0o600 });
+
+ const personCases = [
+ ['recordLandingWaiver', [{ agentId: 'person', channel: 'terminal', reason: 'fixture' }]],
+ ['recordRowDecisions', [{ agentId: 'person', channel: 'terminal', decisions: [] }]],
+ ['answerDecision', [1, { agentId: 'person', asPerson: true, channel: 'terminal' }]],
+ ['holdLane', [box.lane, { agentId: 'person', asPerson: true, channel: 'terminal', reason: 'fixture' }]],
+ ['releaseLane', [box.lane, { agentId: 'person', asPerson: true, channel: 'terminal' }]],
+ ['shout', [{ from: 'coordinator', to: 'all', text: 'person request fixture', lanes: [box.lane], request: true }]],
+ ];
+ const personResult = await box.script(`
+ import { relayOperation } from ${JSON.stringify(new URL('../src/relay.js', import.meta.url).href)};
+ const cases = ${JSON.stringify(personCases)};
+ const results = [];
+ for (const [operation, args] of cases) {
+ try { await relayOperation(process.cwd(), operation, args, { err() {} }); results.push(null); }
+ catch (error) { results.push(error.code ?? error.name); }
+ }
+ console.log(JSON.stringify({ results }));
+ `);
+ assert.equal(personResult.code, 0, 'the real private CLI environment runs every person-only operation');
+ assert.deepEqual(personResult.document.results, personCases.map(() => 'HUMAN_REQUIRED'),
+ `each person-only action is refused before asking an unreachable relay; observed requests: ${JSON.stringify(arrivals)}`);
+ assert.deepEqual(arrivals, [], 'no person-only operation reaches the relay');
+});