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

45 lines
1.4 KiB
TOML

[package]
name = "agent-core"
version.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true
description = "Base agent runtime for the agent-economy apps (Turnstile/Abacus): rig Agent over Relay + the AITP-402 payment seam."
[dependencies]
rig-core.workspace = true
relay-provider.workspace = true
aitp-client.workspace = true
thiserror.workspace = true
tracing.workspace = true
anyhow.workspace = true
# The capture journal (JSON lines).
serde.workspace = true
serde_json.workspace = true
hex.workspace = true
async-stream.workspace = true
futures-util.workspace = true
# `time` is required by the capture reconciler's bounded-backoff retry loop.
tokio = { workspace = true, features = ["time"] }
async-trait = { workspace = true, optional = true }
[features]
# Enables the runnable `agent-runtime-demo` binary, which drives the direct-Mint
# paid path (and the capture reconciler) against the in-process fake Mint using
# rig's mock completion model. Off by default so normal builds stay lean.
demo = ["rig-core/test-utils", "dep:async-trait"]
[[bin]]
name = "agent-runtime-demo"
required-features = ["demo"]
[dev-dependencies]
async-trait.workspace = true
rig-core = { version = "=0.39.0", default-features = false, features = [
"reqwest",
"rustls",
"derive",
"test-utils",
] }
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread", "time"] }