fix(core): fail-fast on corruption, preserve buffer on transient errors

- Throw from init() when integrity check fails and recovery doesn't help,
  preventing writes to a known-corrupt database
- Only drain buffer on successful flush; requeue valid entries on transient
  failures (busy/IO) so they aren't silently lost
- Add spy on flushAgentLogBuffer in deleteTask test to prove flush-before-delete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Timothy Laurent
2026-05-03 21:39:08 -07:00
parent a5a87022c1
commit 3a93758dc4
3 changed files with 27 additions and 4 deletions

View File

@@ -4917,8 +4917,11 @@ Task with acceptance criteria
const task = await createTestTask();
await store.appendAgentLog(task.id, "to be cascaded", "text");
// deleteTask should flush first, then cascade-delete the entry
// Prove flush happens before delete
const flushSpy = vi.spyOn(store as any, "flushAgentLogBuffer");
await store.deleteTask(task.id);
expect(flushSpy).toHaveBeenCalled();
flushSpy.mockRestore();
const after = (store as any).db.prepare(
"SELECT COUNT(*) as count FROM agentLogEntries WHERE taskId = ?",