fix(audit): remove coarse per-request middleware that wrote unusable rows #198

Merged
David merged 2 commits from fix/pms-275-remove-coarse-audit-middleware into main 2026-06-13 17:39:12 +02:00
Owner

The per-request audit middleware (PMS-119) fired post-response with only the HTTP method and URL available, so it always passed None for entity_id and the old/new value payload, producing rows with record "-" and null before/after values. Because the API router is nested under /api/v1, the path the middleware saw was already prefix-stripped, so strip_prefix("/api/v1/") always returned None and every row was tagged entity_type "unknown". These junk rows sat interleaved with the rich rows and, for instrumented modules, duplicated them.

The in-transaction audit_write path (PMS-117) is the canonical audit writer: it runs inside the mutation's transaction and records the entity type, record id, and JSONB before/after snapshots. Remove the coarse middleware (its layer wiring, the module, and the now-unused AuditService::append) so audit_write is the sole writer and every audit entry carries the entity, record, and payload the trail needs.

#PMS-275

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

The per-request audit middleware (PMS-119) fired post-response with only the HTTP method and URL available, so it always passed `None` for `entity_id` and the old/new value payload, producing rows with record "-" and null before/after values. Because the API router is nested under `/api/v1`, the path the middleware saw was already prefix-stripped, so `strip_prefix("/api/v1/")` always returned `None` and every row was tagged entity_type "unknown". These junk rows sat interleaved with the rich rows and, for instrumented modules, duplicated them. The in-transaction `audit_write` path (PMS-117) is the canonical audit writer: it runs inside the mutation's transaction and records the entity type, record id, and JSONB before/after snapshots. Remove the coarse middleware (its layer wiring, the module, and the now-unused `AuditService::append`) so `audit_write` is the sole writer and every audit entry carries the entity, record, and payload the trail needs. #PMS-275 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
fix(audit): remove coarse per-request middleware that wrote unusable rows
Some checks failed
E2E (staging) / Playwright against staging (pull_request) Failing after 16s
Check / fmt + clippy + compile + tests (pull_request) Successful in 1m28s
Build OCI container / Build and push mokosh-api image (push) Successful in 3m37s
6892bc4a54
The per-request audit middleware (PMS-119) fired post-response with only the HTTP method and URL available, so it always passed `None` for `entity_id` and the old/new value payload, producing rows with record "-" and null before/after values. Because the API router is nested under `/api/v1`, the path the middleware saw was already prefix-stripped, so `strip_prefix("/api/v1/")` always returned `None` and every row was tagged entity_type "unknown". These junk rows sat interleaved with the rich rows and, for instrumented modules, duplicated them.

The in-transaction `audit_write` path (PMS-117) is the canonical audit writer: it runs inside the mutation's transaction and records the entity type, record id, and JSONB before/after snapshots. Remove the coarse middleware (its layer wiring, the module, and the now-unused `AuditService::append`) so `audit_write` is the sole writer and every audit entry carries the entity, record, and payload the trail needs.

#PMS-275

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merge branch 'main' into fix/pms-275-remove-coarse-audit-middleware
Some checks failed
Create release / Create release from merged PR (pull_request) Has been skipped
E2E / Playwright against staging (pull_request) Has been cancelled
Check / fmt + clippy + compile + tests (pull_request) Failing after 6m8s
c54ebe3091
David merged commit a9ccf05602 into main 2026-06-13 17:39:12 +02:00
David deleted branch fix/pms-275-remove-coarse-audit-middleware 2026-06-13 17:39:12 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!198
No description provided.