Skip to content

fix: Startup recovery for regular task executions (#128) - #165

Merged
vybe merged 4 commits into
Abilityai:mainfrom
AndriiPasternak31:AndriiPasternak31/sprint-issue-128
Mar 25, 2026
Merged

vybe merged 4 commits into
Abilityai:mainfrom
AndriiPasternak31:AndriiPasternak31/sprint-issue-128

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Summary

  • On backend restart, schedule_executions stuck in running are checked against agent containers and process registries
  • Orphaned executions (container down or not in agent's process registry) are immediately marked failed with capacity slots released
  • Reduces recovery time from 2 hours (cleanup service timeout) to seconds (startup check)

Changes

  • src/backend/db/schedules.py — Added get_running_executions() query
  • src/backend/database.py — Exposed new method on DatabaseManager
  • src/backend/services/cleanup_service.py — Added recover_orphaned_executions() using existing AgentClient for HTTP checks
  • src/backend/main.py — Call recovery in lifespan handler after cleanup service start
  • tests/unit/test_orphaned_execution_recovery.py — 6 unit tests covering all scenarios
  • docs/memory/changelog.md — Updated

Test Plan

  • New unit tests pass: pytest tests/unit/test_orphaned_execution_recovery.py -v (6/6)
  • Existing tests unaffected
  • Manual verification: restart backend with running executions, verify they get recovered in logs

Closes #128

Generated with Claude Code

AndriiPasternak31 and others added 3 commits March 25, 2026 01:54
On backend restart, schedule_executions stuck in 'running' status are now
checked against agent containers and process registries. Orphaned executions
are immediately marked failed with capacity slots released, instead of
waiting 2 hours for the cleanup service timeout.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Use existing AgentClient instead of raw httpx (reuse)
- Extract duplicated try/except into _recover_execution helper (DRY)
- Log warning on agent unreachable instead of silent swallow
- Replace defaultdict with plain dict.setdefault
- Simplify test mocks to match AgentClient usage

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.

Clean bug fix, well-tested, follows existing recovery patterns.

@vybe
vybe merged commit fcf6320 into Abilityai:main Mar 25, 2026
@AndriiPasternak31
AndriiPasternak31 deleted the AndriiPasternak31/sprint-issue-128 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.

Startup recovery for regular task executions

2 participants