Skip to content

Report the reason for rejected batch requests to server diagnostics - #10372

Merged
glen-84 merged 3 commits into
mainfrom
gai/report-batching-rejections-to-diagnostics
Sep 8, 2026
Merged

glen-84 merged 3 commits into
mainfrom
gai/report-batching-rejections-to-diagnostics

Conversation

@glen-84

@glen-84 glen-84 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • A request rejected because variable or request batching is disabled now raises IServerDiagnosticEvents.HttpRequestError with an error that names the disabled mode and points at GraphQLServerOptions.Batching. The client response is unchanged and still says Invalid GraphQL Request. with code HC0009.
  • The variable batch paths in ExecutorSession.ExecuteSingleAsync previously returned without raising any diagnostic event, both for disabled batching and for an exceeded MaxBatchSize. Both now raise HttpRequestError, so listeners such as the OpenTelemetry instrumentation record the reason on the request span.
  • The operation batch branch in HttpPostMiddlewareBase checks the batching flag before the batchOperations value, so the reported reason is the check that rejected the request. A missing or unparseable batchOperations value keeps reporting the generic error.

Test plan

  • New tests in HttpPostMiddlewareTests use a recording ServerDiagnosticEventListener to assert the reported message and the unchanged response body for a variable batch, a request batch, and an operation batch with batching disabled, a variable batch over MaxBatchSize, and an operation batch with an invalid batchOperations value.
  • HttpPostMiddlewareTests and GraphQLOverHttpSpecTests pass.

Copilot AI lite review requested due to automatic review settings September 8, 2026 12:36

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

The new diagnostic errors for “batching disabled” are emitted without passing through session.Handle(...), making diagnostics inconsistent with other request errors and bypassing custom IErrorHandler behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves server diagnostics for rejected batch requests by emitting IServerDiagnosticEvents.HttpRequestError with a more specific error explaining why batching was rejected, while keeping the client-facing response unchanged for the “batching disabled” cases.

Changes:

  • Add dedicated error messages for “variable batching disabled” and “request batching disabled” via ErrorHelper + resource strings.
  • Emit HttpRequestError when variable batching is disabled and when variable batch size exceeds MaxBatchSize.
  • Reorder/adjust operation-batch handling in HttpPostMiddlewareBase to report the correct rejection reason, and add tests validating diagnostic output and response body.
File summaries
File Description
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/HttpPostMiddlewareTests.cs Adds coverage asserting diagnostic messages and unchanged response bodies for batching rejection scenarios.
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Utilities/ErrorHelper.cs Introduces new IError factories for batching-disabled diagnostic reasons.
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.resx Adds localized resource strings for the new batching-disabled messages.
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.Designer.cs Updates generated resource accessors for new resource keys.
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs Emits diagnostic reasons for request/operation batching disabled and adjusts condition ordering.
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/ExecutorSession.cs Emits diagnostics for variable batching disabled and max variable batch size exceeded.
Review details

Files not reviewed (1)

  • src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Properties/AspNetCorePipelineResources.Designer.cs: Generated file

Suppressed comments (1)

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs:202

  • The diagnostic error for disabled request batching is emitted without applying session.Handle(...). For consistency with other request errors (and to allow custom IErrorHandler implementations to affect diagnostics), pass the error through session.Handle before calling HttpRequestError.
                        session.DiagnosticEvents.HttpRequestError(
                            context,
                            ErrorHelper.RequestBatchingDisabled());
  • Files reviewed: 5/6 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (27/27)

File Covered Changed Patch %
…/AspNetCore/src/AspNetCore.Pipeline/ExecutorSession.cs 4 4 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs 15 15 100.0% 🟢
…/AspNetCore/src/AspNetCore.Pipeline/Utilities/ErrorHelper.cs 8 8 100.0% 🟢

Project coverage: 57.9% (288200/497786 lines)

@glen-84
glen-84 merged commit 6289795 into main Sep 8, 2026
151 checks passed
@glen-84
glen-84 deleted the gai/report-batching-rejections-to-diagnostics branch September 8, 2026 13:10
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