Repository navigation
Description
Summary
Add a per-agent circuit breaker at the backend dispatch layer (in front of SlotService / BacklogService) that fast-fails new executions with HTTP 503 when an agent is unhealthy, instead of accepting them into the backlog where they sit doomed. Track a rolling failure window per agent; when failure rate exceeds threshold (e.g., 5 of last 10 within 60 s), open the circuit; half-open probe after a cooldown.
Distinct from #304 (closed — agent-to-agent calls via chat_with_agent MCP tool) and #307 (heartbeat signal). This is the producer-side breaker that consumes the heartbeat to stop filling the queue with work that will time out.
Context
From the orchestration architecture review (2026-04-26):
No per-agent circuit breaker or failure isolation. A wedged agent (auth dead, OOM looping, push stream broken) keeps draining slots and backlog. Backlog has a depth cap but no health gate: you'll happily queue 50 doomed tasks. Producers have no signal to back off.
Concrete scenario: agent's Anthropic API key expires. Every execution fails after the auth-detect window (~seconds) but the slot is held for the duration. Backlog starts queuing more. By the time someone notices, 50 tasks are queued, each will fail in turn, and the user sees a 25-minute wait before getting their first failure.
Acceptance Criteria
- Per-agent breaker state machine:
closed → open → half-open → closed, persisted in Redis (so it survives backend restart) and surfaced viaGET /api/agents/{name}/health. - Breaker opens when rolling failure rate exceeds threshold (default: 5 failures of last 10 within 60 s; configurable per agent). Counts only specific error codes —
AGENT_ERROR,AUTH,TIMEOUT— notCAPACITY(which is normal backpressure). - When circuit is open: dispatch returns HTTP 503 immediately with
X-Circuit-Open: trueand aretry_after_seconds. Do not enqueue to backlog. This is the key invariant. - Half-open probe after cooldown (default 30 s): allow one execution through; success → close, failure → reopen with exponential backoff.
- Frontend surfaces breaker state in the agent dashboard with a clear "circuit open" status (distinct from "stopped" or "no capacity").
- Cleanup-on-trip: when circuit opens, drain the agent's existing backlog and mark queued executions
failedwithcircuit_openreason, so users get a fast failure instead of a 24-h timeout. - Pairs with feat: Agent heartbeat push for fast failure detection (RELIABILITY-004) #307 heartbeat — missed heartbeats count as a failure signal that can trip the breaker without waiting for a real dispatch to fail.
- Audit log entry on every state transition (open / half-open / closed).
Technical Notes
- Live alongside
SlotServiceinservices/slot_service.pyor as a newservices/circuit_breaker.py. Check happens beforeacquire_slot(). - Library: pybreaker is already in the codebase from feat: Circuit breaker + retry logic for agent-to-agent calls (RELIABILITY-001) #304 (closed) — reuse rather than reimplement.
- Related: feat: Agent heartbeat push for fast failure detection (RELIABILITY-004) #307 (heartbeat input signal), feat: Circuit breaker + retry logic for agent-to-agent calls (RELIABILITY-001) #304 (sibling — agent-to-agent breaker, already shipped),
docs/planning/ORCHESTRATION_RELIABILITY_2026-04.md§ "considerations for the future".
Activity
docs(planning): add Tier 2.6 hardening + actor-model destination roadmap
docs(planning): mark #291 (WEBHOOK-001) shipped, Sprint C now 5/5
Release: v0.5.0 (#608)
docs(requirements): add §10.10 Dispatch Circuit Breaker (RELIABILITY-…
feat(agent-runtime): richer /health signal — active_tasks, last_task_…
feat: per-agent dispatch circuit breaker to prevent backlog poisoning (…
vybe commentedon Jun 2, 2026
Closed by #986 (squash-merged to
devas0c671158). Auto-close didn't fire because the merge target wasdev, not the default branch. RELIABILITY-007 ships default-OFF (dual-gated opt-in canary).fix(backend): bake all top-level modules via Dockerfile COPY glob + p…
3 remaining items
docs(target-arch): revise coordination model to pull/work-stealing (#…
docs(user-docs): sync to post-v0.6.0 platform state
feat(executions): propagate cancelled terminal status end-to-end (#679)…
fix(ci): tighten Alembic guard to require a new MIGRATIONS entry (#1342)
fix(ci): guard the Alembic (Postgres) track in schema-parity (#1342) (#…
Release: v0.8.0 (#1529)
fix(config): forward OPERATOR_INTAKE/DO_NOT_TRACK, DISPATCH_BREAKER_E…
Release: v0.8.5 (#1781)
refactor(chat): split routers/chat.py into thin handlers + bounded se…
fix(subscriptions): a pull-dispatched terminal triggers SUB-003 (#2643)…
fix(subscriptions): a 429 is BILLING, the refusal predicate is three-…
fix(subscriptions): a rate-limited turn completes on another subscrip…
fix(devex): stop the raw-colour scanner counting issue references (#2732
Merge remote-tracking branch 'origin/dev' into feature/553-canvas-lif…