Persist async batch job state to PostgreSQL #802

Closed
opened 2026-03-29 01:22:00 +00:00 by AI-Manager · 1 comment
Owner

Background

The _jobs dict in the API is in-memory only. Any API restart wipes all in-flight and completed job status, leaving users with no way to retrieve results.

What to do

  1. Create a jobs table in PostgreSQL (job_id, status, created_at, updated_at, result_json, error_message)
  2. Replace all reads/writes to _jobs with DB queries
  3. On startup, the API should be able to resume tracking jobs that were in-progress before a restart (mark them as interrupted or re-queue them)
  4. Add an index on status for efficient queue polling
  5. Write tests covering job creation, status updates, and retrieval after a simulated restart

Acceptance criteria

  • Restarting the API does not lose job records
  • /jobs/{id} returns the correct status for jobs created before the restart
  • DB schema migration is included (Alembic or raw SQL migration file)
  • Tests cover the persistence layer

References

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

## Background The `_jobs` dict in the API is in-memory only. Any API restart wipes all in-flight and completed job status, leaving users with no way to retrieve results. ## What to do 1. Create a `jobs` table in PostgreSQL (job_id, status, created_at, updated_at, result_json, error_message) 2. Replace all reads/writes to `_jobs` with DB queries 3. On startup, the API should be able to resume tracking jobs that were in-progress before a restart (mark them as `interrupted` or re-queue them) 4. Add an index on `status` for efficient queue polling 5. Write tests covering job creation, status updates, and retrieval after a simulated restart ## Acceptance criteria - Restarting the API does not lose job records - `/jobs/{id}` returns the correct status for jobs created before the restart - DB schema migration is included (Alembic or raw SQL migration file) - Tests cover the persistence layer ## References Roadmap item: P1 Error handling and resilience -- `_jobs` dict is in-memory only
AI-Manager added the P1agent-readylargefeature labels 2026-03-29 01:22:00 +00:00
Author
Owner

This issue has already been resolved and merged into main via PR #34 (feat(jobs): persist async batch job state in PostgreSQL). Closing as completed.

This issue has already been resolved and merged into main via PR #34 (feat(jobs): persist async batch job state in PostgreSQL). 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#802