feat(FN-5143): clear agent logs when task is soft-deleted

Clears agent logs when a task is soft-deleted, with new regression tests covering the end-to-end behavior and documentation updated in the storage guide. The core logic lives in `store.ts` while `store-upsert.test.ts` is updated to reflect the new expectations.

Fusion-Task-Id: FN-5143
This commit is contained in:
Fusion (runfusion.ai)
2026-05-20 09:27:35 -07:00
committed by gsxdsm
parent 5696823eaa
commit 321c170b90
4 changed files with 173 additions and 4 deletions

View File

@@ -6301,9 +6301,24 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
},
});
this.clearLinkedAgentTaskIds(id, deletedAt);
// FN-5143: clear historical agent logs for the soft-deleted task so
// downstream readers (evaluator evidence, self-healing diagnostics,
// dashboard log views, register-task-workflow-routes) observe zero logs
// immediately after deletedAt is set. Atomic with the deletedAt write.
this.db.prepare("DELETE FROM agentLogEntries WHERE taskId = ?").run(id);
this.db.bumpLastModified();
});
// FN-5143 defense-in-depth: drop any in-memory buffer entries for this
// task. flushAgentLogBuffer() above already ran inside the lock, but a
// concurrent appendAgentLog from another async path could re-buffer
// before this lock releases; the next flush would still drop them via
// ACTIVE_TASKS_WHERE, but filtering here avoids the warn log and keeps
// memory bounded.
if (this.agentLogBuffer.length > 0) {
this.agentLogBuffer = this.agentLogBuffer.filter((entry) => entry.taskId !== id);
}
// Remove from cache if watcher is active
if (this.isWatching) this.taskCache.delete(id);