From 01e09949fbc1618830ae0a8acb60b38ecb4b6098 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Fri, 27 Feb 2026 13:25:27 +0100 Subject: [PATCH] Fix orphaned branches after clearing all snapshots The footer "Clear All Snapshots" button deleted records from the server but left stale in-memory state (lastCapturedIdMap, activeSnapshotId, etc.) intact. New captures then referenced deleted parents, creating isolated branches. Reset all branching state on both clear-all paths. Co-Authored-By: Claude Opus 4.6 --- js/snapshot_manager.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/snapshot_manager.js b/js/snapshot_manager.js index 9e5adc7..073ff0c 100644 --- a/js/snapshot_manager.js +++ b/js/snapshot_manager.js @@ -2917,6 +2917,7 @@ async function buildSidebar(el) { if (entry.workflowKey === currentKey) { activeSnapshotId = null; currentSnapshotId = null; + activeBranchSelections.clear(); } if (viewingWorkflowKey === entry.workflowKey) { viewingWorkflowKey = null; @@ -2996,6 +2997,13 @@ async function buildSidebar(el) { if (!confirmed) return; try { const { lockedCount } = await db_deleteAllForWorkflow(effKey); + // Clear stale in-memory state to prevent orphaned branches + lastCapturedIdMap.delete(effKey); + lastCapturedHashMap.delete(effKey); + lastGraphDataMap.delete(effKey); + activeSnapshotId = null; + currentSnapshotId = null; + activeBranchSelections.clear(); pickerDirty = true; if (lockedCount > 0) { showToast(`Cleared snapshots (${lockedCount} locked kept)`, "info");