Skip to content

fix: use stream for codex auto test - #4325

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/codex-stream-test
Apr 22, 2026
Merged

fix: use stream for codex auto test#4325
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/codex-stream-test

Conversation

@seefs001

@seefs001 seefs001 commented Apr 18, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

codex渠道自动测试没有使用stream导致无法自动启用

🚀 变更类型 / 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

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

Summary by CodeRabbit

  • Tests
    • Enhanced response validation for streaming channels to properly detect required data payloads, distinguish between incomplete responses and upstream errors, and improve test accuracy
    • Improved channel testing framework to intelligently enable streaming capabilities for compatible channel types, delivering more reliable test execution, enhanced error detection capabilities, and more accurate outcomes

@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The changes enhance channel test response validation by distinguishing between stream and non-stream responses. Stream responses now require valid SSE event payloads beyond just error detection, and automatic channel testing now enables streaming mode exclusively for Codex channels rather than unconditionally disabling it.

Changes

Cohort / File(s) Summary
Stream-Specific Validation and Codex Channel Testing
controller/channel-test.go
Added validateStreamTestResponseBody and refactored validation logic into validateTestResponseBody(respBody, isStream) that checks for upstream errors in non-stream tests and additionally validates SSE event payloads for stream tests. Introduced shouldUseStreamForAutomaticChannelTest to enable streaming mode selectively for Codex channels during automatic testing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through streaming tests so bright,
With Codex channels now enabled right,
SSE payloads validated with care,
No more silent failures hiding there! 🌊✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: enabling stream mode for Codex channel auto-testing, which directly addresses the core fix.
Linked Issues check ✅ Passed The code changes directly implement the fix for #4304 by enabling streaming for Codex channel auto-tests, which restores automatic re-enabling when account quotas recover.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the Codex channel auto-test streaming behavior; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

@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.

🧹 Nitpick comments (1)
controller/channel-test.go (1)

573-603: Optional: deduplicate SSE line scanning with detectErrorFromTestResponseBody.

validateStreamTestResponseBody and detectErrorFromTestResponseBody share nearly identical line-splitting / data: / [DONE] logic. validateTestResponseBody currently walks the body twice for stream responses. A small helper that yields decoded SSE payloads (or a single pass that both checks for upstream errors and tracks whether a valid event was seen) would DRY this up and halve the work on large bodies. Not blocking.

♻️ Sketch
// iterateSSEPayloads invokes fn for each non-empty, non-[DONE] data: payload.
// fn returns true to stop iteration.
func iterateSSEPayloads(b []byte, fn func(payload []byte) bool) {
    for _, line := range bytes.Split(b, []byte{'\n'}) {
        line = bytes.TrimSpace(line)
        if len(line) == 0 || !bytes.HasPrefix(line, []byte("data:")) {
            continue
        }
        payload := bytes.TrimSpace(bytes.TrimPrefix(line, []byte("data:")))
        if len(payload) == 0 || bytes.Equal(payload, []byte("[DONE]")) {
            continue
        }
        if fn(payload) {
            return
        }
    }
}

Then both validators can share it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@controller/channel-test.go` around lines 573 - 603, The SSE parsing in
validateStreamTestResponseBody is duplicated with
detectErrorFromTestResponseBody and causes double work for stream responses;
refactor by extracting a shared iterator (e.g., iterateSSEPayloads or similar)
that scans bytes.Split lines, trims, filters non-"data:" lines and "[DONE]"
payloads, and invokes a callback for each decoded payload; update
validateStreamTestResponseBody to use the iterator to detect any valid event and
update detectErrorFromTestResponseBody to use the same iterator to detect
upstream error payloads, then have validateTestResponseBody call
detectErrorFromTestResponseBody and, if streaming, rely on
validateStreamTestResponseBody which now uses the shared iterator so the body is
only scanned once per flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@controller/channel-test.go`:
- Around line 573-603: The SSE parsing in validateStreamTestResponseBody is
duplicated with detectErrorFromTestResponseBody and causes double work for
stream responses; refactor by extracting a shared iterator (e.g.,
iterateSSEPayloads or similar) that scans bytes.Split lines, trims, filters
non-"data:" lines and "[DONE]" payloads, and invokes a callback for each decoded
payload; update validateStreamTestResponseBody to use the iterator to detect any
valid event and update detectErrorFromTestResponseBody to use the same iterator
to detect upstream error payloads, then have validateTestResponseBody call
detectErrorFromTestResponseBody and, if streaming, rely on
validateStreamTestResponseBody which now uses the shared iterator so the body is
only scanned once per flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 52527016-0799-4889-bd01-372dbf6e19ed

📥 Commits

Reviewing files that changed from the base of the PR and between 5b9dcf1 and ccc6f9e.

📒 Files selected for processing (1)
  • controller/channel-test.go

@Calcium-Ion
Calcium-Ion merged commit 5f67d2a into QuantumNous:main Apr 22, 2026
2 checks passed
wanghualoong added a commit to wanghualoong/new-api that referenced this pull request Apr 22, 2026
Resolve conflict in controller/channel-test.go:
- Drop the legacy single-model testChannel call from origin/main
  (replaced by the per-model loop introduced in this PR).
- Adopt the new shouldUseStreamForAutomaticChannelTest(channel) helper
  (added by upstream PR QuantumNous#4325) inside the per-model goroutine, so codex
  channels are still tested with stream mode under the per-model regime.
liuyaaixxa pushed a commit to liuyaaixxa/xnew-api that referenced this pull request Apr 24, 2026
isboyjc pushed a commit to isboyjc/amux-api that referenced this pull request Apr 29, 2026
Jinxuans referenced this pull request in TokFlux-Org/TokFlux May 9, 2026
xyfacai pushed a commit to xyfacai/new-api that referenced this pull request May 30, 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.

运营管理-监控设置-成功时自动启用Codex通道失效

2 participants