Milestone 2 — Durable orchestration and task lifecycle
Status: implemented and locally verified (2026-10-22). The milestone is complete through the API and worker orchestration boundary. Work stops before milestone 3; no real coding agent, model gateway, artifact store, GitHub integration, or task UI is included.
Delivered
- One lifecycle graph and shared guard rules for board stage transitions, branch return stages, expected versions, and reasons. User commands and scheduler/system transitions write a versioned audit row and event. Scheduler-owned
IN_PROGRESSand retry-exhaustion transitions cannot be forged through the manual transition endpoint. - Separate task stage and run status, idempotent task commands, pause/resume/cancel/retry behavior, and optimistic conflict responses (
409 version_conflictwith the current version). - Migration
ffac3c1be398adds transition history, runs, checkpoints, leases, domain events, transactional outbox, consumer inbox, effect intents, and dead letters. Task state and its event/outbox record commit in one PostgreSQL transaction. - Redis Streams outbox publication, consumer-group delivery, transactional inbox deduplication before
XACK, retained event replay, stream rebuild from PostgreSQL, and bounded stream/replay/event retention. - PostgreSQL-backed atomic READY claims with global and project limits, least-recently-dispatched project fairness, descending task priority, lease heartbeats, monotonically increasing fencing tokens, and stale-write rejection.
- Durable checkpoint hashes and recovery: an expired lease resumes only from a retained resumable checkpoint; otherwise the run is visibly failed and dead-lettered instead of being silently relaunched.
- Transient, rate-limited, permanent, and operator retry classes; bounded exponential backoff/jitter; attempt and wall-time limits; dead-letter listing and audited operator replay.
- Pause/resume/cancel/retry, with active cancellation forwarded through
ExecutionAdapter.cancel. Stable-key effect reconciliation distinguishes applied, not applied, and unknown results; abandonedreconcilingwork becomes eligible again after 60 seconds. - Project-authorized task create/list/detail, transition and command endpoints, run and transition history, project-cursor event replay, dead-letter inspection/replay, and administrator dispatch rebuild. OpenAPI is the source for the generated TypeScript contracts.
- A production-safe
UnconfiguredExecutionAdapter. It remains unavailable, so the worker cannot claim work or emit simulated agent activity. The deterministic fake adapter is confined totests/adapters/. - Compose now waits for the API readiness check before starting the worker.
pnpm lint,pnpm typecheck,pnpm test, and opt-in real-servicepnpm test:integrationare available.
Invariants and recovery procedures
- PostgreSQL is authoritative. A state mutation, transition audit, domain event, and outbox row are committed together. Redis publication can repeat after a crash; consumer inbox uniqueness suppresses repeated domain handling.
- Redis can be rebuilt. An administrator calls
POST /ops/dispatch/rebuildafter authorization and Redis recovery. The stream is reconstructed from retained PostgreSQL events for tasks that remainREADYandQUEUED; scheduler eligibility is queried directly from PostgreSQL. - A lease has one current fence. Claiming locks and checks global/project capacity, assigns a unique run and next fencing token, and commits before execution begins. Heartbeat, checkpoint, completion, and failure writes require the same task/run/owner/token and an unexpired lease.
- Expired work does not run twice silently. The worker first looks for the latest resumable checkpoint. It creates a new fenced run using that checkpoint only when available and below retry limits; without one it marks the old run failed, creates a dead letter, and blocks automatic dispatch.
- Retry limits are explicit. Transient/rate-limited errors get capped exponential delay with jitter; provider
Retry-Afteris capped at one hour. Defaults are three attempts, 1,800 seconds total wall time, four global active runs, two active runs per project, and 30-day event retention. Configure through.env; event replay is capped at 500 items and Redis stream length at 10,000 by default. - Cancellation prevents another claim immediately. The command updates run status and cancellation time in PostgreSQL before returning. An active worker observes the state and calls the adapter cancellation hook. A queued task is no longer eligible for a claim.
- Unknown effects remain recoverable. Reconciliation claims database rows in a short transaction, calls its adapter outside that transaction, and stores the result with a retry time. A crash leaves a
reconcilingrow that can be reclaimed after its stale window. - Every read is project-scoped. Task, run, transition, dead-letter, and event routes resolve the project and check the local membership. Event cursors are monotonically increasing within one project and return HTTP 410 after retention expires.
For an operator recovery, inspect GET /projects/{project_id}/dead-letters, review the run/checkpoint history, then call POST /dead-letters/{id}/replay with a reason and Idempotency-Key. Replay requires project operator or administrator membership, records the command and event, and returns the task to READY/QUEUED. Operators can pause, resume, cancel, or retry through POST /tasks/{id}/commands using If-Match and an idempotency key. The event replay route is GET /projects/{id}/events?after={cursor}&limit={n}.
No database transaction is held while an execution or effect adapter performs external work. The worker's production executor is intentionally unconfigured, and the event endpoint is HTTP replay only; SSE/AG-UI subscriptions are left for their later milestone.
Verification performed
All service tests used the local disposable PostgreSQL 16.10 and Redis 7.4.2 Compose services. Integration environment variables pointed to database harnessa_test and Redis database 1. The test fixture rejected database names that do not end in _test, migrated the database before the suite, truncated test-owned rows, and flushed only Redis database 1.
- From
apps/api,uv run alembic upgrade headwithDATABASE_URLset to a newly created emptyharnessa_fresh_testdatabase — succeeded. Confirmed revisionffac3c1be398and all nine new orchestration tables. - Upgrade compatibility — from
apps/api, ranuv run alembic upgrade 0001_foundationon an emptyharnessa_upgrade_test, inserted an organization, project, and task, then ranuv run alembic upgrade head. The old task remained present with empty description and priority 0; the project retained event sequence 0 and received max concurrency 2. Final revision wasffac3c1be398. - From
apps/api,uv run alembic checkwithDATABASE_URLset toharnessa_test— reportedNo new upgrade operations detected. podman compose -f infra/compose.yaml config -q— passed.API_PORT=8011 WEB_PORT=3001 POSTGRES_PORT=5433 REDIS_PORT=6380 podman compose -f infra/compose.yaml up --build -d— API, web, database, Redis, and worker built/started; API healthcheck passed and worker waited for API readiness. Ports 8010 and 3000 belonged to existing AionForge services, which were left running.curl http://localhost:8011/health/ready— HTTP 200,{"status":"ready"}.curl http://localhost:3001/— HTTP 200.HARNESSA_API_URL=http://localhost:8011 pnpm contracts:generate— passed; generated schemas include task stages, run statuses, task/run/transition/event/dead-letter contracts, and API paths.pnpm lint— passed (web ESLint and API Ruff).pnpm typecheck— passed (web TypeScript and 16 typed API/domain/service modules via mypy).pnpm test— 6 passed, 9 integration tests skipped because disposable-service variables were not set; one upstream Starlette/AnyIOBlockingPortaldeprecation warning.pnpm test:integration, withTEST_DATABASE_URLset to the disposableharnessa_testdatabase andTEST_REDIS_URLset to Redis database 1 — 9 passed against real PostgreSQL and Redis. Coverage includes simultaneous claims, priority/project/global limits, fencing, checkpoint recovery, unrecoverable worker loss, attempt and wall-time exhaustion, cancellation forwarding, dead-letter replay, pause/resume, duplicate command replay, pre-publish and post-publish crash recovery, consumer crash before ack, inbox deduplication, stream rebuild, effect reconciliation after a simulated crash, event replay, illegal transitions, stale versions, authentication, and project authorization.- The production web image build completed during
podman compose up --build; Next.js 16.4.2 compiled, typechecked, and prerendered/,/login, and/projects.
No paid service, live model, external GitHub API, or repository scan was used.
Adapter hooks and remaining setup
- A real
ExecutionAdaptermust declare availability/name, implement execution with checkpoint and cancellation callbacks, and honor a current fencing token through the supplied run context. The default adapter stays disabled until that implementation is configured. - An
EffectReconcilermust use stable external-effect keys and reportapplied,not_applied, orunknown; no external effects are issued by the current worker. - LiteLLM routing/spend control, OpenSpec discovery, ACP execution, AG-UI streaming, Harness² probes, artifact storage, OIDC, and GitHub synchronization remain reserved for later milestones.
- Task and recovery endpoints are API-only. There is no task board UI, artifact model/API, or live event subscription yet.
- To run integration tests locally, create a disposable database whose name ends in
_test, use a dedicated Redis database (the README uses database 1), and passTEST_DATABASE_URLplusTEST_REDIS_URL. The suite truncates the database and flushes that Redis database.
Milestone 3 boundary
Milestone 3 can add LiteLLM routing and spend controls on top of ExecutionAdapter without changing the PostgreSQL task/outbox authority. It must not treat a model response as permission to perform an external effect; effect intents and reconciliation remain the durable boundary.