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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: flush interrupted journal evidence before archiving (#13332)
Adam Eivy0a9500c6280a
diff --git a/scripts/recover-maintenance-transaction.mjs b/scripts/recover-maintenance-transaction.mjsindex c6a6d6baf1..ed18055e76 100644--- a/scripts/recover-maintenance-transaction.mjs+++ b/scripts/recover-maintenance-transaction.mjs@@ -72,7 +72,13 @@ export async function recoverMaintenanceTransaction(reason, { data = PATHS.data,pending, originalStateSha256: original ? createHash('sha256').update(original).digest('hex') : null,hold: state.hold };durableWrite(join(archiveDir, 'receipt.json'), `${JSON.stringify(receipt)}\n`);- for (const { name } of pending) io.renameSync(join(directory, name), join(archiveDir, name));+ // Interrupted writes may never have flushed their data. A directory fsync+ // preserves names, not those bytes; retain the original fence on flush failure.+ for (const { name } of pending) {+ const fd = io.openSync(join(directory, name), 'r');+ try { io.fsyncSync(fd); } finally { io.closeSync(fd); }+ io.renameSync(join(directory, name), join(archiveDir, name));+ }syncMaintenanceDirectory(archiveDir, io);// Publish and fsync a hold BEFORE moving the admission lock. A crash at any// step retains either the original fence or the deliberate recovery hold.diff --git a/scripts/recover-maintenance-transaction.test.js b/scripts/recover-maintenance-transaction.test.jsindex f14dc109bc..b71ceca462 100644--- a/scripts/recover-maintenance-transaction.test.js+++ b/scripts/recover-maintenance-transaction.test.js@@ -114,4 +114,29 @@ describe('offline maintenance transaction recovery', () => {expect(createMaintenanceAdmission(data).status()).toMatchObject({ state: 'ready', hold: { owner: 'Transaction recovery' } });expect(fs.existsSync(join(directory, partial, 'receipt.json'))).toBe(true);});++ it('refuses to release the original fence when interrupted pending evidence cannot be flushed', async () => {+ const { data, directory, admission } = fixture();+ interrupt(directory);+ const descriptors = new Map();+ const io = { ...fs,+ openSync: (path, ...args) => {+ const fd = fs.openSync(path, ...args);+ descriptors.set(fd, path);+ return fd;+ },+ closeSync: fd => { descriptors.delete(fd); fs.closeSync(fd); },+ fsyncSync: fd => {+ if (descriptors.get(fd) === join(directory, 'pending-fixture.json')) throw new Error('fixture evidence flush failed');+ fs.fsyncSync(fd);+ },+ };+ await expect(recoverMaintenanceTransaction(reason, { data, processes: stopped, io })).rejects.toThrow('fixture evidence flush failed');+ expect(admission.status()).toMatchObject({ state: 'unavailable', cause: 'interrupted-transaction' });+ expect(fs.readFileSync(join(directory, 'pending-fixture.json'))).toHaveLength(0);+ expect(fs.readFileSync(join(directory, 'pending-other.json'), 'utf8')).toBe('{"partial":true}');+ expect(descriptors.size).toBe(0);+ await recoverMaintenanceTransaction(reason, { data, processes: stopped });+ expect(createMaintenanceAdmission(data).status()).toMatchObject({ state: 'ready', hold: { owner: 'Transaction recovery' } });+ });});