Add capture-in-progress guard to prevent duplicate snapshots

Concurrent captureSnapshot calls (e.g. manual Ctrl+S overlapping a
debounced auto-capture) could both pass the hash check before either
sets the hash, creating duplicates. A simple boolean flag now ensures
only one capture runs at a time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 11:48:45 +01:00
parent a1c6716ef6
commit e29e7dfad1

View File

@@ -1411,8 +1411,16 @@ async function showPreviewModal(record) {
// ─── Snapshot Capture ──────────────────────────────────────────────── // ─── Snapshot Capture ────────────────────────────────────────────────
let captureInProgress = false;
async function captureSnapshot(label = "Auto") { async function captureSnapshot(label = "Auto") {
if (restoreLock) return false; if (restoreLock) return false;
if (captureInProgress) return false;
captureInProgress = true;
try { return await _captureSnapshotInner(label); } finally { captureInProgress = false; }
}
async function _captureSnapshotInner(label) {
const graphData = getGraphData(); const graphData = getGraphData();
if (!graphData) return false; if (!graphData) return false;