Skip to content

feat(audit): retry, dead letters, and a file sink - #34

Merged
blakebauman merged 1 commit into
mainfrom
feat/audit-reach
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/audit-reach

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Roadmap Horizon 1 item 4, less the otlp-logs sink — that brings a new dependency (the OTel logs SDK) and gets its own change, so this one stays reviewable.

The problem

Audit is fold's single exit door — one event per terminal response, denials included — and it shipped as stdout or a webhook that tried once and gave up. A receiver restarting for thirty seconds cost every event in that window, silently. That is the opposite of what an audit trail is for.

Delivery

  • Retry with exponential backoff and equal jitter: 4 attempts, 500 ms → 30 s, on by default. Not opt-in, because the old behavior was a defect rather than a policy anyone chose.
  • Jitter matters at fleet scale: every instance watches the same receiver and fails at the same instant, so unjittered retries turn a stumble into a synchronised stampede just as it recovers.
  • Equal jitter, not full. Full jitter around the delay overshoots the cap by 50% — a cap that doesn't cap. My first implementation had exactly that bug; the test asserting the bound caught it at attempt 4 (925 ms against an 800 ms cap).
  • A 4xx other than 429 is permanent and not retried: a receiver that rejects the payload rejects it identically four times.

Dead letters and the file sink

What delivery finally abandons goes to deadLetterPath, one JSON event per line, for replay. Without one, exhausted events are counted and gone — visible rather than silent.

The file sink is both a destination and the dead letter's machinery: JSON lines, size-based rotation that renames in place so a tail -F or log shipper watching the live name survives it, bounded at 100 MB × 5 (an audit sink that fills the disk turns a recording problem into an outage). Hand-rolled rather than depended on — the requirement is "append lines, don't fill the disk", and a library whose feature set is compression and cleanup schedules is a bigger surface than the problem. Directory 0o750, file 0o600: these records name principals and the tools they invoked.

Visibility

fold_audit_events_total{sink,outcome} counts delivered / retried / dead_lettered / dropped, with a FoldAuditEventsLost alert on the last two — the audit trail is the one system that cannot report its own gaps.

Notably, the observability pack's lockstep test refused the new metric until it had a panel and an alert. That is precisely what it was built to do, and it's the second time this session it's paid for itself.

A sink that won't construct is logged and skipped rather than fatal; StartupErrors() gives the caller the words to say so.

Verification

make check green (lint 0 issues), make helm-check green. Nine new tests covering recovery-after-failure, permanent-rejection, dead-letter contents, counted drops with no dead letter, file writing, rotation bounds and live-name preservation, unopenable sinks, and the backoff bound/jitter properties.

Two gosec findings handled deliberately rather than uniformly: G301 tightened the directory to 0o750 (a fair catch), G404 annotated with a reason (jitter spreads retries in time; it isn't generating a secret).

🤖 Generated with Claude Code

Roadmap Horizon 1 item 4, less the otlp-logs sink, which brings a new
dependency and gets its own change.

Audit is fold's single exit door — one event per terminal response, denials
included — and it shipped as stdout or a webhook that tried once and gave up.
A receiver restarting for thirty seconds therefore cost every event in that
window, silently, which is the opposite of what an audit trail is for.

Delivery now retries with exponential backoff and equal jitter: four attempts
from 500ms to 30s by default, and on by default rather than opt-in, because
the previous behaviour was the defect and not a policy anyone had chosen. The
jitter matters at fleet scale — every instance watches the same receiver and
fails at the same instant, so unjittered retries turn a stumble into a
synchronised stampede against it as it recovers. Equal jitter rather than
full: full jitter around the delay overshoots the cap by half, which is a cap
that does not cap, and the test that asserts the bound is what caught it.

A 4xx other than 429 is permanent and not retried. A receiver that rejects the
payload will reject it identically four times; retrying only delays the dead
letter.

What delivery finally gives up on goes to deadLetterPath, one JSON event per
line, for replay. Without one, exhausted events are counted and gone — visible
rather than silent, which is the least the trail owes an operator.

The file sink lands as a destination in its own right and as the dead letter's
machinery: JSON lines, size-based rotation, renaming in place so a tail or a
log shipper watching the live name survives it, bounded at 100MB x 5 because
an audit sink that fills the disk turns a recording problem into an outage.
Hand-rolled rather than depended on: the requirement is "append lines, do not
fill the disk", and a library whose feature set is compression and cleanup
schedules is a larger surface than the problem. Directory 0o750, file 0o600 —
these records name principals and the tools they invoked.

fold_audit_events_total{sink,outcome} counts delivered, retried,
dead_lettered, and dropped, with the FoldAuditEventsLost alert on the latter
two, because the audit trail is the one system that cannot report its own
gaps. The observability pack's lockstep test refused the new metric until it
had a panel and an alert, which is exactly what it was built to do.

A sink that will not construct is logged and skipped rather than fatal: losing
one destination should not take the gateway down, and StartupErrors gives the
caller the words to say so.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit f64ce71 into main Aug 11, 2026
6 checks passed
@blakebauman
blakebauman deleted the feat/audit-reach branch August 11, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant