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 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 13:25:27 +01:00
parent f9bdc75a2a
commit 01e09949fb

View File

@@ -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");