feat(audit,cli): signed chain-head snapshot and raw chain export for external anchoring
Summary
Add two read-only, admin-scoped audit operations:
audit.heads(astrid audit heads): a snapshot of every audit chain's head (session, principal, retained count, cumulative pruned count, head content hash), signed by the runtime key over a fixed, versioned byte layout, so an external party can verify it without Astrid's Rust types.audit.export(astrid audit export --session … [--agent …]): paged export of one chain's stored entries with their previous hash, content hash, signature, embedded public key and exact signing bytes. The gateway view strips these today.
Both are exempt from the generic per-call AdminRequest success row, so a
poller does not grow the log it reads. Denied calls are still recorded.
This is the "chain head publication … for external archival" follow-up that #678 names as out of scope, and the admin read path #678 anticipates for remote-CLI verification.
Motivation
The audit chain is tamper-evident only against parties who do not hold the
runtime key. The operator, or anyone with the key file, can truncate a chain
or rewrite and re-sign it, and every local check still passes. The standard
remedy is to publish chain heads to an independent witness that the operator
cannot rewrite. docs/astrid-audit-store-anchoring.md already specifies signed
chain-head statements, anchored locally. These two operations are the missing
interface for doing the same externally.
Our use: AOS ("Unicity Audit" in aos-ce) anchors each head snapshot on the Unicity aggregator. The aggregator stores one value per state id, so a node's anchored history cannot fork. An independent verifier then:
- walks the anchored checkpoints;
- uses
audit.exportto confirm that the live chains still contain the anchored heads.
The whole flow is operator-agnostic and needs only these two operations.
Evidence (Unicity testnet2, patched 2026.9.4 under aos-ce main):
- head snapshots certified in 1.5–2.4 s;
- a store rolled back to an older backup and regrown with different entries is detected at the anchored position;
- a replacement checkpoint for an already-certified position is refused.
The implementation, tests and verifier are ready to share.
Proposed Implementation
Implemented on a branch (unicity-aos/astrid:feat/audit-heads-export,
based on 2026.9.4):
- astrid-audit
heads_snapshot(), which reads each chain's metadata and latest prune receipt together, holding the durable append lock only for those two reads, and re-reads the head entry to confirm it hashes to the recorded head;chain_entries_page(), with a cursor bound to its chain;- a persistent per-chain
omitted_totalcounter, raised in the same metadata CAS that lowers the retained count on prune.
- astrid-core: request and response types and
AuditHeadsSnapshot::signed_bytes_v1.- The layout is length-prefixed and big-endian: domain
astrid.audit.heads.v1, snapshot time in ns, then per chain, sorted: session, principal or none, count,omitted_total, head hash. - Signing is Ed25519 over the bytes directly, and a known-answer vector is included.
- The layout is length-prefixed and big-endian: domain
- astrid-kernel: handlers, capability mapping (
audit:heads,audit:export) and the self-audit exemption. - astrid-uplink, astrid-cli: the client and the
astrid audit heads/astrid audit exportcommands; e2e manifest entries.
Tests cover:
- the byte-format vector;
- chain listing across sessions and storage pages;
omitted_totalacross several prunes and reopen;- cursor paging and rejected cursors;
- signature and head verification in the handler;
- the self-audit exemption through the real IPC path.
We're happy to adapt names, layout or capability scope to your conventions, or for you to author the restricted-crate parts from this design.
Alternatives Considered
- Wait for #1759 (native ordered audit root and verifier handoff). That is the long-term root of trust for the native kernel. It covers native mechanics, not the hosted runtime AOS ships today, and it excludes a public interface. The two operations here are small and hosted-runtime only, and could later emit the #1759 root in place of per-chain heads.
- Read the audit store from disk outside the daemon. This breaks the non-circular boundary and remote-CLI mode, and needs the store's internal format. (#678 already prefers an admin IPC topic.)
- Publish heads from a capsule without kernel support. A capsule cannot read the audit store, and a capsule-built snapshot would not carry the runtime key's signature.
Related
- #678 (
astrid audit verify): this supplies its admin read path and the head-publication follow-up. - #675 (audit routing, admin query topics).
- #693 (signed audit-derived receipts).
- #1759 (native audit root).
docs/astrid-audit-store-anchoring.md.- Follow-ups we would propose separately, after discussion: recording LLM/HTTP requests, approvals and capability grants as audit entries (none are written today), and signing the full outcome.
Part of #1997.
Source: astrid-runtime/astrid