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: retain TimeCapsule bytes when index deletion fails
[._.]/ Adam Eivye5af1c67eac2
diff --git a/server/services/timeCapsule.backupAdmission.test.js b/server/services/timeCapsule.backupAdmission.test.jsindex 4aa7c91b10..bca1fa7f27 100644--- a/server/services/timeCapsule.backupAdmission.test.js+++ b/server/services/timeCapsule.backupAdmission.test.js@@ -1,4 +1,4 @@-/** Snapshot/index pairs must be copied together, including unlink-first deletion. */+/** Snapshot/index pairs must be copied together, including deletion failures. */import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';import { mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';import { join } from 'node:path';@@ -63,7 +63,7 @@ describe.each(cases)('$name snapshot pair', ({ setup }) => {expect(after).not.toEqual(before);});- it('drains from the first file mutation through the index commit', async () => {+ it('drains the complete file and index mutation', async () => {const run = await setup();const reached = deferred(); const commit = deferred();beforeIndexWrite = async () => { reached.resolve(); await commit.promise; };@@ -91,3 +91,13 @@ it('negative control exposes a copied index naming a file created after the fileexpect(copiedFiles).not.toEqual(copiedIndex);} finally { release(); }});++it('preserves referenced snapshot bytes when deletion cannot commit its index', async () => {+ const snapshot = await createSnapshot('Example retained snapshot');+ const before = await capture();+ beforeIndexWrite = async () => { throw new Error('synthetic index write failure'); };+ await expect(deleteSnapshot(snapshot.id)).rejects.toThrow('synthetic index write failure');+ const release = await acquireBackupSnapshotCut();+ try { expect(await capture()).toEqual(before); }+ finally { release(); }+});diff --git a/server/services/timeCapsule.js b/server/services/timeCapsule.jsindex f6df8a33e9..41fefb5cec 100644--- a/server/services/timeCapsule.js+++ b/server/services/timeCapsule.js@@ -202,13 +202,14 @@ export async function deleteSnapshot(id) {if (!exists) return false;const snapshotFile = join(SNAPSHOTS_DIR, `${id}.json`);+ // Commit reference removal first: a failed index write must retain the+ // snapshot bytes. A later unlink failure leaves only an unreferenced file.+ index.snapshots = index.snapshots.filter(s => s.id !== id);+ await saveIndex(index);await unlink(snapshotFile).catch((err) => {if (err.code !== 'ENOENT') throw err;});- index.snapshots = index.snapshots.filter(s => s.id !== id);- await saveIndex(index);-console.log(`🗑️ Time capsule deleted: "${exists.label}" (${id.slice(0, 8)})`);return true;}));