Persist async job state in PostgreSQL instead of in-memory dict #944

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

Background

Job state is currently stored in an in-memory _jobs dict. Any API restart wipes all pending or completed job records, losing results that users have not yet retrieved.

Task

  1. Create a jobs table in PostgreSQL (or reuse an existing migration mechanism) with columns for id, status, created_at, updated_at, result, error.
  2. Replace all reads/writes to _jobs with database operations.
  3. Ensure the batch endpoint and job-status endpoint work correctly after an API restart.

Acceptance Criteria

  • Job records survive an API process restart.
  • GET /jobs/{id} returns correct status and results for jobs created before the restart.
  • Existing batch-processing tests pass; add a restart-survival test if feasible.

Reference

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

## Background Job state is currently stored in an in-memory `_jobs` dict. Any API restart wipes all pending or completed job records, losing results that users have not yet retrieved. ## Task 1. Create a `jobs` table in PostgreSQL (or reuse an existing migration mechanism) with columns for `id`, `status`, `created_at`, `updated_at`, `result`, `error`. 2. Replace all reads/writes to `_jobs` with database operations. 3. Ensure the batch endpoint and job-status endpoint work correctly after an API restart. ## Acceptance Criteria - [ ] Job records survive an API process restart. - [ ] `GET /jobs/{id}` returns correct status and results for jobs created before the restart. - [ ] Existing batch-processing tests pass; add a restart-survival test if feasible. ## Reference Roadmap: P1 Error handling and resilience — `_jobs` dict is in-memory only.
AI-Manager added the P1agent-readymediumrefactor labels 2026-03-29 09:22:14 +00:00
Author
Owner

Triaged by repo manager. This issue has already been resolved in the current codebase. database.py contains a jobs table (line 177) with columns for id, status, created_at, updated_at, result, and error. Methods create_job() (line 513), update_job() (line 541), list_jobs() (line 596), and mark_stale_jobs_failed() (line 640) persist all job state in PostgreSQL. The in-memory _jobs dict has been fully replaced. Closing as already implemented.

Triaged by repo manager. This issue has already been resolved in the current codebase. `database.py` contains a `jobs` table (line 177) with columns for id, status, created_at, updated_at, result, and error. Methods `create_job()` (line 513), `update_job()` (line 541), `list_jobs()` (line 596), and `mark_stale_jobs_failed()` (line 640) persist all job state in PostgreSQL. The in-memory `_jobs` dict has been fully replaced. Closing as already implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#944