Skip to content

Stabilize @defer/@stream snapshots with canonical envelope#9935

Merged
glen-84 merged 3 commits into
mainfrom
gai/deterministic-defer-stream-snapshots
Jun 17, 2026
Merged

Stabilize @defer/@stream snapshots with canonical envelope#9935
glen-84 merged 3 commits into
mainfrom
gai/deterministic-defer-stream-snapshots

Conversation

@glen-84

@glen-84 glen-84 commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

  • @defer/@stream snapshots rendered differently depending on how the transport batched the response (one bundled payload vs. several), making them nondeterministic — the cause of an intermittent snapshot mismatch.
  • Reworks the CookieCrumble ExecutionResultSnapshotValueFormatter to reconstruct a single, delivery-order-independent incremental-delivery envelope (data plus pending/incremental/completed gathered across all payloads and ordered by id), so the snapshot is identical whether the response was bundled or split.
  • The snapshots now actually show incremental delivery — deferred errors, labels, paths, and field deduplication are all visible, which the previous merged form silently dropped.
  • Removes the now-redundant MatchAggregatedSnapshot/MatchAggregatedMarkdownSnapshot and the ExecutionResultAggregated formatter; migrates the defer/stream tests to MatchSnapshot/MatchMarkdownSnapshot and re-records 20 snapshots. StableExecutionResultSnapshotValueFormatter is left untouched.

Test plan

  • Full HotChocolate.Execution.Tests green on net9.0 (614 passed, 1 skipped).
  • Ran DeferTests, DeferReferenceTests, and StreamTests repeatedly across separate process launches on net8.0, net9.0, and net10.0 — 0 failures (previously ~40–65% flaky per run on every framework).

Copilot AI review requested due to automatic review settings June 17, 2026 09:10

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 pull request stabilizes @defer/@stream snapshot output by changing CookieCrumble’s execution-result formatting to emit a canonical incremental-delivery “envelope” that is independent of how the transport batches response payloads.

Changes:

  • Reworked ExecutionResultSnapshotValueFormatter to reconstruct a single canonical envelope (data + collected pending/incremental/completed, ordered by id) across all payloads.
  • Updated defer/stream tests to use the normal MatchSnapshot/MatchMarkdownSnapshot APIs and re-recorded snapshots to reflect the canonical envelope.
  • Removed the aggregated snapshot APIs/formatter hooks (now redundant given canonical formatting).

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/HotChocolate/Core/test/Execution.Tests/StreamTests.cs Switch stream tests from aggregated snapshot helper to standard MatchSnapshot().
src/HotChocolate/Core/test/Execution.Tests/DeferTests.cs Switch defer tests from aggregated markdown snapshot helper to standard MatchMarkdownSnapshot().
src/HotChocolate/Core/test/Execution.Tests/DeferReferenceTests.cs Switch defer reference tests from aggregated markdown snapshot helper to standard MatchMarkdownSnapshot().
src/HotChocolate/Core/test/Execution.Tests/snapshots/StreamTests.Stream.snap Update snapshot to canonical incremental-delivery envelope.
src/HotChocolate/Core/test/Execution.Tests/snapshots/StreamTests.Stream_Nested_Defer.snap Update snapshot to canonical incremental-delivery envelope (nested defer).
src/HotChocolate/Core/test/Execution.Tests/snapshots/StreamTests.Stream_Label_Set_To_abc.snap Update snapshot to canonical incremental-delivery envelope (label).
src/HotChocolate/Core/test/Execution.Tests/snapshots/StreamTests.Stream_InitialCount_Set_To_1.snap Update snapshot to canonical incremental-delivery envelope (initialCount=1).
src/HotChocolate/Core/test/Execution.Tests/snapshots/StreamTests.Stream_InitialCount_Exceeds_Total_Count.snap Update snapshot to canonical incremental-delivery envelope (initialCount exceeds total).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.InlineFragment_Defer.md Update snapshot to canonical incremental-delivery envelope (inline fragment defer).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.InlineFragment_Defer_Nested.md Update snapshot to canonical incremental-delivery envelope (nested).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.InlineFragment_Defer_Label_Set_To_abc.md Update snapshot to canonical incremental-delivery envelope (label).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.FragmentSpread_Defer.md Update snapshot to canonical incremental-delivery envelope (fragment spread).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.FragmentSpread_Defer_Nested.md Update snapshot to canonical incremental-delivery envelope (nested).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.FragmentSpread_Defer_Label_Set_To_abc.md Update snapshot to canonical incremental-delivery envelope (label).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.Ensure_GlobalState_Is_Passed_To_DeferContext_Stacked_Defer.md Update snapshot to canonical incremental-delivery envelope (stacked defer).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.Ensure_GlobalState_Is_Passed_To_DeferContext_Stacked_Defer_2.md Update snapshot to canonical incremental-delivery envelope (stacked defer variant).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.Ensure_GlobalState_Is_Passed_To_DeferContext_Single_Defer.md Update snapshot to canonical incremental-delivery envelope (single defer).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferTests.Ensure_GlobalState_Is_Passed_To_DeferContext_Single_Defer_2.md Update snapshot to canonical incremental-delivery envelope (single defer variant).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferReferenceTests.InlineFragment_Defer_With_TypeCondition.md Update snapshot to canonical incremental-delivery envelope (type condition).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferReferenceTests.Emits_Children_Of_Empty_Defer_Fragment.md Update snapshot to canonical incremental-delivery envelope (empty fragment).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferReferenceTests.Defer_Fragment_With_Errors_On_Top_Level_Query_Field.md Update snapshot to canonical incremental-delivery envelope (deferred errors).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferReferenceTests.Defer_Fragment_With_Error.md Update snapshot to canonical incremental-delivery envelope (deferred resolver error).
src/HotChocolate/Core/test/Execution.Tests/snapshots/DeferReferenceTests.Deduplicates_List_Fields_In_Initial_Payload.md Update snapshot to canonical incremental-delivery envelope (dedup behavior visibility).
src/CookieCrumble/src/CookieCrumble.HotChocolate/Formatters/SnapshotValueFormatters.cs Removes the ExecutionResultAggregated formatter accessor.
src/CookieCrumble/src/CookieCrumble.HotChocolate/Formatters/ExecutionResultSnapshotValueFormatter.cs Implements canonical incremental-delivery envelope reconstruction for streamed results.
src/CookieCrumble/src/CookieCrumble.HotChocolate/Extensions/SnapshotExtensions.cs Removes the aggregated snapshot extension methods.

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

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the branch remains at 49%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File 7cb2688 88d8fd8 +/-
/home/runner/wo...tDiagnostics.cs 88% 73% -15%
/home/runner/wo...lueFormatter.cs 85% 81% -4%
/home/runner/wo...entsListener.cs 66% 62% -4%
/home/runner/wo...gerMessage.g.cs 28% 26% -2%
/home/runner/wo...DefaultTopic.cs 90% 89% -1%
/home/runner/wo...pshotHelpers.cs 68% 69% +1%
/home/runner/wo...geDispatcher.cs 75% 77% +2%
/home/runner/wo...PromiseCache.cs 78% 81% +3%
/home/runner/wo...qlConnection.cs 89% 92% +3%
/home/runner/wo...gerMessage.g.cs 15% 19% +4%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants