From 8837751ad823bb1b82c2f5ec0bf2251090709d24 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:57:17 -0700 Subject: [PATCH] fix(persistence): schedule automation state writes --- src/main/persistence/loading-store/store.ts | 2 ++ .../automation-definition-operations.ts | 4 ++++ .../scheduling-automations/automation-run-operations.ts | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/main/persistence/loading-store/store.ts b/src/main/persistence/loading-store/store.ts index 7dcd26e89ac..48be6a6e083 100644 --- a/src/main/persistence/loading-store/store.ts +++ b/src/main/persistence/loading-store/store.ts @@ -2617,6 +2617,7 @@ export class Store { return { state: this.state, flush: () => this.flush(), + scheduleSave: () => this.scheduleSave(), recordCreated: () => this.recordFeatureInteraction('automation-created') } } @@ -2625,6 +2626,7 @@ export class Store { return { state: this.state, flush: () => this.flush(), + scheduleSave: () => this.scheduleSave(), recordManualRun: () => this.recordFeatureInteraction('automation-run'), getWorkspaceDisplayName: (workspaceId) => this.getAutomationRunWorkspaceDisplayName(workspaceId) diff --git a/src/main/persistence/scheduling-automations/automation-definition-operations.ts b/src/main/persistence/scheduling-automations/automation-definition-operations.ts index 677655c575e..4b30177b5b6 100644 --- a/src/main/persistence/scheduling-automations/automation-definition-operations.ts +++ b/src/main/persistence/scheduling-automations/automation-definition-operations.ts @@ -18,6 +18,7 @@ import { export type AutomationDefinitionOperations = { state: StoreOwnedPersistedState flush: () => void + scheduleSave: () => void recordCreated: () => void } @@ -67,6 +68,7 @@ export function createAutomation( updatedAt: now } operations.state.automations = [...(operations.state.automations ?? []), automation] + operations.scheduleSave() operations.recordCreated() operations.flush() return automation @@ -151,6 +153,7 @@ export function updateAutomation( updatedAt: Date.now() } operations.state.automations[index] = updated + operations.scheduleSave() operations.flush() return updated } @@ -162,5 +165,6 @@ export function deleteAutomation(operations: AutomationDefinitionOperations, id: operations.state.automationRuns = (operations.state.automationRuns ?? []).filter( (entry) => entry.automationId !== id ) + operations.scheduleSave() operations.flush() } diff --git a/src/main/persistence/scheduling-automations/automation-run-operations.ts b/src/main/persistence/scheduling-automations/automation-run-operations.ts index f83117edf8b..91991e5ebe0 100644 --- a/src/main/persistence/scheduling-automations/automation-run-operations.ts +++ b/src/main/persistence/scheduling-automations/automation-run-operations.ts @@ -22,6 +22,7 @@ import { export type AutomationRunOperations = { state: StoreOwnedPersistedState flush: () => void + scheduleSave: () => void recordManualRun: () => void getWorkspaceDisplayName: (workspaceId: string | null | undefined) => string | null } @@ -85,6 +86,7 @@ export function createAutomationRun( if (trigger === 'manual') { operations.recordManualRun() } + operations.scheduleSave() operations.flush() return run } @@ -139,6 +141,7 @@ export function updateAutomationRun( automation.lastRunAt = now automation.updatedAt = now } + operations.scheduleSave() operations.flush() return updated } @@ -161,6 +164,7 @@ export function snapshotAutomationRunWorkspaceDisplayName( return { ...run, workspaceDisplayName: normalizedDisplayName } }) if (updatedCount > 0) { + operations.scheduleSave() operations.flush() } return updatedCount