fix(openai): reject malformed Responses reasoning item IDs - #6678
fix(openai): reject malformed Responses reasoning item IDs#6678ZHOUKAILIAN wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe OpenAI Responses relay now validates reasoning output IDs in batch and streamed responses. IDs must use the ChangesResponses validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Upstream
participant ResponsesRelay
participant Client
Upstream->>ResponsesRelay: Send Responses payload or stream event
ResponsesRelay->>ResponsesRelay: Validate reasoning item ID
ResponsesRelay-->>Client: Forward valid data
ResponsesRelay-->>Client: Return bad-response error for invalid data
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/channel/openai/relay_responses_validation_test.go`:
- Around line 93-138: Extend
TestOaiResponsesStreamHandlerStopsBeforeInvalidReasoningItem with a terminal
response.completed or response.done SSE event whose response.output contains the
invalid reasoning item item_bad. Assert OaiResponsesStreamHandler returns the
existing HTTP 502 and that the terminal event, including item_bad, is not
written to w.Body.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f719f8c5-3704-4f6e-bd30-eaa58bc67cfd
📒 Files selected for processing (2)
relay/channel/openai/relay_responses.gorelay/channel/openai/relay_responses_validation_test.go
📝 变更描述 / Description
The direct OpenAI Responses relay currently forwards successful upstream reasoning items without validating their IDs. If an upstream emits
{"type":"reasoning","id":"item_..."}, clients can persist that output and replay it later, where a conforming endpoint rejects it because reasoning item IDs must use thers_prefix.This change validates reasoning output items before forwarding them:
bad_response_bodywith HTTP 502 before writing the malformed body.response.output_item.*event, and also validate reasoning items in terminalresponse.outputarrays.rs_IDs and non-reasoning item IDs are unchanged.🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Passed:
go test ./...was also run. All discovered packages passed except the root package setup, which requires the generatedweb/distdirectory that is absent in a clean backend worktree:Summary by CodeRabbit
Bug Fixes
Tests