Skip to content

Avoid serializing inline Azure Storage queue messages twice - #1380

Open
Bernd Verst (berndverst) wants to merge 5 commits into
mainfrom
berndverst-avoid-duplicate-queue-serialization
Open

Bernd Verst (berndverst) wants to merge 5 commits into
mainfrom
berndverst-avoid-duplicate-queue-serialization

Conversation

@berndverst

@berndverst Bernd Verst (berndverst) commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • reuse the MessageData JSON already produced for the UTF-8 size check when a queue message stays inline
  • verify byte-for-byte inline payload equivalence with a deterministic custom type binder in both UseDataContractSerialization modes
  • cover the exact 45 KiB inline boundary and the above-threshold blob payload and queue wrapper
  • document custom type-binder expectations and the compatibility caveat for stateful serialization hooks

Backward compatibility

The initial serialization already determines both the queue payload size and the inline/blob decision. TotalMessageSizeBytes is internal and is not a data member. For stable messages with deterministic, side-effect-free serialization, returning that existing JSON on the inline path is byte-for-byte equivalent to the previous second serialization. The size threshold, serializer configuration, public API signatures, queue schema, blob upload content, and blob-reference wrapper serialization are unchanged.

Serialization invocation counts are implementation details, not an API contract. Inline messages now undergo one full serialization pass instead of two. Custom ICustomTypeBinder.BindToName implementations, getters, or serialization callbacks on transport types that change their output or rely on side effects across passes can observe a behavior change and should be reviewed when upgrading. The existing blob path already serializes the full message only once, followed by a separate serialization of the blob-reference wrapper. These expectations are documented in the Azure Storage provider guide and custom type-binder API documentation.

Testing

  • dotnet test Test\DurableTask.AzureStorage.Tests\DurableTask.AzureStorage.Tests.csproj --framework net8.0 --filter "FullyQualifiedName~DurableTask.AzureStorage.Tests.MessageManagerTests"
  • dotnet test Test\DurableTask.AzureStorage.Tests\DurableTask.AzureStorage.Tests.csproj --framework net48 --filter "FullyQualifiedName~DurableTask.AzureStorage.Tests.MessageManagerTests"
  • Rechecked the inline-payload regression cases on both net8.0 and net48 after the documentation update to verify the test helper's binder assignment; both serializer modes passed on both targets.

Fixes #1378

Bernd Verst added 2 commits July 27, 2026 13:38
Reuse the MessageData JSON already produced for size selection when the payload remains inline. Add exact wire-equivalence and threshold-path regression coverage for both serialization modes and a custom binder.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9509e194-db0b-4024-b7b0-26481278e0db
Verify exact inline payload equivalence, single-pass custom binder behavior, and the inline/blob boundary for both data-contract serialization modes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9509e194-db0b-4024-b7b0-26481278e0db
Copilot AI lite review requested due to automatic review settings July 27, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 removes a redundant JSON serialization on the common inline-queue-message path in MessageManager.SerializeMessageDataAsync, reusing the already-produced JSON payload that was generated for the UTF-8 size check. It adds regression tests to assert byte-for-byte equivalence with the prior “serialize twice” behavior (including custom type binder behavior and both UseDataContractSerialization modes), and to validate behavior at the exact 45 KiB inline threshold and just above it (blob offload + wrapper).

Changes:

  • Reuse the initial rawContent JSON string for inline queue payloads instead of serializing MessageData a second time.
  • Add tests validating inline payload equivalence (including custom binder behavior) in both UseDataContractSerialization modes.
  • Add boundary tests covering the exact 45 KiB inline cutoff and the above-threshold blob-wrapper path (including verifying stored blob content).

Reviewed changes

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

File Description
src/DurableTask.AzureStorage/MessageManager.cs Avoids duplicate serialization by returning the already-generated rawContent for inline messages.
test/DurableTask.AzureStorage.Tests/MessageManagerTests.cs Adds regression coverage for inline payload equivalence and for inline/blob behavior at and above the 45 KiB threshold.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings September 4, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is narrowly scoped, preserves the payload format, and is backed by targeted tests covering both serializer modes and the inline/blob threshold boundary.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread src/DurableTask.AzureStorage/MessageManager.cs

@berndverst Bernd Verst (berndverst) left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

.

Copilot AI review requested due to automatic review settings September 22, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The custom binder test helper does not compile for net8.0/net48 and needs the target-appropriate binder implementation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread test/DurableTask.AzureStorage.Tests/MessageManagerTests.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues are reported, and existing behavior is preserved.

Review effort: Lite
Findings: None

Resolved since last review (1)

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.

Avoid serializing inline Azure Storage queue messages twice

3 participants