Skip to content

feat(incremental): report multiple cached task failures together - #4870

Open
yaacovCR wants to merge 1 commit into
graphql:17.x.xfrom
yaacovCR:more-than-one-completion-error
Open

yaacovCR wants to merge 1 commit into
graphql:17.x.xfrom
yaacovCR:more-than-one-completion-error

Conversation

@yaacovCR

Copy link
Copy Markdown
Contributor

@duckki @robrichard @benjie

This proposal extracts the multiple-error reporting idea from Duckki Oe's original implementation in #4859.

This is an optional follow-up to #4868 and #4869. Those changes already prevent lost or delayed successful results and completions for unannounced fragments, in line with #4859.

This PR extracts an additional element from #4859, i.e. how many errored tasks to report for a delivery group with multiple shared tasks that have errored prior to the start of a deferred group.

Currently, when several shared tasks have failed before a deferred group starts, the group completes with the first replayed error. This proposal includes every failure already cached by its retained, started tasks in that one completion. It exposes more information we already have, without waiting for other work.

For example:

{
  hero {
    ... @defer(label: "R1") {
      first: nonNullName
    }
    ... @defer(label: "R2") {
      second: nonNullName
    }
    ... @defer(label: "P") {
      name
      ... @defer(label: "C") {
        first: nonNullName
        second: nonNullName
      }
    }
  }
}

first and second both return null, failing R1 and R2 while P's name is still pending. R1 and R2 each report their own error. When name resolves to "Luke", both versions announce C and complete P successfully.

The final response on 17.x.x is:

{
  "hasNext": false,
  "pending": [
    {
      "id": "3",
      "path": [
        "hero"
      ],
      "label": "C"
    }
  ],
  "incremental": [
    {
      "id": "2",
      "data": {
        "name": "Luke"
      }
    }
  ],
  "completed": [
    {
      "id": "2"
    },
    {
      "id": "3",
      "errors": [
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 4,
              "column": 7
            },
            {
              "line": 12,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "first"
          ]
        }
      ]
    }
  ]
}

With this proposal, the final response is:

{
  "hasNext": false,
  "pending": [
    {
      "id": "3",
      "path": [
        "hero"
      ],
      "label": "C"
    }
  ],
  "incremental": [
    {
      "id": "2",
      "data": {
        "name": "Luke"
      }
    }
  ],
  "completed": [
    {
      "id": "2"
    },
    {
      "id": "3",
      "errors": [
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 4,
              "column": 7
            },
            {
              "line": 12,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "first"
          ]
        },
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 7,
              "column": 7
            },
            {
              "line": 13,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "second"
          ]
        }
      ]
    }
  ]
}

The implementation moves cached-failure inspection from startTask to startGroup. It adds an additional pass over a group's tasks before starting new work to check for cached failures. This also ensures that a group already known to have failed does not start unnecessary tasks.

Unlike the original implementation's retained group errors, this version reads the existing computation results. It adds no persistent group-error storage or WeakSet.

This proposal extracts the multiple-error reporting idea from Duckki Oe's
original implementation in [graphql#4859](graphql#4859).

This is an optional follow-up to [graphql#4868](graphql#4868)
and [graphql#4869](graphql#4869). Those changes already
prevent lost or delayed successful results and completions for unannounced
fragments, in line with graphql#4859.

This PR extracts an additional element from graphql#4859, i.e. how many errored tasks
to report for a delivery group with multiple shared tasks that have errored
prior to the start of a deferred group.

Currently, when several shared tasks have failed before a deferred group starts,
the group completes with the first replayed error. This proposal includes every
failure already cached by its retained, started tasks in that one completion.
It exposes more information we already have, without waiting for other work.

For example:

```graphql
{
  hero {
    ... @defer(label: "R1") {
      first: nonNullName
    }
    ... @defer(label: "R2") {
      second: nonNullName
    }
    ... @defer(label: "P") {
      name
      ... @defer(label: "C") {
        first: nonNullName
        second: nonNullName
      }
    }
  }
}
```

`first` and `second` both return `null`, failing R1 and R2 while P's `name`
is still pending. R1 and R2 each report their own error. When `name` resolves
to `"Luke"`, both versions announce C and complete P successfully.

The final response on `17.x.x` is:

```json
{
  "hasNext": false,
  "pending": [
    {
      "id": "3",
      "path": [
        "hero"
      ],
      "label": "C"
    }
  ],
  "incremental": [
    {
      "id": "2",
      "data": {
        "name": "Luke"
      }
    }
  ],
  "completed": [
    {
      "id": "2"
    },
    {
      "id": "3",
      "errors": [
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 4,
              "column": 7
            },
            {
              "line": 12,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "first"
          ]
        }
      ]
    }
  ]
}
```

With this proposal, the final response is:

```json
{
  "hasNext": false,
  "pending": [
    {
      "id": "3",
      "path": [
        "hero"
      ],
      "label": "C"
    }
  ],
  "incremental": [
    {
      "id": "2",
      "data": {
        "name": "Luke"
      }
    }
  ],
  "completed": [
    {
      "id": "2"
    },
    {
      "id": "3",
      "errors": [
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 4,
              "column": 7
            },
            {
              "line": 12,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "first"
          ]
        },
        {
          "message": "Cannot return null for non-nullable field Hero.nonNullName.",
          "locations": [
            {
              "line": 7,
              "column": 7
            },
            {
              "line": 13,
              "column": 9
            }
          ],
          "path": [
            "hero",
            "second"
          ]
        }
      ]
    }
  ]
}
```

The implementation moves cached-failure inspection from `startTask` to
`startGroup`. It adds an additional pass over a group's tasks before starting
new work to check for cached failures. This also ensures that a group already
known to have failed does not start unnecessary tasks.

Unlike the original implementation's retained group errors, this version reads
the existing computation results. It adds no persistent group-error storage or
WeakSet.

Co-authored-by: Duckki Oe <[email protected]>
@yaacovCR yaacovCR added the PR: bug fix 🐞 requires increase of "patch" version number label Oct 18, 2026
@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

@yaacovCR is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@duckki

duckki commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for separating this from the lifecycle fixes. I support this approach: when several retained, started shared tasks have already rejected, reporting their cached failures together gives the client more information without waiting for unfinished work or introducing persistent group-error storage.

I also understand this is preferable over #4861: these are multiple failures explaining why the group cannot deliver; some previously collected errors may be omitted (such as nullable-field errors from discarded data).

The corresponding spec question is whether GROUP_FAILURE should accept a non-empty error list, and whether reporting every already-available propagating cause should be required or left to implementations. The draft’s current singleton error seems worth clarifying alongside this change.

@duckki

duckki commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

I've implemented a formal model of this PR in Lean.
The model has been proved correct. I didn't find any issues.

This branch has not been deployed

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

Labels

PR: bug fix 🐞 requires increase of "patch" version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants