Skip to content

[dotnet] Server emits explicit nulls for optional event fields; strict clients reject them #2816

Open

Description

@yousuf64

Area

AGUI.Server 1.0.0 event serialization (consumed via Microsoft.Agents.AI.Hosting.AGUI.AspNetCore 1.22.0-preview.260918.1, .NET 10 TypedResults.ServerSentEvents path).

What happens

Streamed events carry explicit nulls for optional fields, e.g.:

{"type":"RUN_STARTED","threadId":"t1","runId":"","parentRunId":null,"input":null,"timestamp":null,"rawEvent":null,"metadata":null}

Strict clients (@ag-ui/[email protected], Zod-validated) reject the very first event:

ZodError: expected number, received null — path: ["timestamp"]

so the run fails client-side before any UI updates. curl-based testing never sees this (no validation), which makes it easy to ship a backend that looks healthy while all JS UIs fail instantly.

Workaround (host-side)

builder.Services.ConfigureHttpJsonOptions(o =>
    o.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull);

After this, events arrive clean and clients proceed. I note AGUIJsonUtilities.OmitPropertiesWithoutAValue already exists in the SDK — but hosts don't get null-omission by default, and MAF-added wrappers (rawEvent envelopes) reintroduce nulls anyway.

Suggestion

Omit null-valued optionals by default in the server event stream (the protocol marks these fields optional), rather than requiring every host to discover and configure this. At minimum, document it in the .NET hosting guidance.

Activity

  1. Kermittt commented on Sep 29, 2026

    @Kermittt

    The correct fix for this is to explicitly mark properties that are still required to be omitted by the protocol. The migration guide says "Event or message metadata: null and parentRunId: null remain invalid." therefore these two properties should be marked with [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] in the relevant classes within sdks/dotnet/src/AGUI.Abstractions/Generated/AGUIEvents.g.cs
    https://docs.ag-ui.com/concepts/agents#omit-whole-optional-null-fields

  2. Kermittt commented on Oct 1, 2026

    @Kermittt

    Related... microsoft/agent-framework#7919
    It's possible the fix should just be over in the Microsoft.Agents.AI.Hosting.AGUI.AspNetCore package.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions