Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: refuse FIFO recovery evidence without blocking maintenance (#13346)

Adam Eivyf14b817a69be
diff --git a/scripts/outputPublicationRecovery.test.js b/scripts/outputPublicationRecovery.test.js
index 8c4c719cc9..044655282c 100644
--- a/scripts/outputPublicationRecovery.test.js
+++ b/scripts/outputPublicationRecovery.test.js
@@ -125,6 +125,38 @@ it.each(['changed', 'missing', 'empty'])('refuses %s evidence and explains the n
expect(fs.existsSync(receiptPath(request))).toBe(false);
});
+it.skipIf(process.platform === 'win32')('refuses FIFO evidence and receipts without blocking inspection or reconciliation', () => {
+ const state = readState();
+ state.operations[0].pid = 2147483647; // Synthetic PID outside the supported hosts' process-id range.
+ fs.writeFileSync(statePath, JSON.stringify(state));
+ const request = inspect();
+ fs.writeFileSync(requestPath, JSON.stringify(request));
+ const path = join(data, spec.files[1].path);
+ const original = fs.readFileSync(path);
+ fs.unlinkSync(path);
+ expect(spawnSync('mkfifo', [path]).status).toBe(0);
+ const script = fileURLToPath(new URL('./reconcile-output-publication.mjs', import.meta.url));
+ for (const args of [['inspect', operationId, specPath], ['reconcile', requestPath, '--confirm-disposition']]) {
+ const result = spawnSync(process.execPath, [script, ...args, '--install-root', root],
+ { env: process.env, encoding: 'utf8', timeout: 5000 });
+ expect(result.error).toBeUndefined();
+ expect(result.status).toBe(1);
+ expect(result.stdout).toContain('Evidence must be regular files');
+ expect(gate.status().state).toBe('draining');
+ expect(gate.operations()).toEqual(state.operations);
+ }
+ fs.unlinkSync(path);
+ fs.writeFileSync(path, original);
+ expect(spawnSync('mkfifo', [receiptPath(request)]).status).toBe(0);
+ const result = spawnSync(process.execPath, [script, 'reconcile', requestPath, '--confirm-disposition', '--install-root', root],
+ { env: process.env, encoding: 'utf8', timeout: 5000 });
+ expect(result.error).toBeUndefined();
+ expect(result.status).toBe(1);
+ expect(result.stdout).toContain('No valid matching receipt');
+ expect(gate.status().state).toBe('draining');
+ expect(gate.operations()).toEqual(state.operations);
+});
+
it.each(['absent', 'duplicate', 'journal', 'unbound'])('rejects insufficient %s evidence before mutation', mode => {
if (mode === 'absent') spec.files = [];
if (mode === 'duplicate') spec.files[1].path = spec.files[0].path;
diff --git a/server/services/outputPublicationRecovery.js b/server/services/outputPublicationRecovery.js
index 84c45b8cb3..e5dc985517 100644
--- a/server/services/outputPublicationRecovery.js
+++ b/server/services/outputPublicationRecovery.js
@@ -70,7 +70,8 @@ function fingerprint(file, data, io) {
try {
const path = join(io.realpathSync(data), ...parts);
if (io.realpathSync(path) !== resolve(path)) refuse('Evidence symlinks are not accepted.');
- fd = io.openSync(path, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
+ // A replaced file may be a FIFO; never block while owning the journal.
+ fd = io.openSync(path, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
const before = io.fstatSync(fd);
if (!before.isFile() || before.size > MAX_EVIDENCE_BYTES) refuse('Evidence must be regular files, at most 16 MiB in total. Preserve larger artifacts and use bounded owning-service evidence.');
const raw = io.readFileSync(fd);
@@ -124,15 +125,22 @@ export function reconcileOutputPublication(input, { confirmDisposition = false,
if (!isDeepStrictEqual(evidence, request.evidence)) refuse('Evidence changed since inspection.');
};
const readReceipt = () => {
- let receipt;
- try { receipt = parse(receiptSchema, JSON.parse(io.readFileSync(receiptPath, 'utf8'))); }
- catch { refuse('No valid matching receipt exists. Preserve existing evidence and diagnose the reservation; a missing owner cannot create a receipt.'); }
- if (!isDeepStrictEqual(receipt.request, request)) refuse('The existing receipt binds different evidence, reason, hold, or operation.');
- // A receipt-first interrupted write may have linked the file before directory fsync.
- const fd = io.openSync(receiptPath, 'r+');
- try { io.fsyncSync(fd); } finally { io.closeSync(fd); }
- syncDirectory(gate.directory, io);
- return receipt;
+ let fd, receipt;
+ try {
+ try {
+ fd = io.openSync(receiptPath, fs.constants.O_RDWR | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0));
+ const stat = io.fstatSync(fd);
+ if (!stat.isFile() || stat.size > 256 * 1024) refuse('The receipt must be a bounded regular file.');
+ const raw = io.readFileSync(fd);
+ if (raw.length !== stat.size) refuse('The receipt changed while being read.');
+ receipt = parse(receiptSchema, JSON.parse(raw.toString('utf8')));
+ } catch { refuse('No valid matching receipt exists. Preserve existing evidence and diagnose the reservation; a missing owner cannot create a receipt.'); }
+ if (!isDeepStrictEqual(receipt.request, request)) refuse('The existing receipt binds different evidence, reason, hold, or operation.');
+ // A receipt-first interrupted write may have linked the file before directory fsync.
+ io.fsyncSync(fd);
+ syncDirectory(gate.directory, io);
+ return receipt;
+ } finally { if (fd !== undefined) io.closeSync(fd); }
};
try { return gate.reconcilePublicationRefusal({ hold: request.hold, expected: request.operation,
replay: () => { verify(); return { ...readReceipt(), replayed: true }; },