Skip to content

fix: Cleanup service misses no-session and skipped executions (#137) - #201

Closed
AndriiPasternak31 wants to merge 3 commits into
Abilityai:mainfrom
AndriiPasternak31:AndriiPasternak31/issue-137-scheduler-misfire
Closed

AndriiPasternak31 wants to merge 3 commits into
Abilityai:mainfrom
AndriiPasternak31:AndriiPasternak31/issue-137-scheduler-misfire

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Summary

Fixes #137 — the cleanup service was failing to catch two categories of orphaned executions:

  1. Running executions with no session — never caught by the 60-second no-session check
  2. Skipped executions — never moved to a terminal state

Root cause: SQLite's datetime('now', '-60 seconds') returns space-separated format (2026-03-27 01:20:00) while started_at is stored in ISO 8601 with T separator (2026-03-27T01:20:00.123456Z). In SQLite string comparison, T (ASCII 84) sorts after space (ASCII 32), making the < comparison always false for same-day timestamps.

Changes:

  • Replace SQLite datetime() with Python-computed ISO 8601 thresholds in all 4 affected cleanup queries
  • finalize_orphaned_skipped_executions now sets status = 'failed' (was only setting completed_at)
  • No-session check matches both NULL and empty-string claude_session_id

Test plan

  • Verify SQLite comparison: sqlite3 :memory: "SELECT '2026-03-27T01:15:00.123456Z' < '2026-03-27T01:20:00';" returns 1
  • Start services, check cleanup status endpoint returns correct counts
  • Create a stuck execution manually and verify cleanup catches it within 5 minutes

🤖 Generated with Claude Code

AndriiPasternak31 and others added 3 commits March 27, 2026 01:23
… terminal-state skipped executions (Abilityai#137)

SQLite's datetime('now') returns space-separated format while started_at
is stored in ISO 8601 with T separator. In string comparison, T (ASCII 84)
sorts after space (ASCII 32), so the < comparison was always false for
same-day timestamps — cleanup queries never matched any rows.

- Replace SQLite datetime() with Python-computed ISO 8601 thresholds
- Set status='failed' on orphaned skipped executions (was only setting completed_at)
- Match empty-string claude_session_id in addition to NULL

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Upstream added security fixes (Abilityai#174-Abilityai#177), event subscriptions (EVT-001),
and subscription improvements (Abilityai#74, Abilityai#148). Our Abilityai#137 cleanup fix entry
placed chronologically above at 2026-03-27.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr. SQLite datetime format mismatch root cause confirmed. Fix is correct and consistent across all 4 affected queries. Feature flow updated accurately.

vybe added a commit that referenced this pull request Mar 28, 2026
…201)

SQLite's datetime('now', '-60 seconds') returns space-separated format while
started_at is stored in ISO 8601 with T separator. The T character sorts after
space in ASCII, making the < comparison always false — cleanup never matched.

- Replace SQLite datetime() with Python-computed ISO 8601 thresholds in all 4 queries
- finalize_orphaned_skipped_executions now sets status='failed' (was non-terminal)
- No-session check matches both NULL and empty-string claude_session_id

Closes #137
@vybe

vybe commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Merged manually after resolving conflicts (changelog moved to archive, feature-flows index). Squash-merged as 4b2a339. Closes #137.

@vybe vybe closed this Mar 28, 2026
@AndriiPasternak31
AndriiPasternak31 deleted the AndriiPasternak31/issue-137-scheduler-misfire branch April 25, 2026 17:59
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.

bug: Cleanup service misses no-session running executions and doesn't terminal-state skipped executions

2 participants