# Audit log (/docs/operate/audit)



Every change to what a project runs or who can touch it leaves an audit line: publications,
deployments, approvals and imports with what they pinned, and — through one declarative
middleware (`services/audit.ts`) — creating, changing or deleting decisions, tables, datasets,
test cases, API keys, credentials, connections, webhooks, environments, experiments, members and
invitations, with the request fields worth keeping and never a secret.

**Draft saves are not audited** — the editor autosaves.

Project admins read it in **Audit log**, filtered by entity, action, actor and date
(`GET /audit-logs`).

## Tamper evidence [#tamper-evidence]

Executions are the audit trail of every decision, so each project's executions form a
**hash chain**. A few seconds after an execution is written, the worker seals it as link *n*:

```
SHA-256(link n-1 ‖ n ‖ canonical JSON of the record)
```

…where the record is input, output, trace, reasons, actions, error, version, environment and time,
with sorted keys. Sealing never touches the execute path.

Changing, removing or reordering a sealed execution breaks every link after it. **Verify**
(`GET /audit-logs/chain`) recomputes the chain and names the first broken link. Deleting a
decision deletes its executions, which the verification reports as missing links; executions
removed by retention simply move the start of the chain.

When a person's data is erased (Settings → Data protection), the execution keeps its row and its
link but its content becomes a tombstone, so that one link can no longer be recomputed. The
verification takes it as stored and reports how many it took that way (`erased`); the link after
it is still computed from it, so altering it or removing a record is still detected. In the
executions export an erased record carries `"erased": true`, and an offline verifier should treat
its `chain_hash` as given instead of recomputing it.

## Compliance exports [#compliance-exports]

Exports for compliance (`audit.read`):

* The audit log (`/audit-logs/export`, with the list's filters).
* The sealed executions (`/audit-logs/executions/export`, in chain order, with `chain_seq`,
  `chain_hash` and the trace, so the chain can be recomputed offline from the file alone).

Both ship as CSV or JSONL, up to `AUDIT_EXPORT_MAX_ROWS`. Each ends with a manifest — kind,
filters, row count, the SHA-256 of everything before it, the chain range it covers — as the last
JSONL line or, for CSV, the `x-export-manifest` header.

With `AUDIT_SIGNING_KEY` (Ed25519, PKCS#8 PEM) the manifest is signed
(`x-export-signature`, Ed25519 over its canonical JSON) and the public key is shown next to the
verification. Every export is itself audited.
