fix(openai/responses): drop response.metadata for non-Codex clients

The Codex backend now sends a response.metadata event with prompt-moderation flags.
It is not a public Responses event, and clients that parse a closed event list
(Grok Build 1.0.60 and 1.0.70: "unknown variant response.metadata") fail the
whole turn on it. Filter it for standard Responses clients like the other private
Codex events; official Codex clients still receive it.
This commit is contained in:
Frank Dai
2026-10-25 00:28:55 -07:00
parent bc0643405a
commit 86d951cd50
2 changed files with 16 additions and 2 deletions

View File

@@ -161,8 +161,10 @@ func (f *responsesSSEFramer) shouldFilterPrivateEvent(streamEvent, payloadType s
return false
}
// For standard Responses API clients: filter any codex.* private events.
if strings.HasPrefix(name, "codex.") {
// For standard Responses API clients: filter any codex.* private events, and the Codex
// backend's moderation metadata, which is not a public Responses event: clients that parse
// a closed event list fail on it.
if strings.HasPrefix(name, "codex.") || name == "response.metadata" {
return true
}

View File

@@ -625,6 +625,9 @@ func TestResponsesSSEFramer_FiltersUpstreamPrivateEvents(t *testing.T) {
subscriptionUsageFrame := []byte("event: response.subscription_usage\ndata: {\"subscription\":{\"tier\":\"1234567890123456\",\"weekly\":{\"resets_at\":1792368000,\"used_percent\":80},\"window\":{\"resets_at\":1792272519,\"used_percent\":10,\"window_duration_mins\":300}},\"type\":\"response.subscription_usage\"}\n\n")
framer.WriteChunk(&output, subscriptionUsageFrame)
moderationFrame := []byte("event: response.metadata\ndata: {\"type\":\"response.metadata\",\"metadata\":{\"openai_chatgpt_moderation_metadata\":{\"prompt\":{}}}}\n\n")
framer.WriteChunk(&output, moderationFrame)
completedFrame := []byte("event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-1\",\"status\":\"completed\"}}\n\n")
framer.WriteChunk(&output, completedFrame)
@@ -632,6 +635,9 @@ func TestResponsesSSEFramer_FiltersUpstreamPrivateEvents(t *testing.T) {
if strings.Contains(got, "codex.rate_limits") {
t.Fatalf("expected codex.rate_limits to be stripped, got: %q", got)
}
if strings.Contains(got, "event: response.metadata") || strings.Contains(got, "openai_chatgpt_moderation_metadata") {
t.Fatalf("expected response.metadata to be stripped, got: %q", got)
}
if strings.Contains(got, "codex.response.metadata") {
t.Fatalf("expected codex.response.metadata to be stripped, got: %q", got)
}
@@ -692,6 +698,9 @@ func TestResponsesSSEFramer_PreservesMetadataForCodexClient(t *testing.T) {
createdFrame := []byte("event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"resp-1\"}}\n\n")
framer.WriteChunk(&output, createdFrame)
moderationFrame := []byte("event: response.metadata\ndata: {\"type\":\"response.metadata\",\"metadata\":{\"openai_chatgpt_moderation_metadata\":{\"prompt\":{}}}}\n\n")
framer.WriteChunk(&output, moderationFrame)
completedFrame := []byte("event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-1\",\"status\":\"completed\"}}\n\n")
framer.WriteChunk(&output, completedFrame)
@@ -699,6 +708,9 @@ func TestResponsesSSEFramer_PreservesMetadataForCodexClient(t *testing.T) {
if !strings.Contains(got, "codex.response.metadata") {
t.Fatalf("expected codex.response.metadata to be preserved for official Codex client, got: %q", got)
}
if !strings.Contains(got, "event: response.metadata") {
t.Fatalf("expected response.metadata to be preserved for official Codex client, got: %q", got)
}
if !strings.Contains(got, "event: response.created") {
t.Fatalf("expected response.created in output, got: %q", got)
}