Improve Defer Plans#9602
Merged
michaelstaib merged 13 commits intomainfrom Apr 30, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors Fusion’s @defer planning/execution to improve requirement hoisting and nested-defer handling by introducing “incremental plans” with explicit plan-scope requirements and parent-scope dependencies, and updates plan serialization plus regression fixtures accordingly.
Changes:
- Replace
ExecutionSubPlan/DeferUsageconcepts withIncrementalPlan/DeliveryGroup, including a sharedIOperationPlanexecutor contract. - Add planning-time parent-scope tracking (
PlanContextGraph,ParentPlanContext) and parent-step dependency wiring (ParentStepRef,ParentDependencies) to support defer requirement routing. - Update executor/runtime to materialize parent-sourced requirement snapshots for deferred sub-plans and adjust JSON/YAML plan serialization + snapshots/tests.
Reviewed changes
Copilot reviewed 66 out of 68 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_RequirementReachableFromParent_Should_InjectIntoParentOp_When_SameSubgraph.yaml | New/updated snapshot for defer requirement hoisting behavior. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_RequirementOnForeignSubgraph_Should_PlanParentScopeLookup.yaml | New/updated snapshot for cross-subgraph requirement routing. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_NestedDefer_InnerRequirement_Should_ResolveAtOuterScope_When_SameSubgraphAsOuterKey.yaml | New/updated snapshot for nested defer requirement scoping. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_NestedDefer_InnerRequirement_Should_ResolveAgainstOuterDefer.yaml | New/updated snapshot for nested defer requirement reuse. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_NestedDefer_InnerRequirement_OnForeignSubgraph_Should_PlanLookupInOuterScope.yaml | New/updated snapshot for nested foreign-subgraph requirement routing. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_NestedDefer_InnerAndOuterShareRequirement_Should_DeduplicateAtOuter.yaml | New/updated snapshot for requirement dedup across nested defers. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/snapshots/DeferPlannerTests.Defer_MultipleDeferGroupsShareRequirement_Should_DeduplicateHoistedField.yaml | New/updated snapshot for sibling-group requirement dedup. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Planning/DeferPlannerTests.cs | Update existing tests to IncrementalPlans and add new regression tests for requirement routing/dedup. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/FusionTestBase.cs | Allow passing planner options into PlanOperation. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Serialization/snapshots/JsonOperationPlanSerializationTests.Parse_Plan_Preserves_DeliveryGroup_Identity_Across_Plan_And_SubPlans.snap | Snapshot update for new plan shape (requirements + parent dependencies). |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Serialization/JsonOperationPlanSerializationTests.cs | Update assertions to IncrementalPlans and add coverage for parent dependency round-tripping. |
| src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Results/FetchResultStoreTests.cs | New unit tests for requirement snapshot merging/dedup and error handling. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_With_Error_In_Deferred_Fragment_Should_Return_Error_In_Incremental_Payload.yaml | Snapshot update reflecting requirement injection into parent op + new dependency encoding. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_Two_Siblings_With_Overlapping_Fields_Should_Deduplicate.yaml | Snapshot update reflecting hoisted requirement and parent dependency serialization. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_Two_Siblings_Sharing_Field_Emit_One_Incremental_That_Completes_Both_Groups.yaml | Snapshot update reflecting merged incremental behavior. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_Single_Fragment_Returns_Incremental_Response.yaml | Snapshot update reflecting hoisted requirement and parent dependency serialization. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_Nested_Without_Label_On_Inner_Should_Return_Incremental_Response.yaml | Snapshot update reflecting hoisted requirement and parent dependency serialization. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_Nested_Should_Return_Incremental_Response_In_Order.yaml | Snapshot update reflecting updated plan structure and dependency encoding. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_IfTrue_Variable_Should_Return_Streamed_Result.yaml | Snapshot update for @skip/@defer interplay and injected requirements. |
| src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/snapshots/DeferTests.Defer_IfFalse_Variable_Should_Return_NonStreamed_Result.yaml | Snapshot update for conditional defer and injected requirements. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Properties/FusionExecutionResources.resx | Resource key rename for incremental-plan parent resolution errors. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Properties/FusionExecutionResources.Designer.cs | Designer update for renamed resource key. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/Steps/ParentStepRef.cs | New type to represent parent-scope step dependencies. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/Steps/OperationPlanStep.cs | Add ParentDependencies to planning step model. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/RequirementConsumer.cs | Introduce discriminator to route requirements to either a step or an incremental-plan descriptor. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/PlannerCostEstimator.cs | Adjust inline-cost logic to account for new consumer model. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/PlanContextGraph.cs | New structure to track enclosing scope for nested deferred sub-plans. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/ParentPlanContext.cs | New record to represent mutable parent-scope state during defer routing. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.cs | Rework defer planning pipeline to route requirements before compiling root op; rename types. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.BuildExecutionTree.cs | Build incremental plans, assign ids, resolve parent node ids; emit parent dependency wiring. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/IncrementalPlanDescriptor.cs | New descriptor carrying delivery-group set plus plan-scope requirements. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/FieldWithRequirementWorkItem.cs | Replace raw step id with RequirementConsumer. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/FieldOccurrence.cs | Rename enclosing defer tracking to delivery-group terminology. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/FieldLocation.cs | Update docs to delivery-group set key terminology. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeliveryGroupSetKey.cs | Rename/replace defer usage set key with delivery group set key. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferSubPlanResult.cs | New result type for defer sub-plan planning pass. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferSubPlanDescriptor.cs | Remove old descriptor type (replaced by IncrementalPlanDescriptor). |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferRewriterTypes.cs | Update split result to use IncrementalPlanDescriptor. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferPartitioningResult.cs | Rename partitioning outputs to DeliveryGroup. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferPartitioner.cs | Rename defer usage to delivery group; preserve identity mapping. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferOperationRewriter.cs | Update defer splitting to bucket by delivery-group set and emit incremental plan descriptors. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferOccurrenceCollector.cs | Update collector to use delivery-group mapping. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/DeferEffectiveSetResolver.cs | Update effective-set resolver to produce DeliveryGroupSetKey. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Planning/Backlog.cs | Push requirement work items with RequirementConsumer. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ThrowHelper.cs | Rename exception factory to incremental-plan parent resolution naming. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/FetchResultStore.cs | Add snapshot-based variable set creation and variable import; adjust deferred merge behavior. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/AdditionalPathAccumulator.cs | Add helper to add additional paths in bulk. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Pipeline/OperationExecutionMiddleware.cs | Update defer checks to use IncrementalPlans. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanExecutor.cs | Execute incremental plans with requirement snapshots and retained memory; support nested defers. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanContext.cs | Generalize to IOperationPlan; add requirement snapshot installation + retained-memory ownership handling. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanContext.Pooling.cs | Update initializer signature to accept IOperationPlan and clear new fields on pool return. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Serialization/YamlOperationPlanFormatter.cs | Emit incremental plan requirements and parent dependencies in YAML output. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Serialization/JsonOperationPlanParser.cs | Parse incremental plans, requirements, and mixed dependency encoding (local + parent). |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Serialization/JsonOperationPlanFormatter.cs | Serialize incremental plan requirements and parent dependencies; reuse requirement writer. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs | Rename defer-usage APIs to delivery-group APIs. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/OperationPlan.cs | Implement IOperationPlan; rename deferred sub-plans surface to IncrementalPlans. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/OperationDefinition.cs | Add parent dependency tracking to operation definitions. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/OperationCompiler.cs | Update compiler pipeline to use delivery group identity. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Operation.cs | Update operation to carry delivery-group mapping. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/IncrementalPlan.cs | New incremental-plan runtime type implementing IOperationPlan. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/IOperationPlan.cs | New interface for executor to treat root plans and subplans uniformly. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/FieldSelectionNode.cs | Rename defer usage field to delivery group. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/ExecutionSubPlan.cs | Remove old runtime subplan type (replaced by IncrementalPlan). |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/ExecutionNode.cs | Add parent dependency tracking to execution nodes. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/DeliveryGroup.cs | Rename DeferUsage to DeliveryGroup. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs | Generalize execution scheduling APIs to accept IOperationPlan. |
| .gitignore | Ignore .work/ directory. |
Files not reviewed (1)
- src/HotChocolate/Fusion/src/Fusion.Execution/Properties/FusionExecutionResources.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.