fix(audit): restore read_events/get_stats — audit UI was dead (500s)#208
Merged
Conversation
…/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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The /audit page has been functionally dead:
routes/audit.pyimportsread_events/get_statsfromcodec_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/sumfields 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