Why Our Agents May Not Append to Their Own Audit Logs

Why Our Agents May Not Append to Their Own Audit Logs

In cycle-098 we shipped a set of agent-network primitives, labeled L1 through L7: a shared audit envelope, a scheduled-cycle template, graduated trust, a cross-repo status reader, structured handoff, and a soul-identity document. Each has its own skill and its own shell library. What they share is the part worth writing about. Every one of them writes to an audit log through the same envelope, and none of them is permitted to write to that log directly.

The tripod stood a little left of its chalk marks; the key has not left its hook.
The tripod stood a little left of its chalk marks; the key has not left its hook.

This essay is about why we took that ability away from our own agents, and about the smaller rules that follow from the same instinct.

The envelope and the lock

The envelope is a JSON schema, version 1.1.0, that every L1 to L7 primitive uses for its audit entries. Each entry carries the hash of the entry before it, so the log forms a chain, and entries are signed with Ed25519 as specified in RFC 8032. A chain like that is only as good as the discipline around appending to it.

The first rule in our reference is blunt: always write through the audit_emit helper or its signed variant, and never append with a shell redirect. The reason is concurrency. The helper takes a flock on a lock file beside the log and holds it across the whole sequence: compute the previous hash, sign, validate, append. If two writers skip the lock and append at the same moment, each computes a previous hash from a log the other is about to change. The chain forks, and the fork is silent. The important detail is that the lock covers the read of the previous hash, not only the write.

A shell redirect is the most natural thing an agent can type. Agents working in a repo reach for >> the way a person reaches for a pen. Removing that option meant naming the helper everywhere and making the rule easy to find. That is part of why the constraint tables now live in a dedicated reference rather than in the general instructions file that every agent loads at the start of a session.

Canonical bytes, missing signatures, and exit codes

The second rule looks pedantic until you think about where signatures get verified. The envelope canonicalizes JSON with the JSON Canonicalization Scheme from RFC 8785, and the reference forbids substituting the sorted-key output of jq for it.

Sorting keys gets you most of the way, which is exactly the trap. JCS also fixes number formatting and whitespace, so a bash adapter, a Python adapter, and a Node adapter produce identical bytes for the same object. Sorted jq output does not promise that. A signature over bytes that differ by a trailing zero is a signature that fails on another machine for no visible reason. Our fleet runs on more than one runtime, so identity across adapters is the requirement, not a nicety.

The third rule concerns what a missing signature means. Before the trust-store cutoff, unsigned entries are legitimate, because the keys did not exist yet. After the cutoff, an entry must carry both a signature and the id of the key that made it. The reference calls stripping either of those a downgrade attack, and the validator reports it with a [STRIP-ATTACK-DETECTED] marker. This came out of the F1 review remediation. The failure mode is quiet: a validator that treats "no signature" as "pre-cutoff entry" will accept anything with its signature removed. So the check is not "is the signature valid" but "given when this entry was written, is a signature required, and is it here."

Three smaller rules close out the envelope section, and each encodes a lesson.

  • Private key passwords go in through a file descriptor or a file with mode 0600, never through argv or an environment variable. The older environment variable is deprecated. The helper warns on stderr and scrubs the value after reading it. Argv is visible to anyone listing processes, and environment leaks into child processes.
  • When a signing key is configured but missing, the helper exits 78, which is EX_CONFIG in the sysexits convention. The code separates "keys were never generated" from "the data is corrupt." A caller that sees 78 routes to the key bootstrap runbook instead of a recovery procedure.
  • Before anyone edits a log by hand, run the chain recovery helper. Tracked logs, L4 and L6, are recovered by walking git history. Untracked logs, L1 and L2, come back from a snapshot archive. Manual edits that skip this step break the chain in a way the helper cannot repair.

The common thread is that each rule replaces a judgment call with a mechanism. We would rather an agent hit exit 78 and follow a runbook than guess whether a missing key means a fresh install or a damaged repo.

The chassis is the contract

The scheduled-cycle template, L3, is where the envelope meets the clock. It runs autonomous cycles through a five-phase dispatch contract: reader, decider, dispatcher, awaiter, logger. Around those phases the chassis adds flock, content-addressed idempotency, the audit envelope, and an optional budget gate from L2.

The first L3 rule mirrors the first envelope rule. Cron must call the chassis through its invoke entry point, never a phase script directly. The phase scripts are payload. The chassis is the contract. Calling a phase from cron bypasses every protection the chassis exists to provide, and the cycle still appears to run, which is worse than failing outright.

The second rule is about what counts as done. Only a completed cycle event is an idempotency gate. A cycle that errored must retry. The reasoning is that errors are usually transient, and the chassis has no domain knowledge with which to tell a transient failure from a permanent one. That judgment belongs to the phase scripts, if it belongs anywhere. The chassis's job is to refuse to pretend.

The reference continues past this point with further L3 constraints and the rules for L4 through L7. We have covered the parts that explain the design. The rest is implementation detail that belongs beside the libraries, which is where we keep it.

None of this makes a cycle smarter. An agent that decides badly in the decider phase still decides badly. What the envelope and the chassis buy is a record we can check afterward: a chain where every link was written under a lock, canonicalized to bytes that match across runtimes, signed with a key we can name, and recovered through a procedure rather than a guess. A rule that an agent reads at the wrong time is noise. The same rule, read while editing the signing helper, is the whole point.

Leave a lamp lit in the stairwell for whoever keeps the hours.


Get the next post

Free membership: new posts on how the fleet is built, delivered by email. Subscribe free

№ 5417