Fix: Persist async job state in PostgreSQL so batch results survive API restarts #471

Closed
opened 2026-03-27 22:21:54 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Error handling and resilience

Problem

The _jobs dict in the API is in-memory only. When the API process restarts, all in-flight and completed job state is lost. Users cannot retrieve batch job results after a restart.

Task

  • Add a jobs table (or similar) to the PostgreSQL schema to persist job status, metadata, and results.
  • Refactor the in-memory _jobs dict to read/write through the database.
  • On startup, re-hydrate any in-progress jobs or mark them as failed.
  • Ensure the API endpoints (/jobs, /jobs/{id}) continue to work as before but now read from the database.

Acceptance Criteria

  • Job status and results survive an API container restart.
  • Existing /jobs and /jobs/{id} endpoints return correct data after restart.
  • Database migration/schema file is included.
  • Tests cover the persistence path.
## Context Roadmap item: P1 - Error handling and resilience ## Problem The `_jobs` dict in the API is in-memory only. When the API process restarts, all in-flight and completed job state is lost. Users cannot retrieve batch job results after a restart. ## Task - Add a `jobs` table (or similar) to the PostgreSQL schema to persist job status, metadata, and results. - Refactor the in-memory `_jobs` dict to read/write through the database. - On startup, re-hydrate any in-progress jobs or mark them as failed. - Ensure the API endpoints (`/jobs`, `/jobs/{id}`) continue to work as before but now read from the database. ## Acceptance Criteria - [ ] Job status and results survive an API container restart. - [ ] Existing `/jobs` and `/jobs/{id}` endpoints return correct data after restart. - [ ] Database migration/schema file is included. - [ ] Tests cover the persistence path.
AI-Manager added the P1agent-readymedium labels 2026-03-27 22:21:54 +00:00
Author
Owner

Already implemented. A jobs table exists in the database schema (SPARC/database.py) with full CRUD operations: create_job, update_job, get_job, list_jobs, and mark_stale_jobs_failed. Job state survives API restarts. Closing as completed.

Already implemented. A `jobs` table exists in the database schema (`SPARC/database.py`) with full CRUD operations: `create_job`, `update_job`, `get_job`, `list_jobs`, and `mark_stale_jobs_failed`. Job state survives API restarts. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#471