@@ -8,11 +8,11 @@ const STORE_KEY = 'terminal-console-store'
88const MIGRATION_KEY = 'terminal-console-store-migrated'
99
1010/**
11- * Safety-net interval for persisting during very long executions.
12- * Only fires while an execution is active. Much longer than a debounce
13- * because intermediate writes during execution are low-value .
11+ * Interval for persisting terminal state during active executions.
12+ * Kept short enough that a hard refresh during execution still has
13+ * recent running entries persisted for the reconnect flow to find .
1414 */
15- const LONG_EXECUTION_PERSIST_INTERVAL_MS = 30_000
15+ const EXECUTION_PERSIST_INTERVAL_MS = 5_000
1616
1717/**
1818 * Shape of terminal console data persisted to IndexedDB.
@@ -129,6 +129,7 @@ class ConsolePersistenceManager {
129129 private dataProvider : ( ( ) => PersistedConsoleData ) | null = null
130130 private safetyTimer : ReturnType < typeof setTimeout > | null = null
131131 private activeExecutions = 0
132+ private needsInitialPersist = false
132133
133134 /**
134135 * Binds the data provider function used to snapshot current state.
@@ -144,11 +145,23 @@ class ConsolePersistenceManager {
144145 */
145146 executionStarted ( ) : void {
146147 this . activeExecutions ++
148+ this . needsInitialPersist = true
147149 if ( this . activeExecutions === 1 ) {
148150 this . startSafetyTimer ( )
149151 }
150152 }
151153
154+ /**
155+ * Called by the store when a running entry is added during an active execution.
156+ * Triggers one immediate persist so the reconnect flow can find running entries
157+ * after a page refresh, then disables until the next execution starts.
158+ */
159+ onRunningEntryAdded ( ) : void {
160+ if ( ! this . needsInitialPersist ) return
161+ this . needsInitialPersist = false
162+ this . persist ( )
163+ }
164+
152165 /**
153166 * Signals that a workflow execution has ended (success, error, or cancel).
154167 * Triggers an immediate persist and stops the safety timer if no executions remain.
@@ -174,7 +187,7 @@ class ConsolePersistenceManager {
174187 this . stopSafetyTimer ( )
175188 this . safetyTimer = setInterval ( ( ) => {
176189 this . persist ( )
177- } , LONG_EXECUTION_PERSIST_INTERVAL_MS )
190+ } , EXECUTION_PERSIST_INTERVAL_MS )
178191 }
179192
180193 private stopSafetyTimer ( ) : void {
0 commit comments