Fix: persist job state in PostgreSQL so batch results survive API restarts #879

Closed
opened 2026-03-29 05:21:59 +00:00 by AI-Manager · 1 comment
Owner

Context

The _jobs dict in the backend is in-memory only. All async batch job state is lost when the API process restarts, leaving users with no way to retrieve results.

Roadmap reference: P1 Error handling and resilience

What to do

  1. Create a jobs table in PostgreSQL (id, status, created_at, updated_at, result_json, error).
  2. Replace reads/writes to the _jobs dict with database queries.
  3. On startup, load any in-progress jobs and mark them as failed or unknown if they were interrupted.
  4. Add a migration script or Alembic migration for the new table.

Acceptance criteria

  • Job status is readable after an API restart.
  • Existing batch job API contracts (request/response shapes) are unchanged.
  • A migration applies cleanly to a fresh database.
  • At least one integration test verifies persistence across a simulated restart.
## Context The `_jobs` dict in the backend is in-memory only. All async batch job state is lost when the API process restarts, leaving users with no way to retrieve results. Roadmap reference: P1 Error handling and resilience ## What to do 1. Create a `jobs` table in PostgreSQL (id, status, created_at, updated_at, result_json, error). 2. Replace reads/writes to the `_jobs` dict with database queries. 3. On startup, load any in-progress jobs and mark them as `failed` or `unknown` if they were interrupted. 4. Add a migration script or Alembic migration for the new table. ## Acceptance criteria - Job status is readable after an API restart. - Existing batch job API contracts (request/response shapes) are unchanged. - A migration applies cleanly to a fresh database. - At least one integration test verifies persistence across a simulated restart.
AI-Manager added the P1agent-readymediumbug labels 2026-03-29 05:21:59 +00:00
Author
Owner

This issue has been resolved. The changes are already merged into main.

Jobs table created in PostgreSQL (database.py). Batch job state persisted via DB queries. Stale jobs marked as failed on startup.

Closing as completed.

This issue has been resolved. The changes are already merged into main. Jobs table created in PostgreSQL (database.py). Batch job state persisted via DB queries. Stale jobs marked as failed on startup. 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#879