Skip to content

fix(task): preserve selected key for multi-key polling - #6870

Open
enwaiax wants to merge 1 commit into
QuantumNous:mainfrom
enwaiax:fix/task-polling-multi-key-6864
Open

fix(task): preserve selected key for multi-key polling#6870
enwaiax wants to merge 1 commit into
QuantumNous:mainfrom
enwaiax:fix/task-polling-multi-key-6864

Conversation

@enwaiax

@enwaiax enwaiax commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / Description

多密钥渠道提交异步任务时,分发器已经选出了本次请求实际使用的 API key,但任务记录只为 Gemini/Vertex AI 保存该 key。阿里视频任务因此在后台轮询时回退到包含多个换行分隔 key 的渠道原始字段,写入 Authorization 后触发非法 header 错误。

本 PR 在初始化多密钥任务时保存本次请求实际选中的 key。现有轮询逻辑会优先读取该私有字段,因此后续查询使用与任务提交时相同的凭据;单密钥渠道行为保持不变。

新增表驱动回归测试,覆盖多密钥、普通单密钥以及 Gemini/Vertex 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

新增测试在修复前可以稳定复现失败:

TestInitTaskPreservesSelectedKeyForPolling/multi-key_task_keeps_the_selected_key
expected: "selected-key"
actual:   ""

应用修复后:

go test ./model -run TestInitTaskPreservesSelectedKeyForPolling -count=1
ok github.com/QuantumNous/new-api/model

go test ./model ./service -count=1
ok github.com/QuantumNous/new-api/model
ok github.com/QuantumNous/new-api/service

go vet ./...
go build ./...
# passed

补充说明:本 PR 代码为 AI-assisted 生成,并已人工复核、执行回归测试及质量检查。

Summary by CodeRabbit

  • Bug Fixes

    • Preserved channel API keys when initializing tasks for multi-key channels.
    • Continued correct API key handling for Gemini, Vertex AI, and single-key channels.
  • Tests

    • Added coverage for API key preservation across supported channel configurations.

@coderabbitai

coderabbitai Bot commented Aug 15, 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: 4c4d72ef-81d2-41df-8562-1c868a10585f

📥 Commits

Reviewing files that changed from the base of the PR and between e2c7aa7 and 799d3fa.

📒 Files selected for processing (2)
  • model/task.go
  • model/task_test.go

Walkthrough

InitTask now preserves API keys for multi-key channels. Table-driven tests cover multi-key Ali, single-key Ali, Gemini, and Vertex AI configurations.

Changes

Task key preservation

Layer / File(s) Summary
InitTask key capture and validation
model/task.go, model/task_test.go
InitTask stores the channel key for multi-key channels while retaining Gemini and Vertex AI handling. Tests verify key preservation and clearing across supported channel configurations.

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

Merge Risk: ⚪ Minimal · up to 799d3

The change preserves the selected API key for asynchronous polling while keeping single-key and existing Gemini/Vertex AI behavior unchanged; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: calcium-ion

Poem

I’m a rabbit with keys in a row,
Multi-key tasks now know where to go.
Ali, Gemini, Vertex align,
Tests keep each task key in line.
Hop, hop—the polling paths now grow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes preserve the selected key for multi-key Ali tasks and add regression tests, meeting issue #6864.
Out of Scope Changes check ✅ Passed The implementation and tests focus on multi-key task key preservation and related compatibility cases.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes preserving the selected API key for multi-key task polling, which is the main change.
✨ 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.

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.

阿里视频任务轮询不支持多密钥模式(multi-key)

1 participant