Skip to content

MF White List: DependencyInjection package and retry filter - #355

Merged
milten89 merged 1 commit into
developfrom
feature/263-white-list-di
Nov 22, 2026
Merged

milten89 merged 1 commit into
developfrom
feature/263-white-list-di

Conversation

@milten89

Copy link
Copy Markdown
Owner

Closes #263

What

  • New package OpenUrzednik.MF.WhiteList.DependencyInjection (still IsPackable=false; MF White List: ship it (packaging and docs) #264 ships it). It is a copy of the NBP DI package.
    • AddOpenUrzednikMFWhiteList() and AddKeyedOpenUrzednikMFWhiteList(key) register WhiteListClient and WhiteListStatusClient, with their interfaces, as typed clients of one named HttpClient.
    • Registration validates the options at start, and calling it twice registers the clients only once.
    • Each client gets its own logger, the shared trace source, and the container's metrics (IMeterFactory, or the shared meter) (ADR-0025, Metrics: an IMeterFactory path for the DI packages #333).
    • AddOpenUrzednikMFWhiteListRejectionHandler() turns resilience-handler rejections into errors.
    • Display-path logging (ADR-0017) is on, with leak tests: no NIP, or any 5 of its digits, appears in what IHttpClientFactory logs.
  • WhiteListRetry.ShouldRetryAsync(HttpResponseMessage, CancellationToken) in the base package returns ValueTask<bool>, the type of Polly's ShouldHandle delegate (ADR-0023, Resilience).
    • It retries 400 WL-195/WL-196, 408, and 5xx except 500 WL-197. It doesn't retry 429 or anything else.
    • It reads the code from the body only for 400 and 500, and reads at most 4096 bytes. It then replaces the response's content with WhiteListReplayContent, which serves those bytes and then the rest of the stream, so the error mapping still reads the whole body.
    • A body over the limit, or one that is unreadable or already consumed, counts as having no code, and the status decides.
    • A test runs the documented snippet against the real AddStandardResilienceHandler.
  • Shared layer: RestRequestExecutor.ReadServerMessageAsync treats an error body that was already consumed (.NET) or closed (.NET Framework) as unreadable, instead of throwing. This also protects NBP when an app's handler reads the error body.
  • Polyfill: a Stream.ReadAsync(Memory<byte>, ct) polyfill for netstandard2.0, bounded with WaitAsync, because .NET Framework's network streams ignore the token once a read has started.
  • Wiring:
    • a new mf-white-list-di mutation shard;
    • slnx/slnf entries, the Architecture tests' SrcAssemblies, AotSmoke DI checks (default and keyed);
    • the CLAUDE.md row, the stryker skill table;
    • the Directory.Packages.props comment.
  • Docs:
    • ADR-0023 corrected in place, with a dated line: the ValueTask return type, how the filter reads the code, and the alternatives it rejected;
    • a new rule in .claude/rules/http.md for any code that reads a response body before the client maps it.

Left for #264

READMEs (including the WhiteListRetry snippet, added to #264's scope in a comment), icon, check_nuget.py, version.json path filters, release-workflow filters, the package description.

Review history

The reviewer agent ran four times:

  1. The first review: nothing blocking. The fixes were the unbounded body read, an #if replaced by a polyfill, and the ADR record.
  2. The second review found a blocking bug. With the filter in a resilience handler, a chunked error body over the limit was consumed by LoadIntoBufferAsync(limit), and the client threw. The reviewer reproduced it on .NET and .NET Framework. The fix is the bounded read plus replay described above, and the shared-layer hardening.
  3. The third review confirmed the fix with the same reproduction on both runtimes. Its follow-ups are applied:
    • cancellation on .NET Framework;
    • compile-error collateral in mutation testing;
    • an unjustified Stryker disable removed;
    • narrower catches;
    • read-once replay content.
  4. The final review: nothing blocking. Its one nit, ADR citations, is applied.

Checks run locally

Check Result
dotnet build OpenUrzednik.slnx -p:TreatWarningsAsErrors=true 0 errors
Tests net10.0 / net472 WhiteList 959 / 934, DI 67 / 58, Http 244 / 245, all pass
Architecture, Integration tests 58 and 309 (WireMock), all pass
Explicit WhiteListRetryTest against the test host (a real chunked 400 WL-118), net10.0 and net472 Pass
dotnet format --verify-no-changes Clean
Mutation mf-white-list 100% (542 killed)
Mutation mf-white-list-di 100% (41 killed)
Mutation http, http-netstandard 100% each
AotSmoke publish and run All checks passed
dotnet pack, package_guard.py OK

mf-white-list-di was last run before the final rounds of review fixes, which didn't change the DI package's code. CI runs it again.

🤖 Generated with Claude Code

OpenUrzednik.MF.WhiteList.DependencyInjection registers WhiteListClient and
WhiteListStatusClient as typed clients of one named HttpClient
(AddOpenUrzednikMFWhiteList, AddKeyedOpenUrzednikMFWhiteList), with
validated options, per-client telemetry and container metrics, the
resilience-rejection handler and display-path logging (ADR-0017).

WhiteListRetry.ShouldRetryAsync (base package, ValueTask<bool> for Polly's
ShouldHandle) answers whether a response is worth retrying: 400 WL-195/196,
408 and 5xx except 500 WL-197. Only for 400 and 500 it reads the code from
the body: at most 4096 bytes, then the response's content is replaced with
one that replays them and the rest of the stream, so the error mapping
still reads the whole body. The shared layer treats an error body that was
already consumed as unreadable instead of throwing.

ADR-0023 is corrected in place; .claude/rules/http.md records the rule.

Closes #263

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milten89 milten89 added the enhancement New feature or request label Nov 22, 2026
@milten89
milten89 merged commit 1b16715 into develop Nov 22, 2026
20 of 21 checks passed
@milten89
milten89 deleted the feature/263-white-list-di branch November 22, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MF White List: DependencyInjection package

2 participants