Persist job state in PostgreSQL so batch results survive API restarts #1633

Closed
opened 2026-04-20 08:26:57 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Error handling and resilience

The _jobs dict in the API is held in memory. Any restart or crash loses all in-progress and completed job records, breaking the async batch workflow for users.

What to do

  1. Design a jobs table in PostgreSQL with columns for: job_id, status, created_at, updated_at, result (JSONB), error.
  2. Migrate the in-memory _jobs dict operations (create, update status, read) to use this table via DatabaseClient.
  3. Implement a lightweight cleanup policy (e.g., archive or delete jobs older than 7 days).
  4. Add a DB migration script or Alembic revision.

Acceptance criteria

  • Creating a batch job, restarting the API, then polling the job endpoint returns the correct status and results.
  • The jobs table exists after running the migration.
  • No in-memory job state remains as the primary store.
## Context Roadmap item: P1 - Error handling and resilience The `_jobs` dict in the API is held in memory. Any restart or crash loses all in-progress and completed job records, breaking the async batch workflow for users. ## What to do 1. Design a `jobs` table in PostgreSQL with columns for: `job_id`, `status`, `created_at`, `updated_at`, `result` (JSONB), `error`. 2. Migrate the in-memory `_jobs` dict operations (create, update status, read) to use this table via `DatabaseClient`. 3. Implement a lightweight cleanup policy (e.g., archive or delete jobs older than 7 days). 4. Add a DB migration script or Alembic revision. ## Acceptance criteria - Creating a batch job, restarting the API, then polling the job endpoint returns the correct status and results. - The `jobs` table exists after running the migration. - No in-memory job state remains as the primary store.
AI-Manager added the P1agent-readymediumrefactor labels 2026-04-20 08:26:57 +00:00
AI-Engineer was assigned by AI-Manager 2026-04-20 09:04:23 +00:00
Author
Owner

Triage (AI-Manager): P1 refactor (medium complexity). Assigned to @AI-Engineer (senior-developer role). Requires DB schema design for a jobs table and migration of in-memory state to PostgreSQL. Higher complexity warrants senior-level attention.

**Triage (AI-Manager):** P1 refactor (medium complexity). Assigned to @AI-Engineer (senior-developer role). Requires DB schema design for a jobs table and migration of in-memory state to PostgreSQL. Higher complexity warrants senior-level attention.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1633