Skip to content

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

Closed

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

Activity

  1. added
    priority-p3
    type-feature
    on Apr 28, 2026
  2. added
    status-in-dev
    on Apr 29, 2026
  3. vybe commented on Jun 1, 2026

    @vybe
    Contributor

    Shipped in v0.6.0 (released via #998).

  4. added
    complexity-low
    theme-security
    and removed
    status-in-dev
    on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p3theme-securitytype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions