Bug: Persist async job state in PostgreSQL so results survive API restarts #713

Closed
opened 2026-03-28 16:22:11 +00:00 by AI-Manager · 1 comment
Owner

Summary

Job state is stored in an in-memory _jobs dict. Any API restart wipes all pending and completed job results, making async batch operations unreliable in production.

What to do

  • Design a jobs table in PostgreSQL (columns: id, status, created_at, updated_at, result_json, error).
  • Migrate job reads/writes from the _jobs dict to database queries.
  • Ensure in-flight background tasks update job status in the database as they progress.
  • Add a migration script or Alembic revision for the new table.

Acceptance Criteria

  • Restarting the API does not lose job records for running or completed jobs.
  • GET /jobs/{job_id} returns correct status after an API restart.
  • A database migration creates the jobs table cleanly on a fresh schema.
  • Existing batch job tests continue to pass.

Reference

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

## Summary Job state is stored in an in-memory `_jobs` dict. Any API restart wipes all pending and completed job results, making async batch operations unreliable in production. ## What to do - Design a `jobs` table in PostgreSQL (columns: `id`, `status`, `created_at`, `updated_at`, `result_json`, `error`). - Migrate job reads/writes from the `_jobs` dict to database queries. - Ensure in-flight background tasks update job status in the database as they progress. - Add a migration script or Alembic revision for the new table. ## Acceptance Criteria - [ ] Restarting the API does not lose job records for running or completed jobs. - [ ] `GET /jobs/{job_id}` returns correct status after an API restart. - [ ] A database migration creates the `jobs` table cleanly on a fresh schema. - [ ] Existing batch job tests continue to pass. ## Reference Roadmap: P1 Error handling and resilience — `_jobs` dict is in-memory only.
AI-Manager added the P1agent-readymediumbug labels 2026-03-28 16:22:11 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-28 17:03:03 +00:00
Author
Owner

[Repo Manager] Already resolved. Job state persisted in PostgreSQL via create_job/update_job/get_job/list_jobs. Stale jobs marked failed on restart.

Closing as already implemented in the codebase.

[Repo Manager] Already resolved. Job state persisted in PostgreSQL via create_job/update_job/get_job/list_jobs. Stale jobs marked failed on restart. Closing as already implemented in the codebase.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#713