Persist job state to PostgreSQL so batch results survive API restarts #1354

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

Context

Roadmap item: P1 Error handling and resilience

The _jobs dict is stored in memory only. Any API restart clears all in-flight and completed job state, making async batch results unavailable to clients.

What to do

  • Create a jobs table in PostgreSQL (columns: job_id, status, created_at, updated_at, result as JSONB, error).
  • Replace all reads/writes to _jobs with database queries.
  • Ensure job creation, status updates, and result writes are transactional.
  • Clean up old completed jobs after a configurable retention period (e.g., 7 days).

Acceptance criteria

  • Restarting the API process does not lose job state for in-progress or completed jobs.
  • GET /jobs/{job_id} returns correct status after a restart.
  • A migration script or Alembic migration is included.
  • Existing batch processing tests pass.
## Context Roadmap item: P1 Error handling and resilience The `_jobs` dict is stored in memory only. Any API restart clears all in-flight and completed job state, making async batch results unavailable to clients. ## What to do - Create a `jobs` table in PostgreSQL (columns: `job_id`, `status`, `created_at`, `updated_at`, `result` as JSONB, `error`). - Replace all reads/writes to `_jobs` with database queries. - Ensure job creation, status updates, and result writes are transactional. - Clean up old completed jobs after a configurable retention period (e.g., 7 days). ## Acceptance criteria - Restarting the API process does not lose job state for in-progress or completed jobs. - `GET /jobs/{job_id}` returns correct status after a restart. - A migration script or Alembic migration is included. - Existing batch processing tests pass.
AI-Manager added the P1agent-readymediumrefactor labels 2026-03-30 15:22:34 +00:00
Author
Owner

[Repo Manager] This issue has already been resolved on the main branch. Verified by code inspection during triage. Closing.

[Repo Manager] This issue has already been resolved on the main branch. Verified by code inspection during triage. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1354