Repository navigation
[Fusion] Fix satisfiability results depending on field declaration order - #10705
Merged
Merged
Conversation
michaelstaib
force-pushed
the
mst/fusion-sat-requirement-order
branch
from
November 1, 2026 09:29
3664222 to
1e8f788
Compare
michaelstaib
force-pushed
the
mst/fusion-sat-requirement-order
branch
from
November 1, 2026 09:31
1e8f788 to
ee1cf43
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical validator defects can omit exclusions depending on declaration order and exponentially expand cyclic requirements, potentially stalling composition or exhausting memory.
2 open issues
1 file not reviewed
src/HotChocolate/Fusion/src/Fusion.Composition/Properties/CompositionResources.Designer.cs: Generated file
What changed in this PR
This PR makes Fusion’s satisfiability checks independent of field declaration order by moving requirement-relevant path information into the cached search state. It also aligns validation more closely with gateway planning behavior.
Changes:
- Adds state for schema availability, earlier calls, viewer re-rooting, and event-stream lookup keys.
- Anchors requirement checks at the current object and bounds failure-explanation searches.
- Updates composition tests and adds planning snapshots for requirement-fetching scenarios.
Paths below are relative to src/HotChocolate/Fusion/.
| File | Description |
|---|---|
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirementWithoutHolderData_When_KeyOfOtherSchemaIsHeld.yaml |
Captures fetching requirements using another schema’s held key. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirementThroughLookupOfParentSchema_When_FieldReturningObjectHasRequirement.yaml |
Captures parent lookup planning with field requirements. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirementFromOtherSchema_When_ParentSchemaLacksFieldReturningObject.yaml |
Captures fetching through an alternate parent schema. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirementFromOtherSchema_When_ItEntersParentThroughLookup.yaml |
Captures requirement fetching after a parent lookup. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirement_When_ViewerIsReRootedOrParentHasLookup_subscription_doSomething.yaml |
Captures subscription viewer re-rooting. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirement_When_ViewerIsReRootedOrParentHasLookup_subscription_doOther.yaml |
Captures subscription parent lookup planning. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirement_When_ViewerIsReRootedOrParentHasLookup_mutation_doSomething.yaml |
Captures mutation viewer re-rooting. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirement_When_ViewerIsReRootedOrParentHasLookup_mutation_doOther.yaml |
Captures mutation parent lookup planning. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchRequirement_When_RequirementDataDependsOnEarlierCallOfRequiringSchema.yaml |
Captures dependencies on an earlier schema call. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchNestedRequirement_When_RequirementDataDependsOnEarlierCallOfRequiringSchema.yaml |
Captures nested requirements using earlier-call data. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchNestedLookupKeyByReTraversingPath_When_PathExistsInKeySchema.yaml |
Captures nested key fetching by re-traversal. |
test/Fusion.Execution.Tests/Planning/__snapshots__/RequirementArrivalPathPlanningTests.Plan_Should_FetchLookupKeyByReTraversingPath_When_PathExistsInKeySchema.yaml |
Captures key fetching through an alternate root path. |
test/Fusion.Composition.Tests/Satisfiability/SatisfiabilityErrorExplanationTests.cs |
Tests explanation pruning and retained entries. |
test/Fusion.Composition.Tests/Satisfiability/SatisfiabilityCycleTests.cs |
Tests repeated fields in requirement paths. |
test/Fusion.Composition.Tests/Satisfiability/RequirementsValidatorTests.cs |
Supplies explicit requirement scopes to existing tests. |
src/Fusion.Composition/SatisfiabilityValidator.VisitKeys.cs |
Computes schema reachability and holder reentry state. |
src/Fusion.Composition/SatisfiabilityValidator.Viewer.cs |
Tracks viewer fallback and parent-field relationships. |
src/Fusion.Composition/SatisfiabilityValidator.Exclusions.cs |
Computes availability without specified schemas’ data. |
src/Fusion.Composition/SatisfiabilityValidator.cs |
Uses anchored checks and bounded explanations. |
src/Fusion.Composition/Satisfiability/VisitKey.cs |
Adds exclusions and holder reentry to visit identity. |
src/Fusion.Composition/Satisfiability/SourceSchemaTransitionHelper.cs |
Supports anchored transitions and viewer fallback. |
src/Fusion.Composition/Satisfiability/SchemaSetTable.cs |
Adds reusable buffers and schema counting. |
src/Fusion.Composition/Satisfiability/SatisfiabilityExplanationBudget.cs |
Separates explanation-entry and failure limits. |
src/Fusion.Composition/Satisfiability/RequirementsValidator.cs |
Tracks requirement scope and eligible earlier calls. |
src/Fusion.Composition/Satisfiability/RequirementScope.cs |
Defines requirement-walk boundaries and viewer permissions. |
src/Fusion.Composition/Satisfiability/PathAnchor.cs |
Defines availability checks at a fixed path position. |
src/Fusion.Composition/Satisfiability/FieldAccessCacheKey.cs |
Distinguishes access-path items in cached checks. |
src/Fusion.Composition/Satisfiability/ExclusionReaches.cs |
Stores comparable availability and arrival-call state. |
src/Fusion.Composition/Satisfiability/ArrivalRead.cs |
Identifies which earlier call supplies requirement data. |
src/Fusion.Composition/Satisfiability/ArrivalCallState.cs |
Classifies earlier calls as readable, pending, or unavailable. |
src/Fusion.Composition/Properties/CompositionResources.resx |
Adds the omitted lookup-key diagnostic. |
src/Fusion.Composition/Properties/CompositionResources.Designer.cs |
Exposes the new diagnostic resource. |
src/Fusion.Composition/Collections/SatisfiabilityPath.cs |
Names the gateway-resolved path schema marker. |
Review effort: Balanced
Comment on lines
+389
to
+392
| if (providedTypes.Add(possibleType)) | ||
| { | ||
| CollectProvidedTypes(possibleType, selectionSet, providedTypes); | ||
| } |
Comment on lines
+483
to
+486
| var extended = AddToSchemaSet(unavailable, schemaName); | ||
| scan.Sets.Add(extended); | ||
| CollectExclusions(requirements, type, unavailable, atAnchor, scan); | ||
| CollectExclusions(requirements, type, extended, atAnchor, scan); |
Contributor
Patch coverage94.6% of changed lines covered (1707/1804)
Uncovered changed lines (JSON){
"sha": "404dcc7d8c38a3c5c04acb9cd406206110e38dbb",
"files": [
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/Satisfiability/PathAnchor.cs", "ranges": [[67, 67], [76, 76]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/SatisfiabilityValidator.VisitKeys.cs", "ranges": [[497, 500], [652, 653], [670, 680], [682, 683], [688, 698], [701, 701], [1192, 1193], [1195, 1197], [1200, 1206], [1208, 1209], [1211, 1212], [1288, 1289], [1291, 1294]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/Satisfiability/RequirementsValidator.cs", "ranges": [[603, 604], [701, 701], [730, 731], [746, 749], [754, 755], [951, 961], [963, 963], [1026, 1027]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/Satisfiability/ExclusionReaches.cs", "ranges": [[46, 46], [55, 55]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/SatisfiabilityValidator.Viewer.cs", "ranges": [[213, 214]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/SatisfiabilityValidator.cs", "ranges": [[905, 909]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/SatisfiabilityValidator.Exclusions.cs", "ranges": [[336, 337], [383, 384], [516, 517], [891, 891], [893, 893]] }
]
}Project coverage: 59.4% (321358/540645 lines) |
michaelstaib
force-pushed
the
mst/fusion-sat-requirement-order
branch
4 times, most recently
from
November 3, 2026 12:40
2ef730d to
2aadc45
Compare
…uirement repeats an item
…laration order The satisfiability validator visits each visit key once, but the @require checks walked the whole arrival path, so arrivals with equal keys could get different outcomes and the result depended on which arrival came first. The requirement checks, the lookup re-entry of an event stream holder and the lookup entries of the reach now walk only below the visited object and ask the visit key above it: - The reach is exact: a lookup entry counts only when its key resolves at the object, and a walk no longer treats a cut path as if it reached the root. - For each set of schemas that a requirement check can make unavailable, the key carries the schemas that hold the object without their data, the selection sets they provide, and whether the call holding the object was made without that data. - Requirement walks read the holding schema directly only when the holding call was made without the unavailable data, so some compositions that were accepted before are now rejected. The errors of SatisfiabilityCycleTests.Compose_Should_Fail_When_RequirementRepeatsFieldOfItsPath changed, and Compose_Should_Fail_When_HoldingCallOfRequirementNeedsDataOfRequiringSchema pins the rule. - The key records the schemas that hold the object only through a viewer field re-rooted at Query.viewer. Such a call takes no requirement data from another re-rooted call. - A field that an event stream message omits can be resolved by entering the holding schema again at the object or above it, with a lookup key the message holds. - Requirement walks re-root viewer fields at Query.viewer on mutation and subscription paths. - A viewer field is re-rooted at Query.viewer only in the schemas that do not define it, as in the planner. A schema that has the viewer field as a partial (@external) field no longer re-roots it, neither in the reach nor in a walk. The walk of the whole path now only explains reported failures, within the explanation budgets, and Debug builds compare it with the key based decisions.
…ata of unavailable schemas A requirement check without the data of some schemas validates the lookup keys of the type, and of the types below it, without the same data. When such a key selected a requiring field, the check asked the visit key for a reach without the data of one more schema, but the exclusions of the type were only collected from lookup keys validated with every schema available. Debug builds asserted and Release builds dropped the route. The exclusions of a type are now closed over the lookup keys of the type for each of its sets of unavailable schemas, and a requirement selection also collects the sets that the lookup keys of the types below the object create.
…Query.viewer A field resolved by the call that already holds its object, because its schema has no lookup for the object, takes its requirement data from calls made before that call. On mutation and subscription paths the calls re-rooted at Query.viewer run after the mutation or subscription call and next to each other, so the planner cannot feed such a call with their data. The visit key only counted the re-rooting call itself, so a requirement took its data from a lookup keyed by another re-rooted call, and the mutation call took requirement data from a re-rooted call. The route without a lookup now never takes data that depends on a re-rooted call. For each set of unavailable schemas, the key carries the schemas that hold the object only through calls that depend on a re-rooted call: a schema holds the object independently when it re-traverses the field from an independent call, or enters the object through a lookup whose key resolves from independent calls.
…gh lookups whose keys it holds The planner resolves a field that an event stream message omits through a lookup of the object in a schema that serves the field, picks among those schemas by name, and reads every key field that the holding schema serves from the event, also when the message omits it. The validator accepted such a field whenever the holding schema could be entered again at an ancestor with a key the message holds, so the gateway received plans that read lookup keys missing from the message. A field the message omits is now unresolvable when a lookup of the object in any schema that serves the field reads a key field that the holding schema serves and the message omits. Entering the holding schema again at the object, or for the objects below it, also fails when one of its own lookups reads an omitted key field.
… budget A requirement explanation walks the whole arrival path with a budget that caps its entries but let the search finish. The walk now asks whether the call holding each object on the path was made without the unavailable data, which validates lookup keys that ask the same again, and fuzz seed 5936 kept composing for more than 20 minutes. The visit key decides the requirement, so the explanation search now also stops after 100,000 failures, 100 times its entry budget. Past the entry budget, the explanation still keeps the entries that hold created entries.
Creating a visit key allocated on every arrival, also when an equal key was enqueued before: a schema buffer and an anchor for the reach, and for each set of unavailable schemas another buffer, another anchor and a copy of the reaches created before, so the copies grew quadratically with the number of sets. The buffers and anchors are now rented from pools and returned once the key is created. The reaches without the data of some schemas grow one entry at a time through a table that returns the existing instance for equal entries, so the entries of a key's reaches are only allocated when they are new.
…n an earlier call of the requiring schema
A requiring field whose schema has no lookup for the object is resolved by a call of that schema that
holds the object, and its requirement data must not depend on that call. The requirement walk treated
every call that depends on data of the requiring schema as unavailable, so it rejected requirement data
that a call fetched with keys from an earlier call of that schema, which the planner plans: A root
{ a { id } }, then B h1ById { b { l { x } id } }, then A h2ById { l { f(x) } }.
A requirement walk without the data of a single schema now reads a first-level field from the call that
holds the object, also when that call depends on the unavailable data. When the schema holding the parent
serves the field returning the object without requirements, it also reads the call that holds the parent,
because the planner keeps the field in that call. Otherwise the planner resolves the field in a schema that
resolves it as an option at the parent, and the walk reads the call of such a schema: the parent's schema
only when its requirements resolve there, another schema with requirements only when it enters the parent
through its own lookup, and none when the call that holds the parent provides the field through @provides.
Fields read from the holding call and from these calls all come from the calls of one schema. A call that
enters the object right after a call of the unavailable schema that serves the field, and the same call
further down, stays unavailable, because the planner keeps the field in the call of that schema, which then
resolves the requiring field. Lookups keyed by such data still do not count, and no call is read below a
viewer field re-rooted at Query.viewer. The visit key carries this state for each set of unavailable schemas.
michaelstaib
force-pushed
the
mst/fusion-sat-requirement-order
branch
from
November 3, 2026 13:16
2aadc45 to
1257efe
Compare
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.

The satisfiability validator visits each state of its search only once. But its
@requirechecks looked at the whole path that led to the state, so two paths that reach the same state could get different answers, and only the first one counted. Which path came first depended on the order of the field declarations, so swapping two fields could make composition succeed or fail. Some schemas were accepted although the gateway cannot plan them.The requirement checks now look only below the current object. What they need from above, such as which schemas hold the object and whether those calls were made without the data under check, is now part of the state itself. The result is the same in every declaration order and follows what the planner can plan. The change also fixes how these checks handle event stream messages that leave out lookup keys, viewer fields re-rooted at
Query.vieweron mutation and subscription paths, and requirement data fetched with keys from an earlier call of the requiring schema. A small number of compositions that main accepts and the planner can plan are now rejected; accepting them needs a different search state and is follow-up work.Example
T.fneedsqfromc, andccan only be entered withP.k, which onlydserves.dreachesPthroughgoodbut not throughbad, so{ bad { p { t { f } } } }cannot be planned. Before, composition succeeded whengoodwas declared beforebadand failed the other way round. Now it fails in both orders.