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(core): validate proof stamps before ordered replay [C7,H16]

Corey Olsonc0e27c992d65
diff --git a/src/proof-cli.js b/src/proof-cli.js
index 21683343..1a9ca7ac 100644
--- a/src/proof-cli.js
+++ b/src/proof-cli.js
@@ -1,10 +1,15 @@
/** Native command adapters record execution ids, never agent-written provenance [C7,H16]. */
+import { proofRunReceipt } from './proof-receipts.js';
import { Refused } from './refused.js';
/** Bind an actual run to its native caller before the command can publish its outcome. */
export async function recordNativeProof(ctx, item, run, { ordered, withBoard, resourceAgent }, board = null) {
if (run.executed === false || run.checked === false) return;
if (!run.proofReceiptId) throw new Refused('PROOF_RUN_UNAVAILABLE', 'the executed check has no native receipt; restore receipt storage and read pullboard show <id> before trying again');
- const write = target => ordered(ctx, target, 'recordProofRun', [{ agentId: resourceAgent(ctx), itemId: item.item_id, receiptId: run.proofReceiptId }]);
+ const write = target => {
+ const request = { agentId: resourceAgent(ctx), itemId: item.item_id, receiptId: run.proofReceiptId };
+ proofRunReceipt(target, request);
+ return ordered(ctx, target, 'recordProofRun', [request]);
+ };
return board ? write(board) : withBoard(ctx, write);
}
diff --git a/src/proof-receipts.js b/src/proof-receipts.js
index fce39d52..ee205d01 100644
--- a/src/proof-receipts.js
+++ b/src/proof-receipts.js
@@ -32,32 +32,38 @@ export function proofReceipts(board, itemId) {
.map(row => ({ eventId: row.event_id, ...JSON.parse(row.event_detail).receipt }));
}
-/** Record only native facts, resolving the actor and its parent from board-owned registration. */
-export function recordProofRun(board, request) {
- if ((board.executionEngineVersion ?? ENGINE_VERSION) < PROOF_RUN_ENGINE) {
- throw new Refused('ENGINE_VERSION', `proof receipts require engine ${PROOF_RUN_ENGINE}; upgrade Pullboard`);
- }
+/** Validate native facts against current board-owned identities without changing the board. */
+export function proofRunReceipt(board, request) {
const { agentId, itemId } = request;
if (!listAgents(board).some(agent => agent.agent_id === agentId)) throw new Refused('NOT_JOINED', 'join before recording a proof run');
const run = board.executionEngineVersion === undefined ? boundProofReceipt(board, request) : receiptFields(request.receipt);
if (!run || run.version !== 2 || run.proof.item !== itemId) throw new Refused('PROOF_RUN_UNBOUND', 'the native receipt must name this item; run its check and read pullboard show <id>');
if (run.proof.seat !== agentId) throw new Refused('PROOF_RUN_ACTOR', 'the native receipt belongs to another seat; use the receipts from your own check');
+ const item = getItem(board, itemId);
+ if (run.proof.frozenDigest !== (item.item_frozen_digest ?? null)) throw new Refused('PROOF_RUN_STALE', 'the criterion changed during this proof; read pullboard show <id> before checking again');
+ const receipt = { id: run.id, kind: run.kind, item: itemId, commit: run.head, tree: run.tree,
+ frozenDigest: run.proof.frozenDigest, environment: run.proof.environment, runner: run.proof.runner,
+ seat: agentId, parentSession: seats.agentParent?.(board, agentId) ?? null, exitCode: run.proof.exitCode,
+ counts: run.proof.counts, durationMs: run.proof.durationMs, sourceClean: run.proof.sourceClean, at: run.at };
+ const existing = proofReceipts(board, itemId).find(value => value.id === receipt.id);
+ if (existing) {
+ const { eventId, ...fields } = existing;
+ // Later registration cannot retroactively upgrade an originally unknown parent.
+ receipt.parentSession = existing.parentSession;
+ if (JSON.stringify(fields) !== JSON.stringify(receipt)) throw new Refused('PROOF_RUN_CHANGED', 'that receipt id already binds different facts; keep the original and run a new check');
+ }
+ return { receipt, existing };
+}
+
+/** Record native facts atomically, revalidating after the native adapter's read-only preflight. */
+export function recordProofRun(board, request) {
+ if ((board.executionEngineVersion ?? ENGINE_VERSION) < PROOF_RUN_ENGINE) {
+ throw new Refused('ENGINE_VERSION', `proof receipts require engine ${PROOF_RUN_ENGINE}; upgrade Pullboard`);
+ }
return atomic(board, () => {
- const item = getItem(board, itemId);
- if (run.proof.frozenDigest !== (item.item_frozen_digest ?? null)) throw new Refused('PROOF_RUN_STALE', 'the criterion changed during this proof; read pullboard show <id> before checking again');
- const receipt = { id: run.id, kind: run.kind, item: itemId, commit: run.head, tree: run.tree,
- frozenDigest: run.proof.frozenDigest, environment: run.proof.environment, runner: run.proof.runner,
- seat: agentId, parentSession: seats.agentParent?.(board, agentId) ?? null, exitCode: run.proof.exitCode,
- counts: run.proof.counts, durationMs: run.proof.durationMs, sourceClean: run.proof.sourceClean, at: run.at };
- const existing = proofReceipts(board, itemId).find(value => value.id === receipt.id);
- if (existing) {
- const { eventId, ...fields } = existing;
- // Later registration cannot retroactively upgrade an originally unknown parent.
- receipt.parentSession = existing.parentSession;
- if (JSON.stringify(fields) !== JSON.stringify(receipt)) throw new Refused('PROOF_RUN_CHANGED', 'that receipt id already binds different facts; keep the original and run a new check');
- return existing;
- }
- logEvent(board, agentId, 'proof-run', itemId, { engine: PROOF_RUN_ENGINE, receipt });
+ const { receipt, existing } = proofRunReceipt(board, request);
+ if (existing) return existing;
+ logEvent(board, request.agentId, 'proof-run', request.itemId, { engine: PROOF_RUN_ENGINE, receipt });
return receipt;
});
}