Skip to content

fix: normalize missing Responses output item collections - #7088

Open
DoubleMice wants to merge 1 commit into
QuantumNous:mainfrom
DoubleMice:fix/responses-output-item-added
Open

fix: normalize missing Responses output item collections#7088
DoubleMice wants to merge 1 commit into
QuantumNous:mainfrom
DoubleMice:fix/responses-output-item-added

Conversation

@DoubleMice

@DoubleMice DoubleMice commented Aug 30, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

部分 Responses 上游在 response.output_item.added 阶段会省略尚为空的集合字段:reasoning item 缺少 summary,message item 缺少 content。严格按 OpenAI Responses item schema 反序列化的客户端会丢弃该 added item,后续 reasoning/text delta 因此无法关联 active item。

本 PR 在原生 Responses SSE 转发前做最小规范化:仅针对缺失字段补充 summary: []content: []。已有字段、其他 item 类型及事件中的 sequence_number 等数据保持不变。

本 PR 的代码和测试由 AI 辅助生成;提交者已审阅实现、确认协议行为,并完成本地与生产环境验证。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

修复前捕获到的上游事件:

{"type":"response.output_item.added","output_index":0,"item":{"id":"rs_1","type":"reasoning","status":"in_progress"},"sequence_number":2}
{"type":"response.output_item.added","output_index":1,"item":{"id":"msg_1","type":"message","role":"assistant","status":"in_progress"},"sequence_number":3}

修复后使用 OpenAI Codex 验证,ReasoningSummaryPartAdded/ReasoningSummaryDelta/OutputTextDelta without active item 均消失,普通 streaming、reasoning 与 shell tool call 正常。

测试结果:

go test ./relay/channel/openai ./relay/channel/advancedcustom
ok github.com/QuantumNous/new-api/relay/channel/openai
ok github.com/QuantumNous/new-api/relay/channel/advancedcustom

go test ./relay/channel/...
全部通过

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility with streamed OpenAI Responses events by supplying missing empty collections for reasoning summaries and message content.
    • Preserved existing summaries, function-call payloads, and event sequence numbers.
    • Streams now stop safely if response normalization fails.
  • Tests

    • Added coverage for mixed streamed response items and token usage reporting.

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 812d4362-b2e5-461f-a02b-aa4063db4273

📥 Commits

Reviewing files that changed from the base of the PR and between 918427d and ff3418a.

📒 Files selected for processing (2)
  • relay/channel/openai/relay_responses.go
  • relay/channel/openai/relay_responses_compat_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The Responses SSE relay now adds missing empty summary or content arrays to reasoning and message output items. The handler forwards normalized events and aborts on normalization errors. A compatibility test verifies defaults, preservation, exclusions, and sequence numbers.

Changes

Responses SSE normalization

Layer / File(s) Summary
Normalize missing output collections
relay/channel/openai/relay_responses.go
Adds normalization for missing reasoning item.summary and message item.content arrays while preserving existing fields and other item types.
Apply normalization and validate relay output
relay/channel/openai/relay_responses.go, relay/channel/openai/relay_responses_compat_test.go
The stream handler forwards normalized payloads and aborts on normalization errors. The compatibility test verifies defaults, preservation, exclusions, and sequence numbers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to ff341

The relay now adds required empty collections to affected reasoning and message streaming items while preserving existing data and event ordering, preventing compatible clients from dropping those items. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: calcium-ion

Poem

A rabbit checks the stream with care
Empty arrays bloom in waiting air
Reasoning and messages align
Old fields stay safely in line
Sequence numbers hop along
The relay carries items strong

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: normalizing missing collections in Responses output items.
Linked Issues check ✅ Passed The changes satisfy issue #7087 by adding missing summary and content arrays only for applicable Responses output items, while preserving existing fields, unrelated item types, event data, and sequenc…
Out of Scope Changes check ✅ Passed The pull request contains only the Responses SSE normalization logic and focused regression tests. No unrelated code changes are identified.
Full details: Linked Issues check

Explanation

The changes satisfy issue #7087 by adding missing summary and content arrays only for applicable Responses output items, while preserving existing fields, unrelated item types, event data, and sequence numbers. The added test covers these requirements.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Responses SSE added item 缺少空数组时 Codex 丢失 active item

1 participant