Skip to content

fix(audit): persist audit chain to SQLite WAL store on every append (AUDIT-001) - #276

Merged
imran-siddique merged 1 commit into
mainfrom
fix/audit-chain-sqlite-persistence
Jun 10, 2026
Merged

fix(audit): persist audit chain to SQLite WAL store on every append (AUDIT-001)#276
imran-siddique merged 1 commit into
mainfrom
fix/audit-chain-sqlite-persistence

Conversation

@imran-siddique

Copy link
Copy Markdown
Member

Summary

  • Adds SqliteAuditStore (audit/store.py) — writes each AuditEntry synchronously to an SQLite WAL DB before AuditChain.append() returns. A crash or OOM kill can no longer silently erase audit history.
  • On startup, orphaned sessions (no session_end in the DB) trigger a WARNING log so operators can identify sessions open at time of last crash.
  • Config: new audit_db_path field (default audit.db). Injected into RuntimeContext; SessionManager passes it to every AuditChain.
  • 7 new unit tests; 2 pre-existing benchmark test failures are unrelated to this PR.

Closes #145. Supersedes #188 (already closed as duplicate).

Test plan

  • pytest tests/unit/test_audit_sqlite.py — all 7 pass
  • pytest tests/unit/ — 592 pass, 2 pre-existing benchmark failures unrelated
  • Start gateway, send tool calls, stop and restart — confirm entries survive restart
  • Fresh install with no prior DB — confirm audit.db is created and orphan check logs nothing
  • Kill gateway mid-session — confirm restart logs orphaned session warning

🤖 Generated with Claude Code

…AUDIT-001)

Closes #145. Adds SqliteAuditStore that writes each AuditEntry synchronously
(WAL mode, PRAGMA synchronous=FULL) before AuditChain.append() returns, so a
crash or OOM kill cannot silently erase audit history.

On gateway startup, orphaned sessions (session_start with no session_end) are
detected and logged as a WARNING so operators can identify sessions that were
open when the gateway last stopped.

Config: add audit_db_path (default audit.db). Injected into RuntimeContext;
SessionManager passes the store to every AuditChain it creates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit 45c4117 into main Jun 10, 2026
3 of 10 checks passed
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.

HIGH: Audit chain is in-process memory only — entire chain lost on crash or restart (AUDIT-001)

1 participant