Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/gateway/src/chat/tools/transform-streaming-to-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,23 @@ export function transformStreamingToOpenai(
],
usage: normalizeAnthropicUsage(data.usage),
};
} else if (data.type === "ping") {
transformedData = {
id: data.id ?? `chatcmpl-${Date.now()}`,
object: "chat.completion.chunk",
created: data.created ?? Math.floor(Date.now() / 1000),
model: data.model ?? usedModel,
choices: [
{
index: 0,
delta: {
role: "assistant",
},
finish_reason: null,
},
],
usage: normalizeAnthropicUsage(data.usage),
};

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anthropic ping is a keepalive with no user-visible delta; transforming it into an OpenAI chat.completion.chunk adds extra downstream SSE traffic and can interfere with buffering logic that forwards chunks when delta.role is present (see apps/gateway/src/chat/chat.ts:6443-6453). Consider returning null here (like the OpenAI keepalive case) or emitting an actually-empty delta (no role) so ping events are ignored instead of forwarded.

Suggested change
transformedData = {
id: data.id ?? `chatcmpl-${Date.now()}`,
object: "chat.completion.chunk",
created: data.created ?? Math.floor(Date.now() / 1000),
model: data.model ?? usedModel,
choices: [
{
index: 0,
delta: {
role: "assistant",
},
finish_reason: null,
},
],
usage: normalizeAnthropicUsage(data.usage),
};
transformedData = null;

Copilot uses AI. Check for mistakes.

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new anthropic ping-handling branch isn’t covered by existing unit tests for transformStreamingToOpenai (there are streaming transform tests in transform-streaming-to-openai.spec.ts). Add a test that passes { type: "ping" } for provider anthropic and asserts no warning is logged and that the event is handled as intended (e.g., returns null if treated as a keepalive, or returns the expected no-op chunk).

Copilot uses AI. Check for mistakes.
} else {
logger.warn("[streaming] Unrecognized Anthropic chunk", {
provider: usedProvider,
Expand Down
Loading