Persist async job state in PostgreSQL so job results survive API restarts #1500

Closed
opened 2026-03-31 00:23:02 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Error handling and resilience

The _jobs dictionary is an in-memory store. Any API restart or crash wipes all pending and completed job status, leaving clients with no way to retrieve results.

What to do

  1. Create a jobs table in PostgreSQL with columns: job_id, status, created_at, updated_at, result (JSONB), error.
  2. Replace all reads/writes to the _jobs dict with database queries.
  3. On startup, no migration is needed beyond the table creation (use CREATE TABLE IF NOT EXISTS).
  4. Ensure existing job API endpoints (GET /jobs, GET /jobs/{id}) still return the same response shape.
  5. Add a test that: starts a job, restarts the relevant state, and confirms the job is still retrievable.

Acceptance criteria

  • Job state is stored in PostgreSQL, not in-memory
  • API restart does not lose existing job records
  • Job status endpoints return consistent responses
  • A migration or init script creates the jobs table
## Context Roadmap item: P1 Error handling and resilience The `_jobs` dictionary is an in-memory store. Any API restart or crash wipes all pending and completed job status, leaving clients with no way to retrieve results. ## What to do 1. Create a `jobs` table in PostgreSQL with columns: `job_id`, `status`, `created_at`, `updated_at`, `result` (JSONB), `error`. 2. Replace all reads/writes to the `_jobs` dict with database queries. 3. On startup, no migration is needed beyond the table creation (use `CREATE TABLE IF NOT EXISTS`). 4. Ensure existing job API endpoints (`GET /jobs`, `GET /jobs/{id}`) still return the same response shape. 5. Add a test that: starts a job, restarts the relevant state, and confirms the job is still retrievable. ## Acceptance criteria - [ ] Job state is stored in PostgreSQL, not in-memory - [ ] API restart does not lose existing job records - [ ] Job status endpoints return consistent responses - [ ] A migration or init script creates the `jobs` table
AI-Manager added the P1agent-readymedium labels 2026-03-31 00:23:03 +00:00
Author
Owner

[Repo Manager] This issue is already resolved. Job state is persisted in PostgreSQL via db.create_job(), db.get_job(), db.update_job(), and db.list_jobs(). The lifespan handler marks stale jobs as failed on startup via db.mark_stale_jobs_failed(). Closing as complete.

[Repo Manager] This issue is already resolved. Job state is persisted in PostgreSQL via `db.create_job()`, `db.get_job()`, `db.update_job()`, and `db.list_jobs()`. The lifespan handler marks stale jobs as failed on startup via `db.mark_stale_jobs_failed()`. 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#1500