Skip to content

fix(audit): restore read_events/get_stats — audit UI was dead (500s)#208

Merged
AVADSA25 merged 1 commit into
mainfrom
fix/audit-query-endpoints
Jul 2, 2026
Merged

fix(audit): restore read_events/get_stats — audit UI was dead (500s)#208
AVADSA25 merged 1 commit into
mainfrom
fix/audit-query-endpoints

Conversation

@AVADSA25

@AVADSA25 AVADSA25 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

What

The /audit page has been functionally dead: routes/audit.py imports read_events/get_stats from codec_audit, but both were removed in 979edab (Apr 15) when the log moved to the unified schema:1 envelope — the routes were extracted later (#161) still referencing them. Both endpoints 500'd (ImportError), and the UI swallowed it into "--" stats + a permanent "No events found" state.

Reimplements both against the current envelope, deriving the UI's cat/lvl/sum fields at read time (write path + schema untouched per CLAUDE.md §6). Scans the live log + rotated files newest-first. 26 new tests.

Implemented in a companion session; verified + landed from the main session. Found during the 2026-07-02 demo dry-run (step 10: FAIL → this fixes it).

🤖 Generated with Claude Code

…/stream were 500ing

routes/audit.py (extracted in #161) imports read_events/get_stats from
codec_audit, but both were dropped in 979edab (2026-04-15) when the log
moved to the unified schema:1 envelope — every /api/audit/stats and
/api/audit/stream call raised ImportError → 500, silently swallowed by
codec_audit.html into permanent "--" stats and "No events found".

Reimplemented against the current envelope: read_events(categories,
level, search, since, until, limit) and get_stats(hours) scan
~/.codec/audit.log + rotated files newest-first and derive the UI's
cat/lvl/sum fields at READ time from event/source/tool/outcome/level.
Write path and envelope schema untouched (CLAUDE.md §6 contract).
_categorize_event is a documented best-effort heuristic — the envelope
never carried a UI category.

26 new tests (tests/test_audit_query.py): shape, ordering, filters,
rotated-file spanning, malformed-line resilience.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AVADSA25 AVADSA25 merged commit 448f254 into main Jul 2, 2026
1 check passed
@AVADSA25 AVADSA25 deleted the fix/audit-query-endpoints branch July 2, 2026 14:24
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.

2 participants