Local history
How DefenseClaw keeps every collected log in a local SQLite store, how retention by days and by size works, how to compact audit.db, and the store's limits.
One generated local-sqlite destination stores every collected log in audit.db, in the DefenseClaw data directory. It cannot be disabled or filtered. It also holds the mandatory floor: a small set of content-free compliance events that is always written, even when you turn off collection for their bucket, and is never exported.
observability:
local:
path: ~/.defenseclaw/audit.db
judge_bodies_path: ~/.defenseclaw/judge_bodies.db
retention_days: 7Settings
| Setting | Default | Behavior |
|---|---|---|
local.path | ~/.defenseclaw/audit.db | Must resolve inside the DefenseClaw data directory; doctor reports an outside path as a custody failure. A ~ or relative path is resolved against the data directory. Changing it needs defenseclaw-gateway restart. |
retention_days | 7 | Days of history to keep. 0 keeps history forever, and doctor warns about capacity. |
max_store_mb | 0 (off) | A size cap for audit.db, 64 MiB or more. See Size cap. |
keep_rejected_records | false | Keep each record the schema gate refuses. See Rejected records. |
rejected_records_max_rows | 10000 | Row cap of the rejected-records table, 100 to 1000000. |
judge_bodies_path | ~/.defenseclaw/judge_bodies.db | Raw LLM-judge request and response text, kept while guardrail.retain_judge_bodies is true (the default). Redaction profiles do not apply. Turn it off with defenseclaw config set guardrail.retain_judge_bodies false, then restart the gateway. |
A running gateway applies changes to retention_days, max_store_mb and the rejected-records keys without a restart.
How retention runs
- A reaper runs a minute after startup and every six hours, and deletes in small batches, the correlation tables (
correlation_*) included. - A session or tool call still marked active but unchanged for the whole window counts as ended (for example an agent killed without a session end), so it no longer keeps its history.
- A live session keeps only the correlation graph of the window, plus its cursor's last event and its open tool or model calls.
- The same window prunes AI discovery scan history and unseen agent identities (
agt-) ininventory.db. The newest scan is always kept.doctorwarns at 1 GiB. - A retention run that fails shows
retention_state: degradedandretention_failure: run_failed, and the gateway log names the cause (the service journal on a managed computer). The run is tried again after a minute, then after waits that double up to 30 minutes, and at once after the next change to the retention settings.
Size cap
max_store_mb caps the size of audit.db on top of retention by days:
- When the used pages pass nine tenths of the cap, the reaper deletes the oldest eligible history, down to seven tenths of the cap.
- The cap wins over the age of the history: under a flood it deletes inside the newest hour too.
- With a cap, the gateway checks the size every 30 seconds (it reads page counts only) and runs a pass when it is near the cap.
defenseclaw status shows it with the retention (7 days, size cap 64 MiB). On a managed computer defenseclaw-gateway status shows it on the Telemetry retention: line, and enterprise linux status or enterprise macos status on the audit store retention: line (audit_store in --json, with the size on disk). Managed command availability lists the commands a managed computer offers.
If a completed pass still leaves the used pages above the cap, gateway health reports retention_state: warning, retention_cap_used_bytes, retention_cap_bytes and a bounded retention_cap_reason. defenseclaw status, defenseclaw doctor and defenseclaw-gateway status show the size, cap, reason and one suggested step. Active correlation state can cause it: end unused sessions, or raise max_store_mb. The warning does not block tool calls, and a later pass that meets the cap clears it.
Rejected records
With keep_rejected_records: true, each record the v8 schema gate refuses (a field value outside its family contract) is kept in the rejected_records table of audit.db, instead of only being counted.
- Each row has the time, signal, family and event name, the reason code, the field that failed, the error, and a copy of the record's fields (16 KiB at most; a larger copy keeps only the field names).
- The copy is redacted per field class with the stricter of the
sensitiveprofile and the local profile of the record's bucket. Only the redacted copy is written. - The gateway writes rows in the background through a bounded queue. When the queue is full a record is dropped and counted, never waited for.
rejected_records_max_rowscaps the table: the oldest rows go first, at once when you lower it.retention_daysandmax_store_mbprune it with the other history.
Read the records with defenseclaw audit rejected [--since 1h] [--limit 100] (JSON lines, newest first).
Audit database size
Retention deletes old rows, but SQLite does not shrink audit.db by itself. defenseclaw doctor shows the size and the deleted space it still holds (Audit database size). To give that space back:
defenseclaw audit compact --dry-run # what it would reclaim; the gateway can keep running
defenseclaw-gateway stop
defenseclaw audit compact
defenseclaw-gateway startcompactkeeps every row. It needs free disk space of about twice the live data next toaudit.db, and refuses, with the numbers, when the disk is short.- Before it rewrites the store it runs SQLite's integrity check. A damaged store is left as it is, and
doctornames the repair. - After one run the store uses incremental
auto_vacuum, so retention gives later deletes back on its own. - While it runs the store is locked, so start the gateway only after
compactreturns.
On a managed computer an administrator stops the gateway service (on Linux, its two sockets too), runs defenseclaw-gateway audit compact as root (or from an elevated PowerShell prompt), and starts the service again. While the service is stopped, hooks block agent tool calls unless the administrator set hook_fail_mode: open, and an ensure run in that window can fail and roll back; run it again after the start.
Write-ahead log
The gateway checks the write-ahead log (audit.db-wal) every two seconds, copies it into audit.db, and trims the file when idle. Under load:
| Active log size | What the gateway does |
|---|---|
| 88 MiB | Copies and syncs the log without holding the audit writer until little is left, then holds the writer for up to 45 ms to restart the log (up to 180 ms once the log is past 132 MiB). |
| 176 MiB | If the log still passes this size, ordinary catch-up holds the audit writer for up to 100 ms. |
| 208 MiB | A flooded log can use one fixed hold of up to 470 ms to restart before the 256 MiB ceiling. |
| Over 256 MiB after a check | The gateway warns, repeats the warning every ten minutes while it stays over, and reports when it falls back under. |
After a missed pass only the wait to acquire the writer grows, from 1 second up to 10 seconds; the hold cap never grows. A SQLite statement can run past that hold, delaying hook answers. A slow disk or long-lived reader can still push the file past 256 MiB: this is an alarm threshold, not a guaranteed disk bound. The defenseclaw.sqlite.wal.bytes metric reports the file size.
Failed writes
If a write to local history fails, for example on a full disk, the record still goes to destinations, and health counts it as dropped on local-sqlite. When writes resume, the gateway writes one sqlite.write_failed record with the number of missing records.
The count survives a crash in local-write-losses.journal in the data directory (64 KiB, reserved in advance, counts and failure classes only). If the journal cannot be written, status and doctor report the in-memory count.
Limits
- Local history is authoritative against other OS accounts: they cannot change it. It is not tamper-proof against its own account, which owns the files. Use a remote SIEM or collector as the system of record, and deduplicate on the record ID.
- A metric recorded during a hook call (hook invocations, latency and outcome, inspect counts, lifecycle gauges) writes no correlation row of its own. A local correlation graph or timeline query lists the call's log records, not its metric points. Exported metrics are not affected.
- On a per-user macOS install, idle gateway memory can grow gradually with the audit store. Retention bounds the stored history; memory may be returned gradually.
- A standalone install stores the field classes of a record (the redaction class of each field) once per set in
audit.db, and each row names its set by digest. The row hash and signature cover that digest, so a row whose set is missing or changed fails the integrity check. Destinations still get the full record.
Destinations and delivery
Send DefenseClaw logs, traces and metrics to an OTLP collector or other destination, narrow what each gets with send and routes, and tune queues.
End-user identity
Learn how DefenseClaw attributes telemetry to endpoint users and agents, which identity facts are verified or claimed, and how to opt in to email.