Skip to content

bug: Cleanup service execution log/row retention never prunes despite configuration (#772) #862

Closed

Description

@vybe

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

  1. Deploy an instance and let it run scheduled agents for 30+ days
  2. Check cleanup status: GET /api/monitoring/cleanup-status → execution_logs_pruned: 0, execution_rows_pruned: 0
  3. 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
  4. Trigger cleanup manually: POST /api/monitoring/cleanup-trigger → still execution_logs_pruned: 0
  5. 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_log column: 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-null execution_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

  1. Verify the cleanup service actually executes the UPDATE schedule_executions SET execution_log = NULL WHERE ... and DELETE FROM schedule_executions WHERE ... statements — add logging to confirm the code path is reached
  2. If T vs space is causing boundary issues, normalize the comparison:
    WHERE replace(completed_at, 'T', ' ') < datetime('now', '-30 days')
    or store datetimes consistently (all space or all T-format)
  3. After the fix, a VACUUM on the DB will be needed on instances where logs have already accumulated

Environment

Related

Activity

  1. vybe commented on May 17, 2026

    @vybe
    ContributorAuthor

    /claim

  2. github-actions commented on May 17, 2026

    @github-actions

    Claimed by @vybe. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/862-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #862
  3. added
    status-in-progress
    on May 17, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 17, 2026
  5. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

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

  6. 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

Labels

priority-p1type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions