#2816·ag-ui

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

Author: yousuf64Created Sep 23, 2026Updated Oct 1, 2026

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.:

json
{"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)

csharp
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.