fix(core): re-arm flush timer after retryable flush failure

When flushAgentLogBuffer() requeues valid entries on transient failure,
the timer was cleared but never re-armed, leaving entries in memory
indefinitely. Now schedules a retry after AGENT_LOG_FLUSH_MS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Timothy Laurent
2026-05-04 12:10:21 -07:00
parent 2800c3cd21
commit 1dea08ebc4

View File

@@ -4857,6 +4857,17 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
// Stale rows were already filtered out above.
if (!flushSucceeded && validEntries.length > 0) {
this.agentLogBuffer.unshift(...validEntries);
// Re-arm the flush timer so retried entries don't sit in memory forever.
if (!this.agentLogFlushTimer) {
this.agentLogFlushTimer = setTimeout(() => {
try {
this.flushAgentLogBuffer();
} catch (err) {
console.error(`[fusion] Retry agent log flush failed (${this.db.path}):`, err);
}
}, TaskStore.AGENT_LOG_FLUSH_MS);
this.agentLogFlushTimer.unref();
}
}
}
}