Skip to content

feat(codex): support non-streaming adaptation via SSE buffering with toggle setting - #2843

Closed
dahetaoa wants to merge 3 commits into
QuantumNous:mainfrom
dahetaoa:feat-codex-non-stream
Closed

feat(codex): support non-streaming adaptation via SSE buffering with toggle setting#2843
dahetaoa wants to merge 3 commits into
QuantumNous:mainfrom
dahetaoa:feat-codex-non-stream

Conversation

@dahetaoa

@dahetaoa dahetaoa commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

功能描述

Codex 后端的 /responses 接口原生仅支持流式 (SSE) 响应。本 PR 通过在 Relay 层缓冲 SSE 事件的方式,实现了对非流式请求的适配支持。

主要改动

  1. Relay 适配:在 relay/channel/codex/adaptor.go 中实现了 SSE 缓冲逻辑。当检测到非流式请求时,会收集所有 delta 直到 response.completed 事件,然后拼接成完整的 JSON 响应返回给客户端。
  2. 开关控制
    • 增加了 codex.non_stream_adapter_enabled 配置项(默认开启)。
    • 在前端 设置 -> 模型设置 -> Codex 中添加了对应的控制开关。
  3. 测试:补充了相关的单元测试。

依赖关系

此 PR 基于 #2826(Header 优化),建议在前者合并后进行 Review。

Summary by CodeRabbit

  • New Features

    • Added Codex API support with improved response handling capabilities.
    • Introduced configurable adapter for response conversion in settings.
    • New Codex settings panel added to configuration interface.
  • Tests

    • Added unit tests for API detection and response handling.

…ream

Codex upstream requires streaming for /responses endpoint. This change implements buffering of SSE events until 'response.completed' to support non-streaming client requests.
- Implement codex.non_stream_adapter_enabled setting (default true).
- Make the SSE buffering logic in Codex adaptor conditional based on the setting.
- Add frontend UI for Codex model settings.
- Fix Codex channel test logic to properly detect and build requests.
@coderabbitai

coderabbitai Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request introduces Codex API type support with non-stream adapter functionality, including early API type detection for endpoint routing, SSE-to-JSON conversion for non-stream clients, settings infrastructure for configuration, and corresponding UI components for management.

Changes

Cohort / File(s) Summary
Controller Channel Test Logic
controller/channel-test.go, controller/channel-test_test.go
Early API type detection to steer endpoint routing; routing consolidation for embedding, rerank, and Codex models; adjusted request construction for compact model suffixes and Codex-type APIs; unit tests verify correct request type selection for Codex channels.
Codex Adaptor Implementation
relay/channel/codex/adaptor.go, relay/channel/codex/adaptor_test.go
Non-stream adapter support with SSE-to-JSON buffering; SSE parsing logic to extract completed responses; header sanitization for non-stream responses; upstream Content-Type enforcement; unit tests validate SSE extraction across multiple event formats.
Settings Configuration
setting/model_setting/codex.go
New CodexSettings type with NonStreamAdapterEnabled boolean flag; default configuration initialized to true; GetCodexSettings() accessor; global config registration under "codex" key.
Web UI Integration
web/src/components/settings/ModelSetting.jsx, web/src/pages/Setting/Model/SettingCodexModel.jsx
Codex card added to settings UI with SettingCodexModel component; React form component for Codex configuration with switch control for non-stream adapter; state key 'codex.non_stream_adapter_enabled' with default true; form submission via API PUT requests with success/failure notifications.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Controller as Controller<br/>(Routing)
    participant Adaptor as Codex<br/>Adaptor
    participant Upstream as Codex<br/>Upstream
    participant Handler as SSE<br/>Handler

    Client->>Controller: Non-stream<br/>Codex request
    Controller->>Adaptor: Route request
    
    Adaptor->>Adaptor: NonStreamAdapterEnabled?
    
    alt Non-stream mode enabled
        Adaptor->>Upstream: Force upstream<br/>streaming (Accept: text/event-stream)
        Upstream-->>Handler: SSE stream
        
        Handler->>Handler: Parse SSE events<br/>(response.completed)
        Handler->>Handler: Extract JSON<br/>response body
        Handler->>Handler: Sanitize headers<br/>(remove content headers)
        
        Handler-->>Client: Single JSON<br/>response
    else Stream passthrough
        Upstream-->>Client: SSE stream
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

ready to merge

Suggested reviewers

  • seefs001
  • creamlike1024

Poem

🐰 Codex hops in with streaming ways,
SSE events parsed through the maze,
JSON packets bundled tight and clean,
Non-stream magic, now unseen,
Settings dance in UI so bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: adding non-streaming adaptation support to the Codex backend via SSE buffering with a configurable toggle setting, which aligns with the changeset's primary objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@seefs001

seefs001 commented Feb 6, 2026

Copy link
Copy Markdown
Collaborator

暂时不考虑这个非流转流的操作,可能会被用于分发,可能会违反OpenAI相关的政策,这个是给个人用户使用的。
不过这个Codex渠道固定用/v1/responses我觉得可以有。

@dahetaoa

dahetaoa commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

暂时不考虑这个非流转流的操作,可能会被用于分发,可能会违反OpenAI相关的政策,这个是给个人用户使用的。 不过这个Codex渠道固定用/v1/responses我觉得可以有。

Codex2api本身就违反OpenAI相关政策了,更何况newapi早就被用于商业分发了.... 我觉得做都做了不如做全,至少比留一个半成品好

@seefs001

seefs001 commented Feb 6, 2026

Copy link
Copy Markdown
Collaborator

暂时不考虑这个非流转流的操作,可能会被用于分发,可能会违反OpenAI相关的政策,这个是给个人用户使用的。 不过这个Codex渠道固定用/v1/responses我觉得可以有。

Codex2api本身就违反OpenAI相关政策了,更何况newapi早就被用于商业分发了.... 我觉得做都做了不如做全,至少比留一个半成品好

这个半成品本身就是刻意只允许在codex能用通,其他地方不支持使用。

@Calcium-Ion Calcium-Ion closed this Feb 6, 2026
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.

3 participants