Software Architect & Builder In Production (AI Factory)

swe-dispatcher

Autonomous Software Engineering Sprint Orchestrator over Worktrees and Heterogeneous Quotas

ClojureBabashkaGit Worktreesclj-kondoOTLP / OpenTelemetryEDN

Diagramas

Chained Worktree Orchestration & Quota Routing (swe-dispatcher)

AUTONOMOUS ORCHESTRATION — SWE-DISPATCHER (CLOJURE / BABASHKA).tasks.edn Planchain-plan · :effortsprint_windows + autoresumeWorktree + Turn-0 CGEfeat/ID-i from feat/ID-(i-1)repo-index scan + pack envelopeFail-Closed Gates1. Red: tests-only first commit2. Green: code + Locked-Test (0444)3. :gate-cmds (make test / go vet)small-router OTLP (task.id + session_id)Auditable Deliveryreview/ID branch · ark-swe[bot]Model: trailer + exact costHeterogeneous Quota Bin-Packing (50 measured tasks / 83 sessions)Anthropic 5h ($13.08: ~16 tasks/window) · AGY Argon ($15.00) · AGY Flash ($50.00 high-throughput) · DeepInfra APISonnet 5.5 averages: low $0.39 (1.7m) · medium $0.76 (3.0m) · high $1.39 (5.8m) → up to ~72 tasks/daysprint_runner.clj (claude -p / agy -p) + swe_runner.clj (headless HTTP) + agy-otlp-hook

Project Overview

Running a coding agent on an isolated bug is easy; the engineering challenge begins when chaining 15 consecutive tasks across production repositories without hallucinated signatures, broken master branches, or exhausted quota windows. swe-dispatcher solves this with two complementary engines in Clojure/Babashka: sprint_runner.clj (chained serial sprint orchestration with claude -p or agy -p over stream-json) and swe_runner.clj (headless execution via small-router with automated PR delivery via ark-swe[bot]).

Real sprint manifest (.tasks.edn) & CLI (swe / bb):

{:sprint     "sprint-01"
 :repo       "/home/pace/dev/small-router"
 :base-branch "main"
 :model      "claude-sonnet-5-5"
 :effort     "medium"
 :gate-cmds  ["make test" "go vet ./..."]
 :tasks      [{:id "MR-032" :profile "architecture" :effort "low"}
              {:id "MR-033" :profiles ["architecture" "testing"] :effort "high"}]}

Operational commands: bb sprint estimate plan.edn, bb autoresume plan.edn, or swe task CA-101 --targets "test/foo_test.clj" --lock-existing-tests.

Empirical telemetry across 50 real sprint tasks: correlating execution logs (~/.local/state/swe/) with small-router OTLP metrics over 83 sessions revealed the exact 5h Anthropic window ceiling at US$ 10.00 to US$ 13.08 (e.g., on 11/13, a single 1h08m window consumed US$ 13.08 at 95.7% cache hit delivering 16 committed tasks). Per-task averages with claude-sonnet-5-5 stabilized at $0.39 (1.7 min, low), $0.76 (3.0 min, medium), and $1.39 (5.8 min, high), enabling predictable scheduling up to ~72 tasks/day via autoresume.

Architecture & Implementation

Operations rely on three deterministic pillars: (1) Turn-0 CGE Context: upon creating each worktree (feat/<ID> chained from the previous task via chain-plan), the dispatcher automatically runs repo-index scan, verify, and pack --format envelope so the agent receives fresh, exact signatures from the prior task. (2) Fail-Closed Gates (Red → Green): in sprint-runner, the Test-First Gate enforces a tests-only first commit (Red) before implementation commits pass :gate-cmds; in swe-runner, existing tests are locked physically with chmod 0444 (Locked-Test) so agents cannot weaken assertions. (3) Heterogeneous Quota Bin-Packing (sprint_windows.clj & sprint_autoresume.clj): models independent quota buckets (Anthropic $13.08/5h, AGY Argon $15.00, high-throughput AGY Flash $50.00, and pay-as-you-go DeepInfra), routing tasks by technical risk and auto-resuming seamlessly across renewal windows.