Skip to content

Latest commit

 

History

History
282 lines (208 loc) · 13 KB

roadmap.md

File metadata and controls

282 lines (208 loc) · 13 KB

V1 Implementation Roadmap

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.


Build Order Rationale

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.


Phase 1: State Layer

Goal: Reliable, atomic filesystem operations.

What to build:

  • StateStore interface (internal/store/store.go)
  • FileSystemStore implementation (internal/store/filesystem.go)
    • Read, Write, Append, List, Exists, Delete
    • Move — uses os.Rename, atomic on POSIX

Critical invariants:

  • Write always creates parent directories (no silent failures)
  • Write is 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.
  • Move uses os.Rename — no other implementation is acceptable for V1
  • List returns consistent, alphabetically sorted filenames and excludes hidden entries (temp files, .wip/)

Success criteria:

  • Create, read, list, and delete files via FileSystemStore
  • Move works atomically (tested with concurrent goroutines — see Phase 4)
  • All operations handle non-existent paths gracefully (no panics)

Phase 2: Task Model

Goal: Define the exact shape of all data the system touches.

What to build:

  • Task struct with all fields (internal/task/task.go)
  • Status type: pending, doing, done, failed
  • Priority type: 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
  • RetryCount starts at 0
  • Role field 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

Phase 3: Task Queue (Claim Logic)

Goal: The complete task lifecycle over the filesystem.

What to build:

  • TaskQueue interface (internal/task/queue.go)
  • task.Queue implementation (the .wip mutation protocol lives here — every operation is acquire into .wip/ → mutate → settle; see Task State Machine §6)
    • CreateTask: write to vault/tasks/pending/{id}.json
    • ClaimTask: list pending, acquire via Move(pending→.wip), set lease fields, settle into doing/
    • CompleteTask: acquire via Move(doing→.wip), validate ownership, set result/completed_at, settle into done/
    • FailTask: acquire via Move(doing→.wip), validate ownership, set error/failed_at, settle into failed/
    • ListTasks: read files from appropriate directories, return filtered slice
    • GetTask: 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
  • ClaimTask iterates pending files and attempts the acquire — if the Move fails (ENOENT), continue to next
  • Only the assigned agent can complete or fail a task (assigned_agent check)
  • CompleteTask and FailTask are idempotent (already-done/already-failed = no-op success)
  • Task Status field must match the directory the file is in

Success criteria:

  • CreateTask writes valid JSON to pending/
  • ClaimTask moves file to doing/ and populates agent/lease fields
  • CompleteTask moves file to done/ and writes result
  • FailTask moves file to failed/ and writes error
  • Trying to complete with wrong agent ID returns an error

Phase 4: Concurrency Test (MANDATORY GATE)

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 ClaimTask on 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

Phase 5: Lease System

Goal: Tasks in doing/ have a time-bounded claim that must be renewed.

What to build:

  • RenewLease: update lease_expiry and heartbeat_at on a doing task
  • ReleaseTask: voluntarily return a doing task to pending (does NOT increment retry_count)
  • Lease duration constant: 30 minutes (configurable later)
  • Heartbeat interval recommendation: lease_duration / 3 = 10 minutes

Critical invariants:

  • RenewLease fails if task is not in doing/ state
  • lease_expiry is always a future timestamp when a task is claimed
  • HeartbeatAt is updated every time RenewLease is called

Success criteria:

  • Claiming a task sets lease_expiry 30 minutes in the future
  • RenewLease extends lease_expiry
  • RenewLease on a non-doing task returns an error
  • ReleaseTask returns task to pending/ without incrementing retry_count

Phase 6: Recovery Controller

Goal: Automatic recovery from worker failures.

What to build:

  • RecoveryController struct with a Run(ctx context.Context) method
  • Runs in a goroutine, polls every 5 minutes
  • Phase 1: Scans doing/ for expired leases, re-queues or fails based on retry_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 to failed/
  • AgentObserver: reads vault/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++, clear assigned_agent/lease_expiry/heartbeat_at/started_at, move to pending/
  • Permanently failed tasks: retry_count >= max_retries, write descriptive error, move to failed/
  • 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_expiry to the past, run recovery → task moves back to pending/
  • Do this 3 times → after 4th expiry (max_retries=3), task moves to failed/
  • Kill recovery loop mid-run, restart → system converges correctly

Phase 7: Agent Loop

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 RenewLease every 10 minutes
  • Agent registration: writes vault/agents/{agent_id}.json at startup, updates last_seen_at on each poll

Success criteria:

  • Single stub agent: claims all tasks in pending/, completes them, moves to done/
  • 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

Phase 8: CLI

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 init produces the correct directory structure
  • acp status shows correct agent liveness and task counts
  • acp task retry correctly resets retry_count and release_count to 0 and moves to pending/

Phase 9: Orchestrator Integration

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 create for each task (or writes directly to vault)
  • Polls vault/tasks/done/ and vault/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

What Is NOT in V1

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.

The Critical Tests to Write (In Order)

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