Autonomous Coding Delegation
Relevant source files
The following files were used as context for generating this wiki page:
- design/coding-delegation.md
- src/agent/coding/tool.ts
- src/agent/coding/coding-flow.test.ts
- changelog.d/2026-04-17-design-drafted-autonomous-coding-container.md
- changelog.d/2026-04-26-phase-slice-autonomous-coding-plan.md
- changelog.d/2026-04-27-phase-slice-plan-approval-execute.md
- design/architecture.md
Autonomous Coding Delegation is a core system within Cogmo that allows the primary agent to offload complex, multi-step coding tasks to a specialized, sandboxed environment. This feature utilizes specialized CLI tools, such as Claude Code, to execute tasks that involve spanning multiple files, running test suites, or performing iterative debugging—operations that would typically exceed the efficiency of standard agentic tool calls.
The system is built on a foundation of "Autonomy Gates," ensuring that significant changes are reviewed by the user through a structured Plan-Approve-Execute lifecycle. By delegating these tasks to a containerized sandbox, Cogmo maintains process isolation and security while leveraging the full power of a dedicated coding assistant.
Sources: design/coding-delegation.md, src/agent/coding/tool.ts:21-25, changelog.d/2026-04-17-design-drafted-autonomous-coding-container.md
System Architecture
The delegation architecture consists of an orchestrator managing durable execution boundaries, a sandbox environment for isolation, and a specialized backend for interacting with the coding model.
Core Components
| Component | Responsibility |
|---|---|
| Delegate Coding Tool | The entry point for the agent to request a coding task. It performs admission checks and submits the task. |
| Orchestrator | Manages the lifecycle of a task across durable step boundaries (Planning, Approval, Execution, Verification). |
| Sandbox (Local-Docker/Daytona) | Provides a containerized environment (typically using sysbox-runc) where the coding CLI executes. |
| Coding Backend | An interface wrapping the coding CLI (e.g., Claude Code), handling stream-json parsing and session management. |
| Streaming Registry | A side-channel pub/sub system used to stream real-time progress (deltas, tool calls) to the user interface. |
Sources: src/agent/coding/tool.ts:31-59, changelog.d/2026-04-26-phase-slice-autonomous-coding-plan.md, changelog.d/2026-04-27-phase-slice-plan-approval-execute.md
Data Flow and Lifecycle
The lifecycle of a coding task is strictly governed by three autonomy gates: Plan, Tool, and Merge. Currently, the system focuses on the transition from planning to execution via user approval.
The flow moves through durable state transitions, ensuring that if the orchestrator process restarts, it can resume from the last successful step.
Sources: design/coding-delegation.md, changelog.d/2026-04-27-phase-slice-plan-approval-execute.md, src/agent/coding/coding-flow.test.ts:153-241
Task Orchestration and Durable Execution
The Orchestrator uses Inngest to maintain durable execution boundaries. This ensures that long-running tasks, which may involve waiting for user approval or extensive CLI processing, remain resilient to system failures.
Durable Phases
- Planning: The orchestrator allocates a git worktree and spawns a container. It runs the coding CLI in "plan" mode.
- Awaiting Approval: The system posts a plan message to the user with "Approve", "Revise", and "Cancel" buttons. The workflow suspends until a callback event is received.
- Execution: Upon approval, the CLI resumes the session from a task-specific home volume and executes the proposed edits.
- Verification: After execution, the task moves to a transient
pending_verifystate to await automated checks or final review.
Sources: changelog.d/2026-04-26-phase-slice-autonomous-coding-plan.md, changelog.d/2026-04-27-phase-slice-plan-approval-execute.md, design/architecture.md
Container Sandboxing and Persistence
To ensure safety and idempotency, coding tasks run in isolated containers.
- Isolation: Uses
sysbox-runcby default to provide rootless-style isolation within the container, preventing process escape and protecting the host. - Worktree Management: Code is bind-mounted from a dedicated git worktree (
COGMO_WORKTREES_DIR). This prevents the main branch from being corrupted during the autonomous coding process. - Session Persistence: CLI session files are stored in a per-task home volume (
cogmo-task-home-<task-id>). This allows the CLI to resume (--resume <session_id>) even if the container is reaped due to idle timeouts during the approval gate.
Sources: changelog.d/2026-04-17-design-drafted-autonomous-coding-container.md, changelog.d/2026-04-26-phase-slice-autonomous-coding-plan.md, design/coding-delegation.md
Interaction Model
The interaction between the user and the coding task is handled through specialized status updates and inline controls.
Streaming Progress
A CodingStreamingRegistry bridges the orchestrator and the delivery layer. It allows real-time token streams, tool calls (e.g., Read, Edit), and usage statistics (input/output tokens and USD cost) to be displayed in the chat interface.
The delegate_coding Tool
The primary agent uses the following schema to initiate work:
const DelegateCodingInput = z.object({
goal: z.string().min(10),
repo: z.string()
});
The tool returns a taskId immediately. The agent is instructed not to speculate about the plan, as the coding CLI's own generated plan is the authoritative source.
Sources: src/agent/coding/tool.ts:4-29
Admission and Resource Control
To prevent system exhaustion, the delegation system implements admission checks.
| Feature | Description |
|---|---|
| Concurrency Limit | Controlled via repo.maxConcurrentTasks. New tasks are rejected if the limit is reached. |
| Admission Check | Performed at the Service.coding.delegate boundary. |
| Resource Limits | Containers are created with specific CPU and Memory ceilings (e.g., 0.5 CPUs, 256MB RAM). |
| Idle TTL | Task containers are reaped after a set idle period (default 20 minutes) to release resources. |
Sources: changelog.d/2026-04-17-design-drafted-autonomous-coding-container.md, src/agent/coding/coding-flow.test.ts:161-167, changelog.d/2026-04-27-phase-slice-plan-approval-execute.md
Conclusion
Autonomous Coding Delegation provides a robust framework for executing complex programming tasks. By combining durable Inngest workflows, containerized sandboxes, and a strict Plan-Approve-Execute lifecycle, Cogmo enables sophisticated code generation while maintaining human oversight and system security.