Skip to content

[BUG] Azure.AI.Agents.Persistent NullReferenceException after successful streamed response finalization #57183

@brandonh-msft

Description

@brandonh-msft

Bug description

When using Azure.AI.Agents.Persistent through Microsoft Agent Framework streaming APIs, a chat run can complete successfully, return the full assistant answer, and then crash during stream finalization/disposal with a System.NullReferenceException.

The exception originates inside the Azure SDK telemetry/finalization path:
Azure.AI.Agents.Persistent.RunStepOpenAPIToolCall.JsonModelWriteCore(...)

Package and environment

  • Package: Azure.AI.Agents.Persistent
  • Package version: 1.0.0-preview.260311.1
  • App shape: .NET 10 console app using Microsoft Agent Framework with Azure Foundry persistent agents
  • OS: Windows
  • Auth: DefaultAzureCredential
  • Streaming path: AIAgent.RunStreamingAsync(...)

Expected behavior

After the streamed answer completes, enumeration/disposal should finish cleanly.

Actual behavior

The full assistant answer is returned to the caller, but the process crashes afterward during stream cleanup/final telemetry processing.

Reproduction notes

  1. Create a persistent Foundry agent and connect with PersistentAgentsClient / ChatClientAgent.
  2. Wrap the agent with Agent Framework OpenTelemetry instrumentation.
  3. Call RunStreamingAsync(...) and enumerate the response stream to completion.
  4. Observe that, after the final assistant output is emitted, the SDK throws NullReferenceException during finalization.

Minimal observed output

assistant(stream)> <full answer omitted>
[update] role=assistant, messageId=..., author=..., responseId=...
[update] role=assistant, messageId=..., author=..., responseId=...
[content:UsageContent] Microsoft.Extensions.AI.UsageContent
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Azure.AI.Agents.Persistent.RunStepOpenAPIToolCall.JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
   at Azure.AI.Agents.Persistent.RunStepOpenAPIToolCall.System.ClientModel.Primitives.IJsonModel<Azure.AI.Agents.Persistent.RunStepOpenAPIToolCall>.Write(...)
   at Azure.AI.Agents.Persistent.ModelSerializationExtensions.WriteObjectValue[T](...)
   at Azure.AI.Agents.Persistent.RunStepOpenAPIToolCall.ToRequestContent()
   at Azure.AI.Agents.Persistent.Telemetry.OpenTelemetryScope.GetToolCallAttributes(RunStepToolCall toolCall)
   at Azure.AI.Agents.Persistent.Telemetry.OpenTelemetryScope.ProcessToolCalls(RunStepToolCallDetails toolCallDetails)
   at Azure.AI.Agents.Persistent.Telemetry.OpenTelemetryScope.RecordRunStepEventAttributes(RunStep runStep, Boolean stream)
   at Azure.AI.Agents.Persistent.Telemetry.OpenTelemetryScope.End()
   at Azure.AI.Agents.Persistent.Telemetry.OpenTelemetryScope.Dispose()

Suspected root cause

The generated serializer for RunStepOpenAPIToolCall appears to iterate OpenAPI without a null check.

Relevant file: sdk/ai/Azure.AI.Agents.Persistent/src/Generated/RunStepOpenAPIToolCall.Serialization.cs

Impact

  • The user-visible answer is already complete, but the client process still terminates.
  • This makes streamed chat runs unreliable in production.
  • The issue appears tied to SDK finalization/telemetry, not application rendering.

Workaround currently used

Application-side workaround: catch this very specific NullReferenceException after the stream completes and preserve the completed answer.

Request

Please confirm whether this is a known bug in Azure.AI.Agents.Persistent preview and whether a null-safe fix should be added around RunStepOpenAPIToolCall serialization / telemetry attribute generation.

Metadata

Metadata

Assignees

Labels

AI AgentsClientThis issue is related to a non-management packageService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions