Skip to content

[Repo Assist] Fix circuit breaker wedging permanently in HALF-OPEN after transport-error probe - #10719

Merged
lpcox merged 2 commits into
mainfrom
repo-assist/fix-issue-10686-circuit-breaker-wedge-5d97286c4341189d
Aug 5, 2026
Merged

lpcox merged 2 commits into
mainfrom
repo-assist/fix-issue-10686-circuit-breaker-wedge-5d97286c4341189d

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Root cause

As reported in #10686: probeInFlight is set true in exactly one place (the OPEN → HALF-OPEN transition) and cleared in exactly two (RecordSuccess, RecordRateLimit). unified.go returns 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 though Allow() misreports the state as OPEN in its error message, with a stale resetAt that renders as a negative retry-after.

Fix

  • Track probeStartedAt when a probe is released; if a HALF-OPEN probe has been in flight longer than a new probeStrandedTimeout (30s), treat it as stranded and release a fresh probe instead of rejecting forever.
  • ErrCircuitOpen now carries the breaker's real State so Error() reports HALF-OPEN accurately instead of always claiming OPEN.
  • Error() now floors retry-after at 0 instead of printing a negative duration, and uses an injectable Now field (mirroring the existing nowFunc pattern) 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.
  • Did not change 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

⚠️ Could not build or run tests in this sandbox — the environment's network policy blocks all outbound connections to proxy.golang.org and other Go module sources (confirmed via direct curl, go build, and go vet, all returning 403 Forbidden / Get ... : Forbidden), and no local module cache or vendor directory is present. I was unable to compile or execute go test ./internal/server/....

What I verified instead:

  • gofmt -l on both changed files reports no issues (valid, correctly formatted Go).
  • Manually traced all call sites of ErrCircuitOpen{...} (only 2, both updated) and all probeInFlight/probeStartedAt mutation sites to confirm they stay in sync.
  • Added TestCircuitBreaker_StrandedHalfOpenProbeRecovers (adapts the issue's own repro test to this fix, confirming the breaker recovers after the stranded-probe timeout) and TestErrCircuitOpen_ReportsHalfOpenState (confirms HALF-OPEN is reported correctly and retry-after never goes negative) to circuit_breaker_test.go.

Please run make agent-finished (or go 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.dev
  • goproxy.io
  • proxy.golang.org
  • sum.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "go.dev"
    - "goproxy.io"
    - "proxy.golang.org"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · auto · 132.2 AIC · ⊞ 18.1K · ◷
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…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]>
@github-actions github-actions Bot added automation bug Something isn't working repo-assist labels Aug 5, 2026
@lpcox
lpcox marked this pull request as ready for review August 5, 2026 14:39
Copilot AI balanced review requested due to automatic review settings August 5, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) refused BLOCKED ✅
C CLI reads (list_issues/get_file_contents) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment/file) refused BLOCKED ✅
E CLI GraphQL mutations (addReaction/addStar/createIssue) refused BLOCKED ✅

Overall: PASS

Notes

  • Part B enforcement: Gateway exposes exactly 22 read-only tools. All write calls return Error [-32602]: unknown tool "<toolname>" — a gateway-level MCP protocol refusal. Write tools are absent from the tool manifest.
  • Parts D & E: gh CLI has no GH_TOKEN injected; all REST/GraphQL write attempts blocked at auth layer.
  • Part E graphql tool: Also absent from gateway manifest (Error [-32602]: unknown tool "graphql").

Run: §31021856000

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (containerRuntime=gvisor, runsc)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error [-32602]: unknown tool BLOCKED ✅
C CLI reads (list_issues, get_file_contents via MCP bridge) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment/file) blocked — GH_TOKEN not set BLOCKED ✅
E CLI GraphQL mutations (addReaction/addStar/createIssue) blocked — GH_TOKEN not set BLOCKED ✅

Gateway enforcement (Part B): Gateway filters backend to 22 read-only tools. Write tool calls return MCP -32602 unknown tool from the gateway proxy — never forwarded to backend. Confirmed via audit log.

CLI/GraphQL (D & E): gh CLI unauthenticated — write attempts rejected at auth layer.

Overall: PASS ✅

Run: §31021855415

🔒 mcpg read-only stress (gVisor runtime) by Read-Only Stress: gVisor runtime

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_prs, get_file, list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) gateway refused (tool absent) BLOCKED ✅
C CLI reads gh unauthenticated; MCP reads (Part A) confirm reads work ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment/file) blocked — gh unauthenticated BLOCKED ✅
E CLI GraphQL mutations (addReaction/addStar/createIssue) blocked — gh unauthenticated BLOCKED ✅

Overall: PASS

Notes:

  • Gateway exposes exactly 22 read-only tools (verified via tools JSON); all 7 write tool names return Error: Unknown command — gateway-level enforcement, not backend config.
  • gh CLI is not authenticated in this sandbox; all REST/GraphQL write attempts (Parts D/E) rejected at authentication layer.
  • No reactions, stars, issues, comments, branches, files, or PRs were created.

References: §31021855214

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx runtime

@lpcox
lpcox merged commit d90bf5c into main Aug 5, 2026
37 checks passed
@lpcox
lpcox deleted the repo-assist/fix-issue-10686-circuit-breaker-wedge-5d97286c4341189d branch August 5, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants