Skip to content

Commit ffc83ab

Browse files
committed
feat(12-02): add Polly circuit breaker as outermost strategy in mcp-tools pipeline (ROB-03)
1 parent 84439f5 commit ffc83ab

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/GsdOrchestrator/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.AI;
1010
using Microsoft.Extensions.Logging;
1111
using Polly;
12+
using Polly.CircuitBreaker;
1213
using Serilog;
1314
using Serilog.Formatting.Compact;
1415

@@ -62,7 +63,19 @@
6263
builder.Services.AddSingleton<McpToolDispatcher>();
6364

6465
// ── Polly resilience pipeline ────────────────────────────────────────────────────────────
66+
// AddCircuitBreaker MUST come before AddRetry — outermost strategy trips first,
67+
// preventing retry budget waste when MCP is unavailable (D-07, D-08).
6568
builder.Services.AddResiliencePipeline("mcp-tools", pipelineBuilder => pipelineBuilder
69+
.AddCircuitBreaker(new CircuitBreakerStrategyOptions
70+
{
71+
// "5 consecutive failures within 60s" expressed as ratio-based (Polly v8 only has ratio-based CB)
72+
FailureRatio = 1.0,
73+
SamplingDuration = TimeSpan.FromSeconds(60),
74+
MinimumThroughput = 5,
75+
BreakDuration = TimeSpan.FromSeconds(30),
76+
ShouldHandle = new PredicateBuilder()
77+
.Handle<McpException>(ex => ex.IsTransient && !ex.IsSecondaryRateLimit)
78+
})
6679
.AddRetry(new Polly.Retry.RetryStrategyOptions
6780
{
6881
MaxRetryAttempts = 3,

0 commit comments

Comments
 (0)