Skip to content

feat: per-agent dispatch circuit breaker to prevent backlog poisoning (RELIABILITY-007) #526

Closed

Description

@vybe

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 via GET /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 — not CAPACITY (which is normal backpressure).
  • When circuit is open: dispatch returns HTTP 503 immediately with X-Circuit-Open: true and a retry_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 failed with circuit_open reason, 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

Activity

  1. added
    priority-p1
    type-feature
    on Apr 26, 2026
  2. added
    status-in-dev
    on Jun 2, 2026
  3. vybe commented on Jun 2, 2026

    @vybe
    ContributorAuthor

    Closed by #986 (squash-merged to dev as 0c671158). Auto-close didn't fire because the merge target was dev, not the default branch. RELIABILITY-007 ships default-OFF (dual-gated opt-in canary).

  4. added
    complexity-medium
    theme-reliability
    on Jun 3, 2026
  5. 3 remaining items

  6. added a commit that references this issue on Jul 26, 2026
  7. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

complexity-mediumpriority-p1theme-reliabilitytype-feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions