Skip to content

fix(asb): add SequenceNumber to ReservedHeaders to prevent duplicate key on redelivery#4187

Merged
iancooper merged 4 commits into
BrighterCommand:masterfrom
MikeFreeman-Flagstone:fix/sequence-number-cause-argument-exception
Jun 17, 2026
Merged

fix(asb): add SequenceNumber to ReservedHeaders to prevent duplicate key on redelivery#4187
iancooper merged 4 commits into
BrighterCommand:masterfrom
MikeFreeman-Flagstone:fix/sequence-number-cause-argument-exception

Conversation

@MikeFreeman-Flagstone

@MikeFreeman-Flagstone MikeFreeman-Flagstone commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • SequenceNumber was surfaced in the message header bag (AzureServiceBusMesssageCreator.cs:110) but not added to ASBConstants.ReservedHeaders
  • On requeue (DeferMessageAction), the publisher serialised it into ApplicationProperties of the outgoing message
  • On redelivery, MapToBrighterMessage added the native broker SequenceNumber (line 110), then hit the stale copy in ApplicationProperties (line 114), throwing ArgumentException: An item with the same key has already been added. Key: SequenceNumber
  • Fix: add SequenceNumberBagKey to ReservedHeaders — the same protection LockToken has always had

Test plan

  • When_Converting_A_Message_The_SequenceNumber_Bag_Entry_Is_Not_Written_To_ApplicationProperties — asserts the fix: SequenceNumber is absent from ApplicationProperties after ConvertToServiceBusMessage
  • When_a_deferred_message_is_redelivered_it_does_not_throw_a_duplicate_key_exception — full round-trip: receive → requeue → receive again without ArgumentException
  • When_mapping_a_message_the_sequence_number_is_added_to_the_header_bag — existing test confirms SequenceNumber still reaches the consumer bag after the fix

Closes #4186

🤖 Generated with Claude Code

…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>
codescene-delta-analysis[bot]

This comment was marked as outdated.

…elivered test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@codescene-delta-analysis codescene-delta-analysis 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.

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.

@iancooper iancooper merged commit 624a8bd into BrighterCommand:master Jun 17, 2026
48 of 51 checks passed
@iancooper

Copy link
Copy Markdown
Member

Thanks @MikeFreeman-Flagstone

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.

bug: SequenceNumber causes ArgumentException on message redelivery when using DeferMessageAction with Azure Service Bus

2 participants