Skip to content

Execute consumer retries and durable failure handling - #88

Merged
thomhurst merged 2 commits into
mainfrom
issue-9-failure-pipeline
Nov 1, 2026
Merged

thomhurst merged 2 commits into
mainfrom
issue-9-failure-pipeline

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

When a handler fails, Relayer can now run immediate retries in fresh scopes, choose a validated native redelivery or durable copy path, and dead-letter poison messages with the complete failure history. Original settlement follows successful durable handling. Failed attempts discard buffered direct sends; successful sends flush after scope disposal.

Composition reuses the startup capability cache, validates every configured delay and the dead-letter path, and requires actual fallback executors. Native redelivery carries owned failure headers. Scheduled/dead-letter copies retain the original identity, creation context, body, headers, ordering key and supported native configuration.

Includes concurrent send buffering, scoped sender reuse, deterministic failure-path tests, Native AOT smoke coverage, MemoryDiagnoser benchmarks, and the public composition example. Native broker adapters and concrete outbox stores remain their existing scaffolds; tests exercise the core's executable transport/scheduler seams.

Closes #9
Validation on b7f8643088ea110356babead17dcd2b783042939, rebased onto topology PR #81:

  • dotnet build -c Release: passes, 0 warnings/errors.
  • dotnet test -c Release --no-build: 291 passed, 0 failed/skipped. Includes 26 failure-pipeline cases: exact native/scheduled delay boundaries, durable scheduler and dead-letter fallbacks, poison envelopes, complete error histories across redelivery, fresh retry scopes, deterministic backoff/cancellation, concurrent send buffering, partial flush failure, scope-disposal failure and startup validation.
  • Windows x64 Native AOT publish and executable pass with reflection disabled, including generated error metadata, poison-message handling and existing sender/topology checks.
  • MemoryDiagnoser: all six successful-processing cases allocate the same 432 B of DI bookkeeping/handler construction, including direct scoped dispatch, the explicit callback pipeline and executable failure handling, with and without one handler send. The warmed allocation regression test also confirms 0 additional bytes over equivalent DI/JSON work.
  • Code-simplifier review, rebase range-diff inspection and git diff --check pass.

Per-message cost: ordinary direct sends add a nullable buffer check, 0 B. Failure-enabled processing adds failure-header lookups and scoped sender resolution; successful handler sends copy payload/header storage into pooled slots and flush after successful async scope disposal. Buffer slot reservation supports concurrent awaited sends without locks. Error history serialization and durable fallback allocations occur only on failure.

The benchmark's synchronous sink isolates pipeline cost; it is not a real-broker throughput acceptance run. The 5% raw-native-client throughput budget remains unverified locally because native adapters are still scaffolds. No throughput/latency trade-off is claimed from these diagnostic numbers. Partial successful-send flushes and copy-versus-completion/cancellation races can duplicate messages, so downstream processing still needs idempotency (D9/D24). Active outbox sends retain transactional enlistment; their transaction owner must roll back a failed attempt.

Archived raw build/test/AOT/benchmark logs, reports, generated benchmark harness and loaded binaries, test binaries, native executable and committed source snapshot: C:/git/Relayer-evidence/pr-88/b7f8643088ea110356babead17dcd2b783042939/. The 642-file inventory was verified by SHA-256 against the original files (the source snapshot is generated directly by git archive for this head). inventory.json SHA-256: 00e3c43ce4cf86848e54833006798ead955fdbb603c220dc4c79d1e895160913. Standard seven-day evidence retention applies.

Review fix validation on 569154508a6b52a06cc1a0e687390740120c3b19:

  • Keep attempt buffering attached throughout async scope disposal. Return the pooled sender only after disposal finishes, including when an earlier disposer throws before DI reaches the sender.
  • Five regression cases cover sends during successful disposal, failed handlers, failed disposal, and suspended disposal with a competing sender scope. All five fail on the original head. Sender reuse after disposal failure is also checked.
  • Stabilize the existing allocation regression test with explicit DI factories. DI's runtime constructor resolver allocates argument arrays until its background compilation completes; that transition inflated the baseline during one full-suite run. The strict allocation equality assertion remains unchanged, and both warm-up paths now resolve the sender.
  • dotnet build -c Release: passes, 0 warnings/errors. dotnet test -c Release --no-build: 296 passed, 0 failed/skipped. Windows x64 Native AOT publish and smoke executable pass with reflection disabled. Code-simplifier review and git diff --check pass.
  • Incremental per-message cost: one null check during sender disposal and one lifecycle call per attempt, 0 B; the existing pool return occurs after scope disposal. Buffer algorithms are unchanged, so this lifecycle bug fix does not require a new benchmark. The earlier benchmark results remain measurements of b7f8643088ea110356babead17dcd2b783042939 only.

Archived current test binaries/reports, native executable, raw validation logs, failing regression/allocation logs, DI inspection output, and committed source snapshot: C:/git/Relayer-evidence/pr-88/569154508a6b52a06cc1a0e687390740120c3b19/. All 462 inventory entries were SHA-256 verified; copied files were also checked against their originals. inventory.json SHA-256: 26868a9aac72f38118f51f321f3ea4cc6a541f2b39ddbf4f83af5eb784e8cc06. Standard seven-day evidence retention applies.

Evidence inventories rechecked before promotion on 2026-11-01: all 642 baseline and 462 current-head archived files match their recorded SHA-256 hashes. The original implementation worktrees were removed by normal checkout cleanup. Remaining originals also match their recorded hashes; the full archive-to-original verification occurred when those archives were created.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 71a96a7c-de82-4d25-9613-e9fb5c1b6f98
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thomhurst

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T12:22:52.654521Z 5691545 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review of #88 (failure pipeline)

Scope: I read FailurePipeline.cs, the ConsumePipeline.ProcessWithFailuresAsync changes and AttemptSendBuffer.cs against AGENTS.md. I did not read the tests, the benchmarks, the transport adapters or the remaining diff files in detail, and I did not build or run anything.

What looks sound

  • Startup validation is fail-early and actionable (D16/D24). It checks the jitter, timeout and delay ranges, a unique named ITransport, the dead-letter path, and an executor for every redelivery delay.
  • Each attempt gets a fresh DI scope. The scoped sender is detached in finally, and the buffered sends are cleared on failure. They are flushed only after the successful scope is disposed. This matches the 'settle only after the work is durable' rule.
  • The happy path has no new reflection, LINQ or locks. The error-path allocations (List, header arrays, linked CTS) are acceptable there.
  • AttemptSendBuffer reuses its entries and buffers, which keeps the flush path at 0 B in steady state.

Non-blocking notes

  1. A flush that fails partway through (AttemptSendBuffer.FlushAsync) leaves earlier sends already delivered. The message is then redelivered and the handler re-runs, so those sends are duplicated. This is the correct at-least-once outcome and the PR describes it. I'd state it explicitly in the design.md section so consumers know to make downstream handling idempotent.
  2. CopyAsync calls timeout.Token.ThrowIfCancellationRequested() after a successful send. If the timeout fires just after the copy lands, the copy is reported as failed and the message is redelivered, which duplicates the copy. This is safe for at-least-once delivery, and a one-line comment saying it is deliberate would help.
  3. The happy path now calls GetService<ISender> once per attempt. It is a cheap lookup in a scope that is already created. The PR states the per-message cost, so no benchmark is needed.

No correctness, security or performance-budget violations found in what I reviewed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7f8643088

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Relayer/Pipeline/ConsumePipeline.cs Resolved
@thomhurst

Copy link
Copy Markdown
Owner Author

Disposition of Claude's current-head review:

  1. Non-blocking documentation suggestion. The failure-handling section already states that partial flushes propagate because an earlier send may have succeeded; D9 and the outbox/inbox section describe downstream idempotency. Keep the reviewed head without a wording-only push.
  2. Non-blocking comment suggestion. The post-send cancellation check deliberately prevents returning successful settlement after cancellation. A copy can already be durable, so duplicates remain possible under D24. The PR's validation notes retain this limitation without another push.
  3. Acknowledged. The scoped sender lookup adds no steady-state allocation. MemoryDiagnoser coverage is included because buffering adds payload/header copies and a flush loop, which AGENTS.md requires benchmarking.

@thomhurst

Copy link
Copy Markdown
Owner Author

@codex review

The blocking scope-disposal finding is fixed in 5691545 and dispositioned on its thread. The PR remains draft for fresh head-bound reviews. Release build, all 296 tests, and Windows x64 Native AOT smoke pass. The PR body records the verified evidence archive and the DI allocation-test stabilization.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review of head b7f8643

I read FailurePipeline, ConsumePipeline, AttemptSendBuffer, SenderPool and Sender in full. I did not read the 671-line test file or the benchmark. I did not build or run anything, so I'm relying on the PR's reported results (291 tests passing, AOT smoke, 432 B allocation parity).

No blocking issues found.

What checks out:

  • Settlement ordering. Scope disposal runs before the buffered sends flush. A flush failure propagates instead of retrying the handler. Failed attempts call Clear() on the buffer. The finally blocks release the sender and buffer even if a disposer throws.
  • Startup validation. Every delay is checked for being finite and non-negative. The code requires an actual executor for each redelivery path (native, copy, outbox) and for the dead-letter path, which matches D16/D24 (fail early, no silent degradation). Jitter only shortens a delay, so a delay validated against a native or scheduling maximum stays within it.
  • Per-message path. There is no reflection or LINQ. The failure-only work (Record, Task.Delay, header arrays, the copy list) sits on the error path. Direct sends add one nullable buffer check. This matches the PR's stated cost.
  • Duplicate-delivery caveats. The partial-flush and copy-vs-timeout races are documented in the PR and covered by D9/D24 idempotency.

Non-blocking observations:

  1. SenderPool.Rent runs Interlocked.Exchange on every slot from index 0, including slots that are already null. Each call writes to the cache line, so many concurrent consumers will contend there. A Volatile.Read(ref slot) is not null check before the exchange would avoid the writes. ConsumePipeline.RentContext has the same pattern, so it could be fixed in both places. This changes constant-time pool cost only, so per AGENTS.md no benchmark is needed.
  2. PooledSender.Dispose has no guard against a double dispose. If it ran twice with AttemptBuffer already null, the same instance would go into the pool twice and two scopes could then share it. A user-code double dispose is unlikely. An Interlocked state flag on rent and return would make it fail safe.
  3. A handler that keeps its scoped ISender after the scope ends (fire-and-forget) would now use a recycled pooled instance. The docs could state that ISender must not outlive the handler scope.
  4. The native dead-letter description uses error.Message directly. Some brokers cap description length (for example Service Bus), so truncating it would be safer. The complete history is already in the headers.

@thomhurst

Copy link
Copy Markdown
Owner Author

Disposition of Claude's review for 569154508a6b52a06cc1a0e687390740120c3b19:

  1. Non-blocking optimization. Changing pool synchronization is separate performance work; no contention regression is demonstrated here. This fix adds one disposal check and one lifecycle call per attempt, 0 B. Keep the existing pool algorithm in this correction.
  2. Non-blocking defensive suggestion. Relayer registers the pooled sender once per DI scope. With an attached attempt buffer, DI's Dispose does not return it; the pipeline's single finally returns it after scope disposal. Ordinary sender scopes return it once through DI. Explicitly disposing a container-owned service twice is outside that lifetime contract; an additional Interlocked operation is not justified by an actual double-return path.
  3. Non-blocking documentation suggestion. The failure-handling section already requires awaiting every handler send. Scoped ISender follows its DI scope's lifetime. No documentation-only push is needed for this disposal fix.
  4. Non-blocking transport concern. Broker limits differ, so a native adapter must map DeadLetterInfo to its client's native constraints; the core cannot choose a portable truncation length. The full error history remains in the headers. Concrete broker settlement adapters remain outside this PR's core execution scope.

The review text repeats the previous head's title and test count; the current head has 296 passing tests, with validation and archived evidence recorded in the updated PR body. The PR stays draft while fresh Codex review is pending.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 569154508a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@thomhurst
thomhurst marked this pull request as ready for review November 1, 2026 12:20
@thomhurst
thomhurst enabled auto-merge (squash) November 1, 2026 12:20
@thomhurst

Copy link
Copy Markdown
Owner Author

Both required reviewers cleared 5691545. All review surfaces were checked, the prior blocking thread is resolved, and Claude's non-blocking observations already have dispositions. Reverified all 642 baseline and 462 current-head evidence hashes and updated the PR body.

Promoted and armed squash auto-merge with scripts/Enable-AutoMerge.ps1 -Pr 88 -MarkReady. Ready CI run: https://github.com/thomhurst/Relayer/actions/runs/41305986093. No source changes or new local test runs in this unit. GitHub will merge the reviewed head when required checks pass.

@thomhurst
thomhurst merged commit bf3191f into main Nov 1, 2026
12 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 569154508a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +68 to +70
if (AttemptBuffer is not null) return;
Outbox = null;
owner.Return(this);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve sender ownership through ordinary scope disposal

Once any FailurePipeline enables the pool, ordinary DI scopes also receive pooled senders, but their AttemptBuffer is null, so this callback clears Outbox and returns the sender before the remaining scoped services finish disposing. If a service resolved before the sender captures it later and sends during DisposeAsync, that send now bypasses its still-active outbox; if disposal suspends, another scope can rent the same sender and attach a different outbox or attempt buffer. The attempt-disposal fix protects attached senders only, leaving this ordinary-scope path exposed. Keep ordinary scoped senders reserved, with their original enlistment, until all services that can use them have finished disposing.

Useful? React with 👍 / 👎.

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.

Failure pipeline: classification, retries, redelivery and dead-lettering

1 participant