Retention/pruning for schedule_log and ai_usage_log (#59) #72

Merged
claude-bot merged 1 commit from fix/59-retention into main 2026-07-16 07:17:48 +00:00
Contributor

Closes #59. Neither log was ever pruned (audit_log stays unpruned per §7.3).

  • New services/retention.py: prune_schedule_log(db, retain_days), prune_ai_usage_log(db, retain_hours=48), run_log_retention(...).
  • Hooked into the daily midnight job (run_reschedule_daily_jobs) — daily cadence keeps ai_usage_log reliably inside its 48h window (only a rolling 24h is queried for AI_DAILY_LIMIT); the weekly job would let it sit ~7 days.
  • schedule_log retention is configurable: SCHEDULE_LOG_RETAIN_DAYS (default 365) via config.py + a RuntimeSettings.schedule_log_retain_days field (follows the backup_retain_count pattern), with a PUT /settings side effect that re-prunes immediately on change. Documented in the spec config reference + troubleshooting.
  • 8 tests in test_retention.py (old/kept/boundary for both tables + end-to-end via the daily job).

Verified: ruff/format/mypy clean; 225 tests pass (only the known Windows-only backup file-lock errors remain, green on Linux CI).

🤖 Generated with Claude Code

Closes #59. Neither log was ever pruned (`audit_log` stays unpruned per §7.3). - New `services/retention.py`: `prune_schedule_log(db, retain_days)`, `prune_ai_usage_log(db, retain_hours=48)`, `run_log_retention(...)`. - Hooked into the **daily** midnight job (`run_reschedule_daily_jobs`) — daily cadence keeps `ai_usage_log` reliably inside its 48h window (only a rolling 24h is queried for `AI_DAILY_LIMIT`); the weekly job would let it sit ~7 days. - `schedule_log` retention is configurable: `SCHEDULE_LOG_RETAIN_DAYS` (default 365) via `config.py` + a `RuntimeSettings.schedule_log_retain_days` field (follows the `backup_retain_count` pattern), with a `PUT /settings` side effect that re-prunes immediately on change. Documented in the spec config reference + troubleshooting. - 8 tests in `test_retention.py` (old/kept/boundary for both tables + end-to-end via the daily job). Verified: `ruff`/`format`/`mypy` clean; 225 tests pass (only the known Windows-only backup file-lock errors remain, green on Linux CI). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add retention/pruning for schedule_log and ai_usage_log (#59)
All checks were successful
CI / Python lint & type-check (pull_request) Successful in 1m32s
CI / Frontend lint, test & build (pull_request) Successful in 1m26s
CI / Python tests (pull_request) Successful in 2m10s
CI / Dependency audit (pull_request) Successful in 1m30s
CI / Alembic migration check (pull_request) Successful in 4m33s
CI / Docker build, health smoke & E2E (pull_request) Successful in 23m34s
5b5df4da72
schedule_log grew unbounded (several rows/day from pushes, retries,
failures) and ai_usage_log grew one row per AI request, with no pruning.
Add a small, unit-testable retention service and hook it into the
existing daily midnight scheduler job: schedule_log rows older than the
new SCHEDULE_LOG_RETAIN_DAYS setting (default 365d) are deleted, and
ai_usage_log rows older than 48h are deleted (only a rolling 24h window
is ever queried for AI_DAILY_LIMIT, so 48h gives margin). audit_log is
untouched per spec §7.3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
claude-bot deleted branch fix/59-retention 2026-07-16 07:17:49 +00:00
Sign in to join this conversation.
No description provided.