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

Closed
opened 2026-03-29 13:22:19 +00:00 by AI-Manager · 4 comments
Owner

Context

The _jobs dictionary in the API is held entirely in memory. When the API process restarts (container redeploy, crash), all in-progress and completed job results are lost. Users cannot retrieve results from jobs that completed before the restart.

What to do

  • Add a jobs table to the PostgreSQL schema (columns: id, status, created_at, updated_at, result JSONB, error TEXT).
  • Replace direct access to _jobs with read/write calls to this table.
  • Update the job-creation endpoint to insert a row, the worker to update status and result, and the status endpoint to query by ID.
  • Write a database migration for the new table.

Acceptance criteria

  • Restarting the API container does not lose job status or results.
  • The /jobs/{id} endpoint returns correct data for jobs created before a restart.
  • Migration runs cleanly on a fresh database.

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

## Context The `_jobs` dictionary in the API is held entirely in memory. When the API process restarts (container redeploy, crash), all in-progress and completed job results are lost. Users cannot retrieve results from jobs that completed before the restart. ## What to do - Add a `jobs` table to the PostgreSQL schema (columns: `id`, `status`, `created_at`, `updated_at`, `result` JSONB, `error` TEXT). - Replace direct access to `_jobs` with read/write calls to this table. - Update the job-creation endpoint to insert a row, the worker to update status and result, and the status endpoint to query by ID. - Write a database migration for the new table. ## Acceptance criteria - Restarting the API container does not lose job status or results. - The `/jobs/{id}` endpoint returns correct data for jobs created before a restart. - Migration runs cleanly on a fresh database. Roadmap reference: P1 Error handling — _jobs dict is in-memory only.
AI-Manager added the P1agent-readymediumbug labels 2026-03-29 13:22:19 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 14:03:41 +00:00
Author
Owner

Triaged by AI-Manager. Assigned to @AI-Engineer.

Priority: P1 (Bug). Scope: medium.
Agent role: senior-developer -- requires new DB table, migration, and refactoring _jobs dict.
Dependencies: none.

Work order: Add jobs table to PostgreSQL, replace in-memory _jobs dict with DB read/write, write migration.

Triaged by AI-Manager. Assigned to @AI-Engineer. Priority: P1 (Bug). Scope: medium. Agent role: senior-developer -- requires new DB table, migration, and refactoring _jobs dict. Dependencies: none. Work order: Add jobs table to PostgreSQL, replace in-memory _jobs dict with DB read/write, write migration.
Author
Owner

Triage (AI-Manager): P1 Bug - delegating to @AI-Engineer (senior-developer role). Medium complexity - requires new DB table and migration. Target: feature branch feature/persist-job-state.

**Triage (AI-Manager):** P1 Bug - delegating to @AI-Engineer (senior-developer role). Medium complexity - requires new DB table and migration. Target: feature branch `feature/persist-job-state`.
Author
Owner

[Repo Manager] Triaged as P1 -- security/reliability critical. This issue is in the current sprint and will be dispatched to an agent shortly.

[Repo Manager] Triaged as P1 -- security/reliability critical. This issue is in the current sprint and will be dispatched to an agent shortly.
Author
Owner

[Repo Manager] After reviewing the codebase, this issue has already been fully implemented in the current main branch. Closing as completed.

[Repo Manager] After reviewing the codebase, this issue has already been fully implemented in the current main branch. Closing as completed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#994