Skip to content

feat(audit): retention and export semantics for the audit event store (#519) - #885

Merged
athvin merged 4 commits into
mainfrom
issue/519-audit-store
Nov 8, 2026
Merged

athvin merged 4 commits into
mainfrom
issue/519-audit-store

Conversation

@athvin

@athvin athvin commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Closes #519

🚧 Claimed by an agent session — 2026-11-08T18:01:19Z, session 93a44611-348c-4819-b503-ac48b5acd076 on Mac.
The claim is this open draft PR: closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

E4's honest residue: retention and export semantics for the audit ledger, plus
the missing feed filters. A dispatcher retention sweep purges audit_log and
settled webhook_deliveries rows past ER_AUDIT_RETENTION_DAYS (default 400,
floor-clamped to 400 — the infra D-RETENTION compliance decision, enforced
rather than documented); both audit feeds gain actor/since/until filters
and a format=csv export arm (the merge-plans pattern); the org audit screen
gains an Export CSV button through the BFF's injection-safe csv helper.

Why

E4's epic body names the residue precisely: "the specific DataGroomr audit
units, and retention and export semantics" (spec 5.21–5.24, 2.33; the log
browser and merge-audit fidelity are substantially built). 5.24's DoD is
"purge job documented and tested"; 5.23's export half is the CSV arm.

Proof

make check green (exit 0) and make frontend green (exit 0 — lint, types,
authz, unit with the coverage floor, and the mock-backed Playwright functional
tier including the new export assertions). pg_audit ran for real under
ER_TEST_PG_DSN (dedicated Postgres on 5478): filters, the half-open window,
both CSV arms, the purge, the pending-rows-stay rule and the convergent second
sweep. Two mutations observed failing: removing the CSV formula guard, and
removing the state <> 'pending' conjunct from the delivery purge. The clamp
is unit-tested as a pure function (retention_days_from).

Risk & rollback

Post-merge ledger

Closed by: agent · session 93a44611-348c-4819-b503-ac48b5acd076 on Mac · 2026-11-08T19:40:00Z

  • main is green with this change on it — merge SHA b12514c0;
    rust, frontend, infra, devcontainer, images and deploy all
    completed success on that SHA itself.
  • images built — completed success on b12514c0 (rust and
    frontend both changed).
  • deploy converged — run 42514196035: the new colour answered
    er-api-preview /readyz -> 200 (its boot replayed the baseline, which
    is what applies the new audit_log_at index) before Cut over and
    Retire the old colour both succeeded. The retention sweep is live but
    silent in dev — the store is younger than 400 days, so a no-op sweep is
    the correct observation.
  • the push-only surface no pull request can pre-test — deploy
    success (above); drift and kind latest runs success.
  • the board card reached Done through the automation (read back
    from the board) and E4 — Audit event store #519 closed COMPLETED by the merge — epic E4 done.
  • follow-ups are open for everything deferred here — feat(bff): retention sweep for the app-tier audit trail (erweb.audit) #897
    (erweb.audit retention sweep, the app-tier store this PR could not
    reach) and feat(ui): audit log-browser polish — filters, paging, live rows (spec 5.21/5.22) #898 (audit log-browser UI polish: filters, paging, detail).
  • what was learned is written down — backend-design's audit bullet
    and recurring-jobs list, and the infra D-RETENTION decision (now noting
    the mechanical floor and the erweb.audit gap), all updated in this PR.

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  1. entities/audit_log: delete/purge_expired (batched subselect DELETE;
    description engages the append-only wording the way
    entity_event/delete/by_run does), an [at] index (lands on live stores
    via the boot's idempotent baseline replay — the reconciler does not diff
    indexes), actor/since/until params on read/page, and the dataset
    column restored to the API projection. entities/webhook_delivery:
    delete/purge_expired for settled rows only (pending rows are never aged
    out — an undelivered webhook is work, not history).
  2. pg.rs: audit_retention_days() (ER_AUDIT_RETENTION_DAYS, default
    400, CLAMPED to ≥400 with a loud warn — D-RETENTION made mechanical) +
    purge_expired(); dispatcher.rs: an hourly retention sweep tick (loud
    non-fatal failure, the s3-tick discipline).
  3. lib.rs: audit_feed parses the three new filters; both feeds gain a
    format=csv arm (text/csv, bounded by the existing 500 limit, cells
    formula-guarded — one better than merge_plans_csv, which leaves that to
    the BFF).
  4. BFF org audit route: passthrough actor/since/until; format=csv
    re-rendered through lib/bff/csv.ts with Content-Disposition (the
    merge-plans precedent — forward() parses JSON). tenant-audit.tsx:
    an Export CSV anchor, asserted in the functional spec.
  5. Docs: backend-design §10 audit sentence + recurring-jobs list;
    infra D-RETENTION gains the mechanical-purge note; regen entities-index.
  6. Tests: pg_audit.rs (one test, phases): filters, csv arm +
    formula-guard, purge (old gone / new stays / pending webhook row stays),
    clamp observed (env 30 → 400 applied). make check + make frontend.
  7. Follow-ups at merge: erweb.audit retention sweep (BFF-side store);
    audit UI filters/paging/live updates (log-browser polish).

Discoveries

Measurements

Files

@athvin athvin mentioned this pull request Nov 8, 2026
The dispatcher retires audit rows and SETTLED webhook deliveries past
ER_AUDIT_RETENTION_DAYS hourly, in convergent batches; the floor is clamped to
400 days in code so the infra D-RETENTION decision cannot be undercut by a
values file (both the clamp and the pending-rows-stay rule were observed
failing under mutation). Both audit feeds gain actor and half-open
[since, until) filters and a format=csv arm whose cells are formula-guarded
server-side; the projection regains the dataset column page.sql always
selected. The org audit screen gets an Export CSV anchor through the BFF's
injection-safe csv helpers, asserted in the functional tier.
@athvin
athvin marked this pull request as ready for review November 8, 2026 19:01
@athvin
athvin force-pushed the issue/519-audit-store branch from f48a869 to 33587c3 Compare November 8, 2026 19:01
@athvin
athvin merged commit b12514c into main Nov 8, 2026
37 checks passed
@athvin
athvin deleted the issue/519-audit-store branch November 8, 2026 19:26
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.

E4 — Audit event store

2 participants