From 180c4c0eae5a61e62ce877173a9acd4254af4e59 Mon Sep 17 00:00:00 2001 From: VectorPeak <73048950+VectorPeak@users.noreply.github.com> Date: Wed, 24 Jun 2026 15:22:57 +0800 Subject: [PATCH 1/2] .NET: Fix stop sequence array serialization --- .../ChatCompletions/Models/StopSequences.cs | 2 +- .../OpenAIChatCompletionsSerializationTests.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs index bed3b2a3206..3a97f2f19b0 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs @@ -183,7 +183,7 @@ public override void Write(Utf8JsonWriter writer, StopSequences? value, JsonSeri } else if (value.IsSequences) { - JsonSerializer.Serialize(writer, value.Sequences, ChatCompletionsJsonContext.Default.IReadOnlyListMessageContentPart); + JsonSerializer.Serialize(writer, value.Sequences, ChatCompletionsJsonContext.Default.IListString); } else { diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs index edf11fbf6bb..a9f0b32507c 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs @@ -54,6 +54,24 @@ public void Deserialize_BasicRequest_RoundTrip() Assert.Equal(request.Messages.Count, roundtripped.Messages.Count); } + [Fact] + public void Serialize_RequestWithMultipleStopSequences_WritesStringArray() + { + // Arrange + string originalJson = LoadChatCompletionsTraceFile("basic/request.json"); + CreateChatCompletion request = JsonSerializer.Deserialize(originalJson, ChatCompletions.ChatCompletionsJsonContext.Default.CreateChatCompletion)!; + request.Stop = StopSequences.FromSequences(["END", "STOP"]); + + // Act + string json = JsonSerializer.Serialize(request, ChatCompletions.ChatCompletionsJsonContext.Default.CreateChatCompletion); + using JsonDocument document = JsonDocument.Parse(json); + + // Assert + JsonElement stop = document.RootElement.GetProperty("stop"); + Assert.Equal(JsonValueKind.Array, stop.ValueKind); + Assert.Equal(["END", "STOP"], stop.EnumerateArray().Select(e => e.GetString())); + } + [Fact] public void Deserialize_BasicRequest_HasMessages() { From bc4cd11edb66b698b6291a13e5cbe3d299670cb8 Mon Sep 17 00:00:00 2001 From: VectorPeak <73048950+VectorPeak@users.noreply.github.com> Date: Wed, 24 Jun 2026 17:18:10 +0800 Subject: [PATCH 2/2] Potential fix for pull request finding Thanks Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../OpenAIChatCompletionsSerializationTests.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs index a9f0b32507c..86e9292d62b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs @@ -67,9 +67,10 @@ public void Serialize_RequestWithMultipleStopSequences_WritesStringArray() using JsonDocument document = JsonDocument.Parse(json); // Assert - JsonElement stop = document.RootElement.GetProperty("stop"); - Assert.Equal(JsonValueKind.Array, stop.ValueKind); - Assert.Equal(["END", "STOP"], stop.EnumerateArray().Select(e => e.GetString())); +JsonElement stop = document.RootElement.GetProperty("stop"); +Assert.Equal(JsonValueKind.Array, stop.ValueKind); +string[] stopValues = stop.EnumerateArray().Select(static e => e.GetString()!).ToArray(); +Assert.Equal(["END", "STOP"], stopValues); } [Fact]