From 69c83f22db741be674a2deba68293ef4a229cf2d Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:56:50 -0800 Subject: [PATCH] fix(persistence): keep the whole-row fallback for replaced run lists A run list replaced outside the run-delta path (catalog import, SSH re-adoption) saves as a whole row again, so histories that can't use the per-run storage still save. A failed in-flight run write restores its pending list only while that list is still current; otherwise it marks the run domain for a whole-row save. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../loading-store/primary-state-write-worker.ts | 10 +++++++++- src/main/persistence/loading-store/write-scheduling.ts | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/persistence/loading-store/primary-state-write-worker.ts b/src/main/persistence/loading-store/primary-state-write-worker.ts index 6a67aa73cb2..de3cef861c9 100644 --- a/src/main/persistence/loading-store/primary-state-write-worker.ts +++ b/src/main/persistence/loading-store/primary-state-write-worker.ts @@ -23,7 +23,15 @@ export async function writeProfileStateInWorker( runtime.dirtyProfileStateDomains.add(domain) } } - runtime.pendingAutomationRunsAfter ??= automationRuns + if (automationRuns === undefined || runtime.pendingAutomationRunsAfter !== undefined) { + return + } + // A run list replaced while this write was in flight is newer; save it as a whole row instead. + if (automationRuns === runtime.state.automationRuns) { + runtime.pendingAutomationRunsAfter = automationRuns + } else { + runtime.dirtyProfileStateDomains?.add('automationRuns') + } } try { diff --git a/src/main/persistence/loading-store/write-scheduling.ts b/src/main/persistence/loading-store/write-scheduling.ts index ea9aa4c32a7..8fe46224898 100644 --- a/src/main/persistence/loading-store/write-scheduling.ts +++ b/src/main/persistence/loading-store/write-scheduling.ts @@ -117,9 +117,12 @@ function scheduleDomainSave( listener(dirtyDomains) } runtime.automationListProjectionCache = null - // A named automationRuns save supersedes older run lists, including one a failed in-flight write restores. - if (dirtyDomains?.includes('automationRuns')) { - runtime.pendingAutomationRunsAfter = runtime.state.automationRuns + // A run list replaced outside the run-delta path saves as a whole row; an older pending delta is stale. + if ( + dirtyDomains?.includes('automationRuns') && + runtime.pendingAutomationRunsAfter !== runtime.state.automationRuns + ) { + runtime.pendingAutomationRunsAfter = undefined } const trackedDomains = runtime.dirtyProfileStateDomains if (dirtyDomains === undefined) {