Repository navigation
[Repo Assist] Fix circuit breaker wedging permanently in HALF-OPEN after transport-error probe - #10719
Conversation
…error probe When a HALF-OPEN probe fails with a transport error (connection failure, JSON parse error, etc.), unified.go returns early without calling RecordSuccess or RecordRateLimit, so probeInFlight is never cleared and the breaker stays wedged in HALF-OPEN forever, rejecting every later request. - Add probeStartedAt tracking and a probeStrandedTimeout (30s) so a stranded HALF-OPEN probe is detected and a fresh probe is released instead of wedging indefinitely. - ErrCircuitOpen now carries the breaker's actual State so its Error() message correctly reports HALF-OPEN instead of always claiming OPEN. - Floor the retry-after duration at 0 instead of rendering a negative value when ResetAt is in the past, and use an injectable Now field for deterministic testing instead of the real clock. Closes #10686 Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes circuit breaker recovery after a HALF-OPEN probe ends with a transport error.
Changes:
- Adds stranded-probe timeout recovery and accurate breaker-state errors.
- Adds regression tests for recovery and non-negative retry durations.
Show a summary per file
| File | Description |
|---|---|
internal/server/circuit_breaker.go |
Implements probe recovery and error reporting. |
internal/server/circuit_breaker_test.go |
Adds regression coverage. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
| // called, so without this timeout probeInFlight would never clear and the | ||
| // breaker would stay wedged in HALF-OPEN indefinitely, rejecting all | ||
| // subsequent requests. Once the timeout elapses, Allow re-releases a probe. | ||
| const probeStrandedTimeout = 30 * time.Second |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot address review feedback |
Co-authored-by: lpcox <[email protected]>
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS Notes
Run: §31021856000
|
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Gateway enforcement (Part B): Gateway filters backend to 22 read-only tools. Write tool calls return MCP CLI/GraphQL (D & E): Overall: PASS ✅ Run: §31021855415
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS Notes:
References: §31021855214
|
Root cause
As reported in #10686:
probeInFlightis settruein exactly one place (the OPEN → HALF-OPEN transition) and cleared in exactly two (RecordSuccess,RecordRateLimit).unified.goreturns early on transport errors (connection failure, JSON parse error, etc.) without calling either, so the single HALF-OPEN probe slot is never released. The breaker then stays wedged in HALF-OPEN forever, rejecting every subsequent request — even thoughAllow()misreports the state asOPENin its error message, with a staleresetAtthat renders as a negative retry-after.Fix
probeStartedAtwhen a probe is released; if a HALF-OPEN probe has been in flight longer than a newprobeStrandedTimeout(30s), treat it as stranded and release a fresh probe instead of rejecting forever.ErrCircuitOpennow carries the breaker's realStatesoError()reportsHALF-OPENaccurately instead of always claimingOPEN.Error()now floors retry-after at0instead of printing a negative duration, and uses an injectableNowfield (mirroring the existingnowFuncpattern) for deterministic tests instead of reading the real clock.Trade-offs
probeStrandedTimeout(30s) is a heuristic bound rather than an event-driven signal — a legitimate very-slow probe could theoretically be treated as stranded and a second probe released concurrently. This mirrors the existing cooldown-based design and is a large improvement over the current "wedged forever" behavior; 30s comfortably exceeds normal request timeouts.unified.go's transport-error handling itself (which the issue's own analysis says is intentionally correct for the CLOSED state) — the timeout-based recovery in the breaker is a more targeted fix for the specific stranded-HALF-OPEN case without touching shared error-handling logic used across all breaker states.Test Status
proxy.golang.organd other Go module sources (confirmed via directcurl,go build, andgo vet, all returning403 Forbidden/Get ... : Forbidden), and no local module cache or vendor directory is present. I was unable to compile or executego test ./internal/server/....What I verified instead:
gofmt -lon both changed files reports no issues (valid, correctly formatted Go).ErrCircuitOpen{...}(only 2, both updated) and allprobeInFlight/probeStartedAtmutation sites to confirm they stay in sync.TestCircuitBreaker_StrandedHalfOpenProbeRecovers(adapts the issue's own repro test to this fix, confirming the breaker recovers after the stranded-probe timeout) andTestErrCircuitOpen_ReportsHalfOpenState(confirmsHALF-OPENis reported correctly and retry-after never goes negative) tocircuit_breaker_test.go.Please run
make agent-finished(orgo test ./internal/server/...) in CI/a networked environment before merging to confirm the new tests pass and no other tests regressed.Warning
Firewall blocked 4 domains
The following domains were blocked by the firewall during workflow execution:
go.devgoproxy.ioproxy.golang.orgsum.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run