Skip to content

feat(audit): automated retention prune for audit_log entries >365d #552

Description

@dolho

Context

Follow-up from #20 (SEC-001 Audit Trail). Phase 4 of docs/requirements/AUDIT_TRAIL_ARCHITECTURE.md listed "retention policy automation" as a checklist item. The append-only contract is already enforced by SQLite triggers (audit_log_no_update, audit_log_no_delete blocks DELETE within 365 days), but nothing prunes entries past the retention window.

Current State

  • audit_log table grows unbounded
  • DELETE within 365d → blocked by trigger
  • DELETE after 365d → allowed but never invoked

Requested

Daily APScheduler job that DELETEs audit_log rows older than 365 days. Trigger-aware so it only runs against the safe window.

Acceptance Criteria

  • New scheduled job in services/scheduler_service.py (or cleanup_service.py) running once per day
  • DELETEs audit_log rows where timestamp < now - 365 days
  • Logs prune count via structured logger
  • Configurable retention window via env var (AUDIT_LOG_RETENTION_DAYS, default 365)
  • Unit test: insert old + new rows, run prune, assert only old removed
  • If hash chain is enabled, prune logic preserves chain integrity (or explicitly documents the gap)

Effort

Low — ~1-2 hr. Single service edit + test.

References

  • Spec Phase 4: docs/requirements/AUDIT_TRAIL_ARCHITECTURE.md § Implementation Plan
  • Append-only triggers: src/backend/db/schema.py:911
  • Closed parent issue: Audit Trail System (SEC-001) #20

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions