Repository navigation
Description
Summary
The cleanup service runs every 5 minutes with execution_log_retention_days: 30 and execution_row_retention_days: 90 configured (the defaults introduced in #772), but consistently reports execution_logs_pruned: 0 and execution_rows_pruned: 0 on every cycle. After 4+ months of operation a production instance has accumulated 11,322 rows in schedule_executions with 1.35 GB of execution_log data (2.7 GB SQLite DB total), causing backend container memory to sit at ~1.2 GB (OS page cache from reading the large DB file). The retention feature appears to be a no-op in the deployed code.
Component
Backend / Cleanup Service (schedule_executions retention)
Priority
P1 — data accumulates indefinitely; no automatic workaround; requires manual DB intervention to recover.
Reproduction
- Deploy an instance and let it run scheduled agents for 30+ days
- Check cleanup status:
GET /api/monitoring/cleanup-status→execution_logs_pruned: 0,execution_rows_pruned: 0 - Verify eligible rows exist in DB:
SELECT COUNT(*) FROM schedule_executions WHERE replace(started_at, 'T', ' ') < date('now', '-30 days') AND execution_log IS NOT NULL; -- Returns thousands of rows on a live instance
- Trigger cleanup manually:
POST /api/monitoring/cleanup-trigger→ stillexecution_logs_pruned: 0 - The DB continues to grow unchecked
Observed State
GET /api/monitoring/cleanup-status
{
"running": true,
"interval_seconds": 300,
"last_report": {
"execution_logs_pruned": 0,
"execution_rows_pruned": 0,
...
}
}
GET /api/settings/ops/config
{
"execution_log_retention_days": { "value": "30", "is_default": true },
"execution_row_retention_days": { "value": "90", "is_default": true }
}
DB state on affected instance (4+ months, no pruning):
schedule_executions: 11,322 rows, 2.86 GB (table + indexes)execution_logcolumn: avg 136 KB/row, up to 19 MB for long-running agents- Total DB: 2.7 GB
- 6,918 rows have
started_at> 30 days ago and non-nullexecution_log— none are being pruned
Likely Root Cause
Two candidates, likely related:
Candidate A — T vs space SQLite date comparison bug: The started_at and completed_at columns store ISO 8601 values with a T separator (2026-03-15T12:00:00), but SQLite's datetime('now') and Python-generated datetime strings use a space separator (2026-03-15 12:00:00). Since 'T' (0x54) > ' ' (0x20) in ASCII, any comparison of the form:
WHERE completed_at < '2026-04-17 00:00:00'…will incorrectly evaluate records from the same date as being after the cutoff (because '2026-04-17T...' > '2026-04-17 ...'). This affects boundary-day records but not cross-month comparisons.
However, since the 6,918 eligible rows span multiple months (Jan–Apr), this alone cannot explain why zero rows are pruned. This points to:
Candidate B — cleanup code path not executing: The retention settings exist in config and the API surface from #772 is present, but the actual SQL UPDATE/DELETE block in the cleanup service may not be reached — either a missing code path, an unhandled exception that's swallowed silently, or the feature was added to config but the implementation was not yet merged.
The absence of any error logs from the cleanup service during the failing cycles (no exceptions surfaced to backend logs) suggests a silent code path issue rather than a runtime exception.
Fix Direction
- Verify the cleanup service actually executes the
UPDATE schedule_executions SET execution_log = NULL WHERE ...andDELETE FROM schedule_executions WHERE ...statements — add logging to confirm the code path is reached - If T vs space is causing boundary issues, normalize the comparison:
or store datetimes consistently (all space or all T-format)
WHERE replace(completed_at, 'T', ' ') < datetime('now', '-30 days')
- After the fix, a
VACUUMon the DB will be needed on instances where logs have already accumulated
Environment
- Trinity version:
f11ae1b - Feature introduced: feat: implement execution log retention and pruning policy #772
- DB engine: SQLite (file-backed, bind-mounted)
- Cleanup interval: 300s
Related
- feat: implement execution log retention and pruning policy #772 (introduced
execution_log_retention_days/execution_row_retention_days) src/backend/services/cleanup_service.py(likely location of the retention logic)GET /api/monitoring/cleanup-status— reportsexecution_logs_pruned/execution_rows_pruned
Activity
vybe commentedon May 17, 2026
/claim
github-actions commentedon May 17, 2026
Claimed by @vybe. Label
status-in-progressadded.Next steps:
feature/862-<short-slug>Fixes #862docs(cleanup): update feature-flow index and cleanup-service.md for #862
fix(cleanup): use correct TaskExecutionStatus values in retention swe…
Merge branch 'dev' into AndriiPasternak31/issue-586-plan-v1
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).