Skip to content

feat: forward all Codex SSE response headers for codex sub#6098

Open
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/chatgpt-sub-sse-response-header
Open

feat: forward all Codex SSE response headers for codex sub#6098
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/chatgpt-sub-sse-response-header

Conversation

@seefs001

@seefs001 seefs001 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

codex渠道类型全量透传sse response header

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Improved streaming responses for Codex requests by preserving supported upstream headers, including multiple cookies.
    • Added buffering support to better handle larger streamed responses.
  • Bug Fixes

    • Prevented inappropriate headers, such as content length, from being forwarded.
    • Preserved existing header behavior for non-Codex requests.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The stream scanner gains configurable buffering and conditional SSE header copying. Codex channels copy eligible upstream headers, while non-Codex channels preserve legacy behavior. Tests cover header inclusion, exclusion, and multi-valued cookies.

Changes

Codex SSE header propagation

Layer / File(s) Summary
Scanner buffering and conditional header copying
relay/helper/stream_scanner.go
Adds NewStreamScanner, configurable buffer sizing, named Codex headers, and channel-type-based header selection.
Header propagation coverage
relay/helper/stream_scanner_test.go
Tests Codex header copying, Set-Cookie, Content-Length exclusion, and non-Codex legacy behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StreamScannerHandler
  participant copyCodexSSEHeaders
  participant UpstreamResponse
  participant GinWriter
  StreamScannerHandler->>copyCodexSSEHeaders: pass Codex channel flag
  copyCodexSSEHeaders->>UpstreamResponse: select upstream headers
  copyCodexSSEHeaders->>GinWriter: append eligible header values
Loading

Possibly related PRs

Poem

I’m a bunny with headers to copy,
Through SSE streams that hop bright and spry.
Codex gets cookies, the rest keep their tune,
Buffers grow softly beneath the moon.
Tests nibble bugs till they all say goodbye! 🐇

🚥 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%. 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 describes the main change: forwarding Codex SSE response headers for Codex subscriptions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/helper/stream_scanner.go`:
- Line 28: Correct the comment for DefaultMaxScannerBufferSize to state that 128
<< 20 is 128MB (128*1024*1024), matching the configured value.
🪄 Autofix (Beta)

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

Run ID: 09d0c97a-e733-486c-827d-25fce23f64cb

📥 Commits

Reviewing files that changed from the base of the PR and between dad57a6 and 5fa871a.

📒 Files selected for processing (2)
  • relay/helper/stream_scanner.go
  • relay/helper/stream_scanner_test.go

DefaultMaxScannerBufferSize = 128 << 20 // 64MB (64*1024*1024) default SSE buffer size
DefaultPingInterval = 10 * time.Second
InitialScannerBufferSize = 64 << 10 // 64KB (64*1024)
DefaultMaxScannerBufferSize = 128 << 20 // 64MB (64*1024*1024) default SSE buffer size

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix incorrect comment: 128 << 20 is 128MB, not 64MB.

The value 128 << 20 equals 134,217,728 bytes (128MB), but the comment states "64MB (6410241024)". This could mislead developers tuning buffer size.

📝 Proposed fix
-	DefaultMaxScannerBufferSize  = 128 << 20 // 64MB (64*1024*1024) default SSE buffer size
+	DefaultMaxScannerBufferSize  = 128 << 20 // 128MB (128*1024*1024) default SSE buffer size
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DefaultMaxScannerBufferSize = 128 << 20 // 64MB (64*1024*1024) default SSE buffer size
DefaultMaxScannerBufferSize = 128 << 20 // 128MB (128*1024*1024) default SSE buffer size
🤖 Prompt for 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.

In `@relay/helper/stream_scanner.go` at line 28, Correct the comment for
DefaultMaxScannerBufferSize to state that 128 << 20 is 128MB (128*1024*1024),
matching the configured value.

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.

1 participant