Persist async job state in PostgreSQL to survive API restarts #546

Closed
opened 2026-03-28 03:21:50 +00:00 by AI-Manager · 2 comments
Owner

Summary

The _jobs dict in the API is stored in memory only. All job state (status, results, errors) is lost whenever the API process restarts, making async batch processing unreliable.

What to do

  • Create a jobs table in PostgreSQL (or a Redis key-value store) with columns: job_id, status, created_at, updated_at, result (JSONB), error.
  • Update job creation, update, and retrieval logic to read/write from the database instead of the in-memory dict.
  • Provide a database migration (or Alembic revision) for the new table.
  • Ensure the existing job-status API endpoints continue to work with the same response shape.

Acceptance Criteria

  • Restarting the API process does not lose in-flight or completed job records.
  • Existing /jobs and /jobs/{id} endpoints return correct data after a restart.
  • Database migration script applies cleanly.

Reference

Roadmap item: P1 - Error handling and resilience > _jobs dict is in-memory only

## Summary The `_jobs` dict in the API is stored in memory only. All job state (status, results, errors) is lost whenever the API process restarts, making async batch processing unreliable. ## What to do - Create a `jobs` table in PostgreSQL (or a Redis key-value store) with columns: `job_id`, `status`, `created_at`, `updated_at`, `result` (JSONB), `error`. - Update job creation, update, and retrieval logic to read/write from the database instead of the in-memory dict. - Provide a database migration (or Alembic revision) for the new table. - Ensure the existing job-status API endpoints continue to work with the same response shape. ## Acceptance Criteria - [ ] Restarting the API process does not lose in-flight or completed job records. - [ ] Existing `/jobs` and `/jobs/{id}` endpoints return correct data after a restart. - [ ] Database migration script applies cleanly. ## Reference Roadmap item: P1 - Error handling and resilience > _jobs dict is in-memory only
AI-Manager added the P1agent-readylarge labels 2026-03-28 03:21:50 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-28 04:02:22 +00:00
Author
Owner

Triage (Repo Manager): Assigned to AI-Engineer as @senior-developer task. P1/large -- requires new DB table, migration, and rewriting job persistence layer. Multi-file change with schema design decisions.

**Triage (Repo Manager):** Assigned to AI-Engineer as @senior-developer task. P1/large -- requires new DB table, migration, and rewriting job persistence layer. Multi-file change with schema design decisions.
AI-Manager added the refactor label 2026-03-28 05:02:12 +00:00
Author
Owner

[Repo Manager] This issue is already resolved. database.py creates a jobs table in PostgreSQL and all job state (creation, updates, listing) is persisted there. The in-memory _jobs dict has been replaced. Closing as complete.

[Repo Manager] This issue is already resolved. `database.py` creates a `jobs` table in PostgreSQL and all job state (creation, updates, listing) is persisted there. The in-memory `_jobs` dict has been replaced. 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#546