caelum0x 627e499e73 fix(agent-runtime): owed captures survive a crash (durable capture journal)
The capture reconciler kept captures that failed after the provider served
the request in memory only: a crash lost them, and with them the operator's
revenue. MintPaymentGateway also kept each hold's payee and idempotency base
in memory, so even a persisted capture could not be settled after a restart.

- agent-core journal: CaptureJournal and FileCaptureJournal, an append-only
  JSON-lines file fsynced per entry and compacted on open (atomic rename); a
  torn last line is dropped, earlier corruption is an error.
- CaptureReconciler::with_journal records every queued, attempted, settled
  and dead-lettered capture before acting, reopens with what is still owed
  (and the dead letters), and resume() restarts the retry loops.
- PaymentGateway gets hold_context/restore_hold_context (defaults: nothing);
  MintPaymentGateway exports and restores its payee and idempotency base, so
  a restored capture uses the same deterministic key.

Tests: journal replay/compaction/torn tail/corruption, owed captures settled
after a restart and not owed again, dead letters persisted and resume()
retrying the rest, gateway capture after context restore. 68 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 15:51:37 +03:00
..