The phased plan for implementing ACP, in exact build order.
V1 Goal: Two isolated worker agents sharing a vault and coordinating via tasks, with automatic failure recovery, driven by an orchestrator.
Language: Go. The control plane is a single static binary.
Status: Phases 1–8 are implemented (internal/, cmd/acp/) with the Phase 4 concurrency gate and the recovery race tests passing under go test -race ./.... Phase 9 (orchestrator integration) is open. One deliberate deviation from the plan below: implementation surfaced two read-modify-write races (claim's two-step window; renewal vs. recovery), fixed by the .wip mutation protocol — see Task State Machine §6 and DD-009.
The order is determined by strict dependency:
State Layer → Task Model → Task Queue → Concurrency Test → Lease System
→ Recovery Controller → Agent Loop → CLI → Orchestrator Integration
Why this order, not another:
- State first: everything reads/writes state. Without correct state, nothing else can be tested.
- Task model second: defines the shape of truth. All other code depends on this.
- Task queue third: the claim logic is the critical path. Must work before agents run.
- Concurrency test fourth: proves the claim is atomic before anything builds on it.
- Lease system fifth: needed before recovery controller can detect failures.
- Recovery controller sixth: now you can simulate crashes and verify recovery.
- Agent loop seventh: the first "alive" piece of the system.
- CLI eighth: human interface, built after system behavior is proven.
- Orchestrator ninth: replaces manual task creation with LLM-driven planning.
Do not skip phases. Each phase's tests are a prerequisite for the next.
Goal: Reliable, atomic filesystem operations.
What to build:
StateStoreinterface (internal/store/store.go)FileSystemStoreimplementation (internal/store/filesystem.go)Read,Write,Append,List,Exists,DeleteMove— usesos.Rename, atomic on POSIX
Critical invariants:
Writealways creates parent directories (no silent failures)Writeis atomic (temp file in the same directory + rename) — this is NOT optional. The VaultController quarantines unparseable files; if writes could tear, a crash mid-write would get a healthy task quarantined. Torn writes must be impossible, not unlikely.Moveusesos.Rename— no other implementation is acceptable for V1Listreturns consistent, alphabetically sorted filenames and excludes hidden entries (temp files,.wip/)
Success criteria:
- Create, read, list, and delete files via
FileSystemStore -
Moveworks atomically (tested with concurrent goroutines — see Phase 4) - All operations handle non-existent paths gracefully (no panics)
Goal: Define the exact shape of all data the system touches.
What to build:
Taskstruct with all fields (internal/task/task.go)Statustype:pending,doing,done,failedPrioritytype:low,normal,high,critical- JSON serialization/deserialization
- Task ID generator:
task_{unix_ns}_{random6}format
Critical invariants:
- All timestamp fields use ISO 8601 / RFC 3339
RetryCountstarts at 0Rolefield is optional (empty = any worker can claim)- JSON round-trip must be lossless (no field silently dropped)
Success criteria:
- Can create a
Task, marshal to JSON, unmarshal back, and get the same struct - ID generation produces unique IDs under concurrent calls
Goal: The complete task lifecycle over the filesystem.
What to build:
TaskQueueinterface (internal/task/queue.go)task.Queueimplementation (the.wipmutation protocol lives here — every operation is acquire into.wip/→ mutate → settle; see Task State Machine §6)CreateTask: write tovault/tasks/pending/{id}.jsonClaimTask: list pending, acquire viaMove(pending→.wip), set lease fields, settle intodoing/CompleteTask: acquire viaMove(doing→.wip), validate ownership, setresult/completed_at, settle intodone/FailTask: acquire viaMove(doing→.wip), validate ownership, seterror/failed_at, settle intofailed/ListTasks: read files from appropriate directories, return filtered sliceGetTask: search all four directories for a task by ID
Critical invariants:
- No operation ever writes a task file it has not first acquired into
.wip/— direct moves between state directories or in-place edits re-introduce the races the protocol exists to prevent ClaimTaskiterates pending files and attempts the acquire — if theMovefails (ENOENT), continue to next- Only the assigned agent can complete or fail a task (
assigned_agentcheck) CompleteTaskandFailTaskare idempotent (already-done/already-failed = no-op success)- Task
Statusfield must match the directory the file is in
Success criteria:
-
CreateTaskwrites valid JSON topending/ -
ClaimTaskmoves file todoing/and populates agent/lease fields -
CompleteTaskmoves file todone/and writesresult -
FailTaskmoves file tofailed/and writeserror - Trying to complete with wrong agent ID returns an error
Goal: Prove that the atomic claim is actually atomic.
This phase is a test, not a feature. Nothing proceeds until this passes.
What to write:
- Test that spawns N goroutines simultaneously calling
ClaimTaskon the same task - Verifies exactly 1 goroutine gets a non-nil Task
- Verifies all others get nil
- Repeat with N = 2, 10, 100
Why this is a gate: If the atomic claim is broken, every system property built on top of it is broken. A bug here means silent task duplication — two workers executing the same task. This is worse than task loss. Fix it here before it's invisible.
Success criteria:
- 100 concurrent goroutines claiming 1 task: exactly 1 succeeds, 99 return nil
- 10 goroutines claiming 10 tasks (one each): each goroutine gets exactly one unique task, no task claimed twice
- Test is deterministic across multiple runs
Goal: Tasks in doing/ have a time-bounded claim that must be renewed.
What to build:
RenewLease: updatelease_expiryandheartbeat_aton a doing taskReleaseTask: voluntarily return a doing task to pending (does NOT incrementretry_count)- Lease duration constant: 30 minutes (configurable later)
- Heartbeat interval recommendation:
lease_duration / 3= 10 minutes
Critical invariants:
RenewLeasefails if task is not indoing/statelease_expiryis always a future timestamp when a task is claimedHeartbeatAtis updated every timeRenewLeaseis called
Success criteria:
- Claiming a task sets
lease_expiry30 minutes in the future -
RenewLeaseextendslease_expiry -
RenewLeaseon a non-doing task returns an error -
ReleaseTaskreturns task topending/without incrementingretry_count
Goal: Automatic recovery from worker failures.
What to build:
RecoveryControllerstruct with aRun(ctx context.Context)method- Runs in a goroutine, polls every 5 minutes
- Phase 1: Scans
doing/for expired leases, re-queues or fails based onretry_count - Phase 2: Logs warnings for tasks in
pending/for >24 hours (no action) VaultController: scans all task directories for files that fail JSON parsing or fail invariant checks, moves tofailed/AgentObserver: readsvault/agents/*.json, logs stale agents (no action in V1)
Critical invariants:
- Recovery is idempotent: running it twice produces the same result
- Re-queued tasks:
retry_count++, clearassigned_agent/lease_expiry/heartbeat_at/started_at, move topending/ - Permanently failed tasks:
retry_count >= max_retries, write descriptive error, move tofailed/ - Controller must be restartable: crashes during recovery are safe because the vault is the source of truth
Simulate and verify:
- Create task, claim it, artificially set
lease_expiryto the past, run recovery → task moves back topending/ - Do this 3 times → after 4th expiry (max_retries=3), task moves to
failed/ - Kill recovery loop mid-run, restart → system converges correctly
Goal: A working agent that completes tasks end-to-end.
What to build:
- Stub agent harness: claims task, waits 2 seconds, writes "stub result", completes
- Goroutine-based polling loop: poll every 5 seconds, claim, execute, complete
- Heartbeat renewal goroutine: runs in background while task is being executed, calls
RenewLeaseevery 10 minutes - Agent registration: writes
vault/agents/{agent_id}.jsonat startup, updateslast_seen_aton each poll
Success criteria:
- Single stub agent: claims all tasks in
pending/, completes them, moves todone/ - Two stub agents: work in parallel on separate tasks, no task claimed twice
- Kill an agent mid-task: after lease expiry, task re-appears in
pending/ - New agent starts, picks up the re-queued task, completes it
Goal: Human-friendly commands for development, debugging, and manual orchestration.
What to build:
acp init ← scaffold vault directory structure
acp task create [--role R] <desc> ← create a task in pending/
acp task list [--status S] ← list tasks with status
acp task show <id> ← detailed view of one task
acp task retry <id> ← move failed task back to pending
acp status ← show agents + task counts
acp serve ← run the control plane loops
acp agent --id <id> ← run a worker (stub or --exec)
(No task cancel — DD-007 explicitly defers cancellation, and the CLI must not offer transitions the state machine doesn't define.)
Tech: Go with cobra or flag package. Compiles to the same acp binary as the control plane.
Success criteria:
- All commands work against a live vault
-
acp initproduces the correct directory structure -
acp statusshows correct agent liveness and task counts -
acp task retrycorrectly resetsretry_countandrelease_countto 0 and moves topending/
Goal: Replace manual task creation with an LLM-driven orchestrator.
What to build: This is the first phase that involves LLM code — and it's intentionally kept thin.
A minimal orchestrator:
- Accepts user input (goal string)
- Calls an LLM (Claude, GPT-4, etc.) to decompose goal into structured tasks
- Parses LLM output into task structs with role/description fields
- Calls
acp task createfor each task (or writes directly to vault) - Polls
vault/tasks/done/andvault/tasks/failed/to observe progress - Reports status to user, creates follow-up tasks if needed
Constraints (stay minimal):
- No complex planning graphs in V1
- No multi-agent delegation within the orchestrator
- No memory system beyond the vault
- One loop: plan → write tasks → wait → read results → next loop
Success criteria:
- User says "Build a hello world Go program" → orchestrator creates appropriate tasks → workers claim and complete them → orchestrator reports results to user
- A failed task causes orchestrator to notify user, not silently disappear
- Orchestrator can be replaced with a different LLM without changing ACP
These are explicitly deferred. They can be added based on real experience with V1.
| Feature | Why Deferred |
|---|---|
| Redis/DB state store | File-based works for V1. Adds external dependency without proven need. |
| Kubernetes runtime | Docker Compose is sufficient. K8s adds major complexity. |
| UI/Dashboard | CLI is sufficient. Dashboard needs an API server. |
| Task dependencies/DAG | State machine not yet proven. Dependencies before stability = rewrite. |
| Security model | No threat model yet. Trust local system in V1. |
| Event bus | Polling works. Events are optimization. |
| ACP managing container lifecycle | Docker Compose handles restarts in V1. |
| Orchestrator memory/context | Vault is the memory. Extra context systems come later. |
| Phase | Test | What Failure Means |
|---|---|---|
| 1 | FileSystemStore operations |
Unreliable state layer — everything above is broken |
| 4 | Concurrent claim: only 1 wins | Silent task duplication — the most dangerous bug |
| 6 | Crash recovery: agent dies, task re-queues | System loses work on crashes |
| 7 | 2 agents + 10 tasks: all complete, none duplicated | End-to-end correctness |
| 9 | Full loop: user goal → orchestrator → tasks → workers → results | System works as designed |