From 414cc33d4817bc13c30ba68a4a34af65cca113e6 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 27 Jan 2026 10:34:41 +0100 Subject: [PATCH 1/2] Fix random chat stream errors --- .../Adapters/AskAi/LlmGatewayStreamTransformer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/LlmGatewayStreamTransformer.cs b/src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/LlmGatewayStreamTransformer.cs index d12ae3541..4f47ee656 100644 --- a/src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/LlmGatewayStreamTransformer.cs +++ b/src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/LlmGatewayStreamTransformer.cs @@ -74,9 +74,10 @@ protected override async Task ProcessStreamAsync(PipeReader reader, PipeWriter w "tool_call" when messageData.TryGetProperty("toolCalls", out var toolCalls) => TransformToolCall(id, timestamp, toolCalls), - "tool_message" when messageData.TryGetProperty("toolCallId", out var toolCallId) - && messageData.TryGetProperty("result", out var result) => - new AskAiEvent.ToolResult(id, timestamp, toolCallId.GetString()!, result.GetString()!), + // Frontend only uses tool_result to show "Analyzing..." status - result content not displayed + // Skip sending the large payload (~30KB) to prevent CloudFront OAC buffering issues + "tool_message" when messageData.TryGetProperty("toolCallId", out var toolCallId) => + new AskAiEvent.ToolResult(id, timestamp, toolCallId.GetString()!, ""), "agent_end" => new AskAiEvent.ConversationEnd(id, timestamp), From 6024437f35a7d61c64d0e64769a16db08ae4ecb6 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 27 Jan 2026 10:55:40 +0100 Subject: [PATCH 2/2] Fix test --- .../Adapters/AskAi/StreamTransformerTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Elastic.Documentation.Api.Infrastructure.Tests/Adapters/AskAi/StreamTransformerTests.cs b/tests/Elastic.Documentation.Api.Infrastructure.Tests/Adapters/AskAi/StreamTransformerTests.cs index 384ffaaa2..9eeadeeae 100644 --- a/tests/Elastic.Documentation.Api.Infrastructure.Tests/Adapters/AskAi/StreamTransformerTests.cs +++ b/tests/Elastic.Documentation.Api.Infrastructure.Tests/Adapters/AskAi/StreamTransformerTests.cs @@ -247,7 +247,8 @@ public async Task TransformAsyncWithRealLlmGatewayPayloadParsesAllEventTypes() events[4].Should().BeOfType(); var toolResult = events[4] as AskAiEvent.ToolResult; toolResult!.ToolCallId.Should().Be("tool1"); - toolResult.Result.Should().Contain("Found 10 docs"); + // Result is intentionally empty - payload stripped to prevent CloudFront OAC buffering issues + toolResult.Result.Should().BeEmpty(); // Event 6: ai_message events[5].Should().BeOfType();