Skip to main content

Module usage_ledger

Module usage_ledger 

Source
Expand description

Per-credential usage accounting (PRD-001s AC-08).

A provider call is billed at most once per (request id, attempt id). The router may retry an attempt (budget-gated 429 recovery), and a dispatch that fails ambiguously may be re-driven; without an idempotency boundary a single logical provider interaction could be metered twice. This ledger keys usage records by (request_id, attempt_id) so that the billing authority sees exactly one metered record per attempt, regardless of how many times the daemon re-presents the attempt result to the ledger.

The ledger is append-only per key. insert returns whether the key was new (a duplicate is a no-op, so the caller can skip a second deduction). Rows carry a monotonic timestamp and expire after a configurable TTL so a long-lived daemon does not accumulate unbounded state; eviction is lazy on access and explicit via sweep_expired.

Structs§

InsertOutcome
UsageLedger
UsageRecord

Constants§

DEFAULT_USAGE_LEDGER_MAX_RECORDS
Default cap on distinct usage records retained by a ledger. When the cap is exceeded the oldest recorded attempts (by recorded time) are evicted.
DEFAULT_USAGE_LEDGER_TTL