#1999·astrid

fix(audit): make host-audit recording ordered and loss-accounted

Author: MastaPCreated Sep 28, 2026Updated Sep 28, 2026

Summary

Make host-call audit recording ordered and loss-accounted, so that a gap in the log is visible in the signed log itself.

Motivation

The host-audit sink (crates/astrid-kernel/src/audit_sink/mod.rs) is a bounded, asynchronous writer:

  • Coalescing: allowed events are coalesced per class over a host_coalesce_ms window.
  • Drops: when the pending queue (default 4096, audit_sink/mod.rs:70) is full, new events are dropped and only a queue_full health counter is incremented (audit_sink/mod.rs:314). Nothing is written to the chain.
  • Ordering: pending work is drained per key, so append order is not event order.
  • Fail-open: the fail-closed interceptor ("no audit, no action") was removed in 0.9.0.

As a result, even an externally anchored log (#1995) cannot show that it is complete. Missing events leave no trace, and related events can appear out of order.

Proposed Implementation

  • Ordering: an ordered per-chain evidence lane. Entries get their chain position and are signed when enqueued, not when drained.
  • Coalescing: keep it, but make it lossless. A coalesced record carries the count and a hash folded over the individual events.
  • Loss: a dropped event produces a signed loss record (class, count, time range). No event may disappear without trace.
  • Fail-closed classes: optionally, per-effect classes such as payments or irreversible writes, where the effect waits for the audit append. The default stays best-effort.

Alternatives Considered

  • Synchronous audit for everything. Simpler, but it puts audit latency on every host call.
  • Keep the counter-only health metric. It is operator-visible, but unsigned and not tied to the chain, so it can't support completeness claims.

Part of #1997.