Skip to content

Conversation

iliar-turdushev
Copy link
Contributor

@iliar-turdushev iliar-turdushev commented Jul 16, 2025

This PR introduces an additional attempt to retrieve the request message from the resilience context, complementing the existing retrieval from the response. This enhancement addresses a bug where the resilience pipeline failed before a response was received, resulting in unintended retries for HTTP methods that should not have been retried.

Fixes #6548.

Microsoft Reviewers: Open in CodeFlow

Adds an attempt to retrieve the request message from the resilience context in addition to retrieving the request from the response
@Copilot Copilot AI review requested due to automatic review settings July 16, 2025 16:31
@iliar-turdushev iliar-turdushev requested a review from a team as a code owner July 16, 2025 16:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the HTTP resilience pipeline where retry logic failed to properly disable retries for certain HTTP methods when the resilience pipeline failed before receiving a response. The fix adds fallback logic to retrieve the request message from the resilience context when it's not available in the response.

  • Extracts request message retrieval logic into a helper method that checks both response and context
  • Updates test cases to verify the new fallback behavior when response is null
  • Adds proper context setup in test methods to support the enhanced retrieval logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
HttpRetryStrategyOptionsExtensions.cs Adds helper method to retrieve request message from response or context as fallback
HttpRetryStrategyOptionsExtensionsTests.cs Updates tests to verify context-based request retrieval and adds missing using statement

@iliar-turdushev iliar-turdushev merged commit 006a569 into dotnet:main Jul 22, 2025
7 checks passed
@iliar-turdushev iliar-turdushev deleted the httpresilience-fix branch July 22, 2025 10:48
This was referenced Aug 13, 2025
joakimia pushed a commit to heimdallpower/api-sdk that referenced this pull request Aug 21, 2025
Updated
[Microsoft.Extensions.Http.Resilience](https://github.com/dotnet/extensions)
from 9.7.0 to 9.8.0.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Extensions.Http.Resilience's
releases](https://github.com/dotnet/extensions/releases)._

## 9.8.0

## What's Changed
* Align EventId generation with M.E.Logging source-gen by @​xakep139 in
dotnet/extensions#6566
* Add resiliency mechanism to CPU and memory utilization checks by
@​amadeuszl in dotnet/extensions#6528
* Suppress flaky test until fixed by @​joelverhagen in
dotnet/extensions#6568
* Create a project template for an MCP server by @​joelverhagen in
dotnet/extensions#6547
* Use dnx instead of dotnet tool exec in MCP server template README by
@​joelverhagen in dotnet/extensions#6571
* Add reporting tests that show NLP results. by @​peterwald in
dotnet/extensions#6574
* Branding updates for 9.8.0 by @​joperezr in
dotnet/extensions#6573
* Fix `ConfigureEvaluationTests.ps1` script when `$ConfigRoot` is not
supplied by @​peterwald in
dotnet/extensions#6575
* Refactor Resource Monitoring by @​evgenyfedorov2 in
dotnet/extensions#6554
* Update McpServer template for 0.3.0-preview.2 by @​stephentoub in
dotnet/extensions#6578
* Add container.cpu.time metric by @​evgenyfedorov2 in
dotnet/extensions#5806
* Add netstandard2.0 compatibility to
Microsoft.Extensions.Diagnostics.Testing and dependencies by @​bdovaz in
dotnet/extensions#6219
* Add netstandard2.0 compatibility to Microsoft.Extensions.Telemetry and
dependencies by @​bdovaz in
dotnet/extensions#6218
* Simplify Http.Diagnostics by @​pentp in
dotnet/extensions#6174
* Add netstandard2.0 compatibility to
Microsoft.Extensions.Http.Resilience and dependencies by @​bdovaz in
dotnet/extensions#6582
* Ingore null loggers returned by LogProviders in ELoggerFactory by
@​petrroll in dotnet/extensions#6585
* Merging changes from internal by @​joperezr in
dotnet/extensions#6588
* [Logging] Fixes LogProperties and LogPropertyIgnore attributes to work
if an object being logged resides in a different assembly than the
logging method by @​iliar-turdushev in
dotnet/extensions#6600
* Add memory usage metric by @​evgenyfedorov2 in
dotnet/extensions#6586
* Add schema version to server.json in MCP template by @​joelverhagen in
dotnet/extensions#6606
* Merge release/9.7 into main by @​joperezr in
dotnet/extensions#6589
* Update MCP server template readme to show both VS Code and Visual
Studio notes by @​Copilot in
dotnet/extensions#6591
* Update Azure Open AI package referenced by eval integration tests by
@​shyamnamboodiripad in dotnet/extensions#6609
* Target .NET 8 for more stable runtime requirement by @​joelverhagen in
dotnet/extensions#6617
* Add support for new Azure AI Foundry project type for Safety evals by
@​shyamnamboodiripad in dotnet/extensions#6621
* M.E.AI.AzureAIInference - Azure.AI.Inference Package Bump by
@​rogerbarreto in dotnet/extensions#6624
* Add DataContent.Name property by @​stephentoub in
dotnet/extensions#6616
* Fix handling of multiple responses messages by @​stephentoub in
dotnet/extensions#6627
* Expose additional chat model conversion helpers by @​stephentoub in
dotnet/extensions#6629
* [main] Update dependencies from dotnet/arcade by @​dotnet-maestro[bot]
in dotnet/extensions#6633
* [Http.Resilience] The DisableFor method should try to retrieve the
request object from the resilience context by @​iliar-turdushev in
dotnet/extensions#6618
* Bump Package validation baseline version to 9.7.0 by @​Copilot in
dotnet/extensions#6650
* Fix internal package version detection for project templates by
@​MackinnonBuck in dotnet/extensions#6651
* Remove `Microsoft.Extensions.AI.Ollama` by @​MackinnonBuck in
dotnet/extensions#6655
* Fix M.E.AI package refs by @​stephentoub in
dotnet/extensions#6654
* Add [Description] to DataContent.Uri by @​stephentoub in
dotnet/extensions#6615
* Fix duplicate solution file when creating an AI Chat Web app from VS
by @​MackinnonBuck in dotnet/extensions#6653
* Add ChatMessage.CreatedAt by @​stephentoub in
dotnet/extensions#6657
* Add TextContent.Annotations by @​stephentoub in
dotnet/extensions#6619
* Add FunctionInvokingChatClient.AdditionalTools by @​stephentoub in
dotnet/extensions#6661
* Fix unintentional test env var change by @​stephentoub in
dotnet/extensions#6660
* Add more openai conversion helpers by @​stephentoub in
dotnet/extensions#6662
* Add OriginalRepoCommitHash to assemblies by @​BrennanConroy in
dotnet/extensions#6667
* Include a trivial items keyword if missing. by @​eiriktsarpalis in
dotnet/extensions#6669
* Add resolution of function parameter level data annotation attributes.
by @​eiriktsarpalis in dotnet/extensions#6671
* Fix issue with NetSourceIndexStage1 for dependency conflict versions
by @​joperezr in dotnet/extensions#6672
* Expose streaming conversion utility methods by @​stephentoub in
dotnet/extensions#6636
* Couple of fixes for MEAI.Evaluation by @​shyamnamboodiripad in
dotnet/extensions#6673
* Fix one more version conflict on the docs transport package by
@​joperezr in dotnet/extensions#6675
 ... (truncated)

## 9.7.2

## Packages Released

* [Microsoft.Extensions.AI.Templates
9.7.2-preview.3.25366.2](https://www.nuget.org/packages/Microsoft.Extensions.AI.Templates/9.7.2-preview.3.25366.2)

## What's Changed

* Target .NET 8 for more stable runtime requirement by @​joelverhagen in
#​6617

**Full Changelog**:
dotnet/extensions@v9.7.1...v9.7.2

## 9.7.1

## Packages Released

* [Microsoft.Extensions.AI
9.7.1](https://www.nuget.org/packages/Microsoft.Extensions.AI/9.7.1)
* [Microsoft.Extensions.AI.Abstractions
9.7.1](https://www.nuget.org/packages/Microsoft.Extensions.AI.Abstractions/9.7.1)
* [Microsoft.Extensions.AI.OpenAI
9.7.1-preview.1.25365.4](https://www.nuget.org/packages/Microsoft.Extensions.AI.OpenAI/9.7.1-preview.1.25365.4)
* [Microsoft.Extensions.AI.AzureAIInference
9.7.1-preview.1.25365.4](https://www.nuget.org/packages/Microsoft.Extensions.AI.AzureAIInference/9.7.1-preview.1.25365.4)
* [Microsoft.Extensions.AI.Templates
9.7.1-preview.3.25365.4](https://www.nuget.org/packages/Microsoft.Extensions.AI.Templates/9.7.1-preview.3.25365.4)

## What's Changed

* Merging changes from internal by @​joperezr in #​6588
* Bump FunctionInvokingChatClient.MaximumIterationsPerRequest from 10 to
40 by @​stephentoub in #​6599
* Expose M.E.AI.OpenAI input message conversions by @​stephentoub in
#​6601
* Add schema version to server.json in MCP template by @​joelverhagen in
#​6606
* Update MCP server template readme to show both VS Code and Visual
Studio notes by @​jeffhandley in #​6591
* Fix schema generation for Nullable<T> function parameters. by
@​eiriktsarpalis in #​6596
* Branding updates for 9.7.1 by @​joperezr in
dotnet/extensions#6611
* Add DelegatingAIFunction by @​stephentoub in
dotnet/extensions#6565
* Add FunctionInvokingChatClient.FunctionInvoker delegate by
@​stephentoub in dotnet/extensions#6564
* Enable specifying "strict" for OpenAI clients via ChatOptions by
@​stephentoub in dotnet/extensions#6552
* AIFunctionFactory: tolerate JSON string function parameters. by
@​eiriktsarpalis in dotnet/extensions#6572
* AIFunctionFactory: add test coverage for JSON comments. by
@​eiriktsarpalis in dotnet/extensions#6576
* Update M.E.AI.OpenAI for latest OpenAI release by @​stephentoub in
dotnet/extensions#6577
* Update OpenTelemetry semantic conventions version from 1.35 to 1.36 by
@​Copilot in dotnet/extensions#6579
* AIFunctionFactory: add a flag for disabling return schema generation.
by @​eiriktsarpalis in dotnet/extensions#6551
* Bump FunctionInvokingChatClient.MaximumIterationsPerRequest from 10 to
40 by @​stephentoub in dotnet/extensions#6599
* Expose M.E.AI.OpenAI input message conversions by @​stephentoub in
dotnet/extensions#6601
* Fix schema generation for Nullable<T> function parameters. by
@​eiriktsarpalis in dotnet/extensions#6596


**Full Changelog**:
dotnet/extensions@v9.7.0...v9.7.1

Commits viewable in [compare
view](dotnet/extensions@v9.7.0...v9.8.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Extensions.Http.Resilience&package-manager=nuget&previous-version=9.7.0&new-version=9.8.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extensions.Http.Resilience: Unexpected default behaviour of Retry.DisableForUnsafeHttpMethods in combination with TimeoutRejectedException
2 participants