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: preserve retryable capsule deletion on unlink failure

[._.]/ Adam Eivy01d302f33f58
diff --git a/docs/BACKUP.md b/docs/BACKUP.md
index e7fa695b64..f4a70383e4 100644
--- a/docs/BACKUP.md
+++ b/docs/BACKUP.md
@@ -99,7 +99,7 @@ Admission inventory (`withBackupAssetPublication`):
| Peer CoS archive imports (`sharing/peerCosSync.js`) | Covered (#9982 partial): verified downloads stage outside admission; final files, index reconciliation and present-but-unindexed recovery take one lease |
| ChatGPT archive import and import-memory deletion (`chatgptImport.js`, `brain.js`; the ZIP's asset extraction in `chatgptZipImport.js`) | Covered (#9982 partial): assets are extracted outside admission and named only by the memory row; each conversation's archived transcript and that row commit under one lease, and deleting an import memory drops the record and unlinks its transcript and unreferenced assets under one lease |
| YouTube ingest (`youtubeIngest.js`) | Covered (#9982 partial): downloads run outside admission; the index record that first names a transcript or audio file takes the lease, and forgetting an ingest drops the record and unlinks its files under one lease |
-| Digital twin documents, enrichment answers/lists, peer document sync and genome upload/delete (`digital-twin-documents.js`, `digital-twin-enrichment.js`, `digital-twin-sync.js`, `genome.js`) | Covered (#9982 partial): each document file or raw genome file and the meta record naming it is one lease, including deletion; enrichment provider work stays outside, while peer sync holds the lease from its meta merge through tombstone reaping and document copying |
+| Digital twin documents, enrichment answers/lists, peer document sync and genome upload/delete (`digital-twin-documents.js`, `digital-twin-enrichment.js`, `digital-twin-sync.js`, `genome.js`) | Covered (#9982 partial): each document file or raw genome file and the meta record naming it is one lease, including deletion; enrichment provider work stays outside, while peer sync holds the lease from document copying through metadata save and tombstone reaping |
| Derived media index (`mediaAssetIndex/`) | Rebuilt: `media_assets` rows are excluded from snapshot dumps; database restore rebuilds atomically from disk before reopening admission, and relevant file restores refresh the mirror |
| Explicit file purge (`dataManager.js`, `routes/uploads.js`, `routes/attachments.js`) | Covered: single and bulk deletions hold one lease. These operator-directed removals may intentionally leave external references; admission prevents a snapshot from interleaving with the removal, not from preserving that already-deleted state |
| Image generation completion, upscale/clean tails, variants and sketch pairs (`imageGen/*.js`, `mediaSketches.js`) | Covered (#9982 partial): provider output publication through sidecar and cleanup takes one lease; remote replacement and variant/sketch rewrites restore previous files on failure |
diff --git a/server/services/timeCapsule.js b/server/services/timeCapsule.js
index 41fefb5cec..3dec2c6e73 100644
--- a/server/services/timeCapsule.js
+++ b/server/services/timeCapsule.js
@@ -203,11 +203,15 @@ export async function deleteSnapshot(id) {
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.
+ // snapshot bytes. Restore the listing on unlink failure so deletion stays retryable.
+ const previousSnapshots = index.snapshots;
index.snapshots = index.snapshots.filter(s => s.id !== id);
await saveIndex(index);
- await unlink(snapshotFile).catch((err) => {
- if (err.code !== 'ENOENT') throw err;
+ await unlink(snapshotFile).catch(async err => {
+ if (err.code === 'ENOENT') return;
+ index.snapshots = previousSnapshots;
+ await saveIndex(index);
+ throw err;
});
console.log(`🗑️ Time capsule deleted: "${exists.label}" (${id.slice(0, 8)})`);