Skip to content

[Fusion] Fix satisfiability results depending on field declaration order - #10705

Merged
michaelstaib merged 11 commits into
mainfrom
mst/fusion-sat-requirement-order
Nov 3, 2026
Merged

michaelstaib merged 11 commits into
mainfrom
mst/fusion-sat-requirement-order

Conversation

@michaelstaib

@michaelstaib michaelstaib commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

The satisfiability validator visits each state of its search only once. But its @require checks 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.viewer on 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

# schema a
type Query {
  good: X @shareable
  bad: X
}

type X {
  p: P @shareable
}

type P {
  t: T @shareable
}

type T {
  f(q: String @require(field: "q")): String
}

# schema c
type Query {
  pByK(k: String!): P @lookup @internal
}

type P {
  k: String @shareable
  t: T @shareable
}

type T {
  q: String
}

# schema d
type Query {
  good: X @shareable
}

type X {
  p: P @shareable
}

type P {
  k: String @shareable
}

T.f needs q from c, and c can only be entered with P.k, which only d serves. d reaches P through good but not through bad, so { bad { p { t { f } } } } cannot be planned. Before, composition succeeded when good was declared before bad and failed the other way round. Now it fails in both orders.

@michaelstaib
michaelstaib added this pull request to stack #10769 November 1, 2026 09:29
@michaelstaib
michaelstaib force-pushed the mst/fusion-sat-requirement-order branch from 3664222 to 1e8f788 Compare November 1, 2026 09:29
Copilot AI balanced review requested due to automatic review settings November 1, 2026 09:29
@michaelstaib
michaelstaib force-pushed the mst/fusion-sat-requirement-order branch from 1e8f788 to ee1cf43 Compare November 1, 2026 09:31

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.

🟡 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);
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

94.6% of changed lines covered (1707/1804)

File Covered Changed Patch %
…/Fusion/src/Fusion.Composition/Satisfiability/PathAnchor.cs 9 11 81.8% 🟡
…/src/Fusion.Composition/SatisfiabilityValidator.VisitKeys.cs 419 472 88.8% 🟡
…/Fusion.Composition/Satisfiability/RequirementsValidator.cs 253 278 91.0% 🟡
…/src/Fusion.Composition/Satisfiability/ExclusionReaches.cs 26 28 92.9% 🟡
…/src/Fusion.Composition/SatisfiabilityValidator.Viewer.cs 84 86 97.7% 🟡
…/Fusion/src/Fusion.Composition/SatisfiabilityValidator.cs 232 237 97.9% 🟡
…/src/Fusion.Composition/SatisfiabilityValidator.Exclusions.cs 602 610 98.7% 🟡
…/src/Fusion.Composition/Satisfiability/FieldAccessCacheKey.cs 6 6 100.0% 🟢
…/src/Fusion.Composition/Satisfiability/RequirementScope.cs 8 8 100.0% 🟢
…/Satisfiability/SatisfiabilityExplanationBudget.cs 14 14 100.0% 🟢
…/src/Fusion.Composition/Satisfiability/SchemaSetInterner.cs 20 20 100.0% 🟢
…/Satisfiability/SourceSchemaTransitionHelper.cs 31 31 100.0% 🟢
…/Fusion/src/Fusion.Composition/Satisfiability/VisitKey.cs 3 3 100.0% 🟢
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)

Base automatically changed from mst/fusion-sat-field-options to main November 2, 2026 09:11
@michaelstaib
michaelstaib force-pushed the mst/fusion-sat-requirement-order branch 4 times, most recently from 2ef730d to 2aadc45 Compare November 3, 2026 12:40
…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
michaelstaib force-pushed the mst/fusion-sat-requirement-order branch from 2aadc45 to 1257efe Compare November 3, 2026 13:16
@michaelstaib
michaelstaib merged commit 301931a into main Nov 3, 2026
9 of 10 checks passed
@michaelstaib
michaelstaib deleted the mst/fusion-sat-requirement-order branch November 3, 2026 13:16
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