fix(asb): add SequenceNumber to ReservedHeaders to prevent duplicate key on redelivery#4187
Merged
iancooper merged 4 commits intoJun 17, 2026
Conversation
…key on redelivery SequenceNumber was surfaced in the message header bag but not added to ReservedHeaders. On requeue (DeferMessageAction), the publisher serialised it into ApplicationProperties. On redelivery, MapToBrighterMessage added the native broker SequenceNumber then hit the stale ApplicationProperties value, throwing ArgumentException: duplicate key. Fixes the same class of bug that LockToken's ReservedHeaders entry prevents. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…elivered test Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
iancooper
approved these changes
Jun 16, 2026
There was a problem hiding this comment.
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
Member
|
Thanks @MikeFreeman-Flagstone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SequenceNumberwas surfaced in the message header bag (AzureServiceBusMesssageCreator.cs:110) but not added toASBConstants.ReservedHeadersDeferMessageAction), the publisher serialised it intoApplicationPropertiesof the outgoing messageMapToBrighterMessageadded the native brokerSequenceNumber(line 110), then hit the stale copy inApplicationProperties(line 114), throwingArgumentException: An item with the same key has already been added. Key: SequenceNumberSequenceNumberBagKeytoReservedHeaders— the same protectionLockTokenhas always hadTest plan
When_Converting_A_Message_The_SequenceNumber_Bag_Entry_Is_Not_Written_To_ApplicationProperties— asserts the fix:SequenceNumberis absent fromApplicationPropertiesafterConvertToServiceBusMessageWhen_a_deferred_message_is_redelivered_it_does_not_throw_a_duplicate_key_exception— full round-trip: receive → requeue → receive again withoutArgumentExceptionWhen_mapping_a_message_the_sequence_number_is_added_to_the_header_bag— existing test confirmsSequenceNumberstill reaches the consumer bag after the fixCloses #4186
🤖 Generated with Claude Code