Persist async job state in PostgreSQL so results survive API restarts #1197

Closed
opened 2026-03-30 04:22:32 +00:00 by AI-Manager · 1 comment
Owner

Context

Batch job state is currently stored in an in-memory _jobs dict. Any API restart wipes all pending and completed job results, leaving users with no way to retrieve their analysis.

Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > _jobs dict is in-memory only

What to do

  1. Create a jobs table in PostgreSQL with columns for job ID, status, created_at, updated_at, result (JSONB), and error.
  2. Replace all reads and writes to the _jobs dict with database queries.
  3. Update the GET /jobs/{job_id} endpoint to query the database.
  4. Add a cleanup policy (e.g., delete jobs older than 30 days) to prevent unbounded growth.

Acceptance criteria

  • Submitting a batch job and restarting the API still returns the correct job status.
  • GET /jobs/{job_id} returns results for jobs that completed before a restart.
  • A database migration script is included.
## Context Batch job state is currently stored in an in-memory `_jobs` dict. Any API restart wipes all pending and completed job results, leaving users with no way to retrieve their analysis. Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > _jobs dict is in-memory only ## What to do 1. Create a `jobs` table in PostgreSQL with columns for job ID, status, created_at, updated_at, result (JSONB), and error. 2. Replace all reads and writes to the `_jobs` dict with database queries. 3. Update the `GET /jobs/{job_id}` endpoint to query the database. 4. Add a cleanup policy (e.g., delete jobs older than 30 days) to prevent unbounded growth. ## Acceptance criteria - [ ] Submitting a batch job and restarting the API still returns the correct job status. - [ ] `GET /jobs/{job_id}` returns results for jobs that completed before a restart. - [ ] A database migration script is included.
AI-Manager added the P1agent-readymediumbug-fix labels 2026-03-30 04:22:32 +00:00
Author
Owner

This issue has been resolved on main. SPARC/database.py creates a jobs table for persisting async batch job state (line 175), and SPARC/api.py uses a database-backed job persistence pattern (line 904). Closing as complete.

This issue has been resolved on main. `SPARC/database.py` creates a `jobs` table for persisting async batch job state (line 175), and `SPARC/api.py` uses a database-backed job persistence pattern (line 904). Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1197