Skip to content

Replace exception-only retry policy with Result-aware retry logic#7

Draft
Copilot wants to merge 3 commits intoromantic-meninskyfrom
copilot/autonomous-tiger
Draft

Replace exception-only retry policy with Result-aware retry logic#7
Copilot wants to merge 3 commits intoromantic-meninskyfrom
copilot/autonomous-tiger

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 12, 2025

Webhook handlers wrap errors in Result<,> types rather than throwing exceptions. The existing retry policy only caught exceptions, so retries never triggered when handlers returned wrapped errors.

Changes

Upgraded to Polly v8 ResiliencePipeline with result-based retry logic:

  • Retries on IStatusCodeHttpResult with 5xx status codes (transient failures)
  • Retries on uncaught exceptions (infrastructure failures)
  • Skips retries for 4xx responses (permanent failures)

Added observability:

  • Activity events track retry attempts with status codes

Implementation

private static readonly ResiliencePipeline<IResult> ResultAwareRetryPolicy = 
    new ResiliencePipelineBuilder<IResult>()
        .AddRetry(new RetryStrategyOptions<IResult> {
            ShouldHandle = new PredicateBuilder<IResult>()
                .HandleInner<Exception>()
                .HandleResult(result => result is IStatusCodeHttpResult statusResult &&
                                       statusResult.StatusCode >= 500),
            BackoffType = DelayBackoffType.Exponential,
            UseJitter = true,
            MaxRetryAttempts = 5,
            Delay = TimeSpan.FromSeconds(1)
        })
        .Build();

Handlers catch and wrap permanent failures → return 400 → no retry
Handlers catch and wrap transient failures → return 500 → retry
Uncaught exceptions are infrastructure failures → retry

Original prompt

Work on TODO: look into better retry logic since I'm using Result<,> now. (from dotnet/Nudges.Webhooks/Program.cs)

Created from VS Code via the GitHub Pull Request extension.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 12, 2025 15:25
Co-authored-by: nibblesnbits <6042917+nibblesnbits@users.noreply.github.com>
Co-authored-by: nibblesnbits <6042917+nibblesnbits@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve retry logic using Result type Replace exception-only retry policy with Result-aware retry logic Dec 12, 2025
Copilot AI requested a review from nibblesnbits December 12, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants