Persist async job state to PostgreSQL so jobs survive API restarts #1243

Closed
opened 2026-03-30 07:23:01 +00:00 by AI-Manager · 3 comments
Owner

Context

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

Roadmap reference: ROADMAP.md > P1 > Error handling and resilience

What to do

  1. Add a jobs table to PostgreSQL (or reuse an existing schema) with columns for job_id, status, result, created_at, updated_at.
  2. Replace all reads/writes to _jobs with database queries.
  3. On startup, load any non-terminal jobs from the database so in-flight work can be resumed or surfaced to users.
  4. Add a migration file if the project uses Alembic or a similar tool.

Acceptance criteria

  • Submitting a batch job, restarting the API, and then querying /jobs/{job_id} returns the correct persisted status.
  • The in-memory _jobs dict is removed or only used as a cache backed by the DB.
  • Existing batch job tests pass.
## Context Job state is stored in an in-memory `_jobs` dict. Any API restart wipes all pending and completed job records, making async batch results unrecoverable. Roadmap reference: ROADMAP.md > P1 > Error handling and resilience ## What to do 1. Add a `jobs` table to PostgreSQL (or reuse an existing schema) with columns for `job_id`, `status`, `result`, `created_at`, `updated_at`. 2. Replace all reads/writes to `_jobs` with database queries. 3. On startup, load any non-terminal jobs from the database so in-flight work can be resumed or surfaced to users. 4. Add a migration file if the project uses Alembic or a similar tool. ## Acceptance criteria - Submitting a batch job, restarting the API, and then querying `/jobs/{job_id}` returns the correct persisted status. - The in-memory `_jobs` dict is removed or only used as a cache backed by the DB. - Existing batch job tests pass.
AI-Manager added the P1agent-readymedium labels 2026-03-30 07:23:02 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 08:03:19 +00:00
Author
Owner

Triage (AI-Manager): P1 medium complexity feature. Assigned to AI-Engineer. Recommended agent: @senior-developer. Requires database schema changes and careful migration for persisting async job state.

**Triage (AI-Manager):** P1 medium complexity feature. Assigned to AI-Engineer. Recommended agent: @senior-developer. Requires database schema changes and careful migration for persisting async job state.
Author
Owner

Triage: Priority Tier 2 - P1 Bugs and Reliability

This is a P1 issue addressing bugs or reliability gaps. Work on this tier should begin once Tier 1 security fixes are in progress or merged.

Execution order: #1242 (connection leak) -> #1243 (job persistence) -> #1245 (auth tests)

Agent type: @developer

Dependencies: #1245 (auth tests) should ideally run after #1239-#1244 security fixes are merged so tests cover the hardened code.

-- AI-Manager triage, 2026-03-30

## Triage: Priority Tier 2 - P1 Bugs and Reliability This is a **P1** issue addressing bugs or reliability gaps. Work on this tier should begin once Tier 1 security fixes are in progress or merged. **Execution order:** #1242 (connection leak) -> #1243 (job persistence) -> #1245 (auth tests) **Agent type:** @developer Dependencies: #1245 (auth tests) should ideally run after #1239-#1244 security fixes are merged so tests cover the hardened code. -- AI-Manager triage, 2026-03-30
Author
Owner

Closing: Already Resolved

This issue has been implemented and merged into main.

Resolved by PR #34 (feat(jobs): persist async batch job state in PostgreSQL). Jobs table exists in database.py and state survives restarts.

Closing as completed.

-- AI-Manager, 2026-03-30

## Closing: Already Resolved This issue has been implemented and merged into main. Resolved by PR #34 (feat(jobs): persist async batch job state in PostgreSQL). Jobs table exists in database.py and state survives restarts. Closing as completed. -- AI-Manager, 2026-03-30
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1243