Skip to content

fix(cleanup): use correct TaskExecutionStatus values in retention sweeps (#862) - #864

Merged
vybe merged 2 commits into
devfrom
feature/862-cleanup-retention-status-fix
May 17, 2026
Merged

fix(cleanup): use correct TaskExecutionStatus values in retention sweeps (#862)#864
vybe merged 2 commits into
devfrom
feature/862-cleanup-retention-status-fix

Conversation

@vybe

@vybe vybe commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: prune_execution_logs and prune_execution_rows queried for status IN ('completed', 'failed', 'terminated') — values that never existed in TaskExecutionStatus. Only 'failed' rows ever matched; 'success' rows (99%+) silently accumulated.
  • Fix: update both SQL predicates to status IN ('success', 'failed', 'cancelled', 'skipped') (the actual TaskExecutionStatus terminal set)
  • Add migration fix_retention_index_status_values to drop and recreate idx_executions_completed_terminal with correct status values on existing installs — CREATE INDEX IF NOT EXISTS alone is a no-op when the wrong index already exists

Changes

  • src/backend/db/schedules.py — fix status predicates in prune_execution_logs and prune_execution_rows
  • src/backend/db/schema.py — fix idx_executions_completed_terminal index definition for new installs
  • src/backend/db/migrations.py — add _migrate_fix_retention_index_status_values migration

Test Plan

  • 13 unit tests pass: pytest tests/unit/test_execution_retention_prune.py -v
  • All 4 terminal statuses verified to prune: success, failed, cancelled, skipped
  • Non-terminal statuses verified safe: running, queued, pending_retry
  • Regression guard: legacy 'completed'/'terminated' values not pruned
  • After deploy: GET /api/monitoring/cleanup-status should show non-zero execution_logs_pruned / execution_rows_pruned on next cycle

Fixes #862

Generated with Claude Code

vybe and others added 2 commits May 17, 2026 13:30
…eps (#862)

The prune_execution_logs and prune_execution_rows methods queried for
status IN ('completed', 'failed', 'terminated'), but TaskExecutionStatus
uses 'success', 'failed', 'cancelled', 'skipped'. Only 'failed' rows
ever matched — 'success' rows (99%+) accumulated indefinitely, causing
1.35 GB of execution_log data to build up on active instances.

Fix: update both SQL predicates, the idx_executions_completed_terminal
partial index in schema.py, and add a migration to drop/recreate the
existing wrong index on live installs (CREATE IF NOT EXISTS alone is a
no-op when the wrong index already exists).

Fixes #862

Co-Authored-By: Claude <noreply@anthropic.com>


Corrects the partial index status values documented in cleanup-service.md
(was 'completed','failed','terminated'; now 'success','failed','cancelled',
'skipped' to match TaskExecutionStatus). Adds #862 entry to feature-flows
index.

Refs #862

Co-Authored-By: Claude <noreply@anthropic.com>
@vybe
vybe merged commit 0b34e8d into dev May 17, 2026
10 checks passed
AndriiPasternak31 added a commit that referenced this pull request May 17, 2026
Brings in 11 commits since the previous rebase (ba4aeae09c8bec),
including the SITE-001 revert (#867), the cleanup retention status-value
fix (#864), and the 60-min default execution timeout (#841).

Conflict resolved: src/backend/db/migrations.py — kept dev's two new
migration entries (default_execution_timeout_to_3600,
fix_retention_index_status_values) first, then our execution_retry_count
appended. All three migration functions defined; order matches each
side's landing chronology.

Phase A (test_cleanup_unreachable_orphan.py helper-pair) and Phase B
(tests/unit/conftest.py baseline-restore) for #797 verified intact after
auto-merge. Lint clean, voice_auth + cleanup tests pass under seed 12345.

Refs #678
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant