3.7 KiB
3.7 KiB
Task 007: Agent Job Queue And Runner MVP
Development description: Implement the durable job path from backend to runner, including queued jobs, isolated workspaces, CLI command execution, log capture, output validation, retry, and cancellation basics.
Implementation Details
- Backend:
POST /api/agent-jobs/test-codexGET /api/agent-jobsGET /api/agent-jobs/{job_id}POST /api/agent-jobs/{job_id}/retryPOST /api/agent-jobs/{job_id}/cancel
- Queue:
- Use Redis-backed Celery, Dramatiq, or RQ.
- Persist
QUEUED,RUNNING,SUCCEEDED,FAILED,CANCELLED.
- Runner:
- Creates one workspace per job.
- Writes structured input files.
- Executes allowed command.
- Captures stdout, stderr, exit code, duration.
- Validates output JSON against the expected schema.
- Uploads job artifacts to object storage where appropriate.
- Test Codex job:
- Must support a demo-safe fake runner mode for CI/local tests.
- Real Codex CLI execution is configurable for environments with runner auth.
Public Interface
- Admin can enqueue a test runner job.
- UI can show job status and logs.
- Failed jobs can be retried where allowed.
Acceptance Criteria
- TDD pre-requirement: before implementation, write one failing backend-to-fake-runner integration test through public job APIs; implement minimal queue/runner behavior to make it green and record evidence in
Result. - Backend can create and persist an agent job.
- Runner claims a queued job and marks it running.
- Runner stores stdout, stderr, exit code, duration, and final status.
- Runner validates output JSON and marks schema failures as
FAILED_SCHEMA_VALIDATION. - Cancelled jobs do not update article domain state.
- Retry creates a new attempt or new job with traceable parent metadata.
- Demo stack works without real Codex credentials by using fake runner mode.
Verification
- Run backend/runner integration tests with fake runner.
- Run a Docker Compose test job from Admin UI or API.
- Verify logs and status in UI.
Result
- Status: Accepted
- TDD plan: Added
/api/agent-jobs/test-codexintegration scenario inapps/backend/tests/integration/test_agent_job_queue_public_api.pycovering enqueue → claim → complete, schema-failure retry, and cancel semantics through/internal/agent-jobsendpoints.- Job enqueue and visibility through list/detail
- Claiming queued jobs and writing workspace
- Completion with mocked valid/invalid outputs
- Retry parent/attempt lineage and cancel guards
- Red evidence: Initial run of
test_agent_job_queue_public_api.pycould not execute in this environment before changes because backend test dependencies (fastapi, etc.) were unavailable. - Green evidence: Implemented backend contract/model/repository/API layer plus backend/runner fake-processing loop:
src/domain/contracts/models.py/openapi.pysrc/infrastructure/repositories.py/schema.pysrc/application/agent_jobs.pysrc/presentation/routes/agent_jobs.pysrc/presentation/main.pysrc/application/fake_runner.pyandsrc/presentation/main.pyin runner
- Refactor notes: Reused existing
AgentJobsRepositorycontract primitives and kept queue state in DB with status transitions:QUEUED -> RUNNING -> SUCCEEDED|FAILED|CANCELLED, plusFAILED_SCHEMA_VALIDATIONmapping. - Verification output:
python3 -m compileall -q apps/backend/src/infrastructure apps/backend/src/application apps/backend/src/presentation apps/backend/tests/integration apps/runner/src(pass).
Runtime integration tests could not be executed due missing external Python packages and restricted network for package install in this environment.