Skip to content

fix(task): 修复渠道配置多个key时无法获取任务的问题 - #2447

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
a4399518s:main
Jan 3, 2026
Merged

fix(task): 修复渠道配置多个key时无法获取任务的问题#2447
seefs001 merged 1 commit into
QuantumNous:mainfrom
a4399518s:main

Conversation

@a4399518s

@a4399518s a4399518s commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

视频任务的渠道配置了多个key时,获取任务详细信息报错。

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced video task functionality with improved credential selection logic that intelligently prioritizes task-specific authorization information when available, with appropriate fallback handling. This optimization ensures more reliable video data requests and better upstream connection resolution, strengthening overall system stability for video operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The key selection logic for FetchTask in the task video controller was modified. The code now prioritizes using task.PrivateData.Key when available, otherwise falling back to channel.Key. This updated key is passed to adaptor.FetchTask, changing authentication or path resolution for upstream requests.

Changes

Cohort / File(s) Change Summary
Key Selection Logic
controller/task_video.go
Modified FetchTask key selection to use task.PrivateData.Key when provided, with fallback to channel.Key; updated key passed to adaptor.FetchTask

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the fallback logic correctly handles cases where task.PrivateData.Key is nil or empty
  • Confirm this change doesn't break existing behavior for tasks without PrivateData.Key set
  • Check downstream impact on adaptor.FetchTask behavior with the different key sources

Poem

A rabbit hops through keys with care,
Choosing the right one here and there,
PrivateData first, if it's around,
Else Channel's key—a solid ground! 🐰🔑

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing an issue where tasks cannot be retrieved when a channel has multiple keys configured, which aligns with the code modification that selects the key from task.PrivateData.Key as a fallback.
✨ 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.

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ea8cbd and 0217ed2.

📒 Files selected for processing (1)
  • controller/task_video.go (1 hunks)
🔇 Additional comments (1)
controller/task_video.go (1)

55-56: No issue found. All FetchTask implementations across adaptor types (vidu, suno, sora, kling, gemini, ali, hailuo, doubao, vertex, jimeng, and others) explicitly use the key parameter passed to the method in API requests, not any key stored during Init(). The per-task key override at lines 77-82 works correctly.

Comment thread controller/task_video.go
Comment on lines +77 to +82
key := channel.Key

privateData := task.PrivateData
if privateData.Key != "" {
key = privateData.Key
}

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.

⚠️ Potential issue | 🔴 Critical

Add nil check for task.PrivateData to prevent potential panic.

If task.PrivateData is nil, accessing privateData.Key on line 80 will cause a nil pointer dereference panic. Add a nil check before accessing the struct field.

Apply this diff to add a nil check:

 	key := channel.Key
 
 	privateData := task.PrivateData
-	if privateData.Key != "" {
+	if privateData != nil && privateData.Key != "" {
 		key = privateData.Key
 	}
📝 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
key := channel.Key
privateData := task.PrivateData
if privateData.Key != "" {
key = privateData.Key
}
key := channel.Key
privateData := task.PrivateData
if privateData != nil && privateData.Key != "" {
key = privateData.Key
}
🤖 Prompt for AI Agents
In controller/task_video.go around lines 77 to 82, the code reads
task.PrivateData without checking for nil which can cause a nil pointer
dereference; update the logic to first test if task.PrivateData != nil and only
then read privateData.Key, e.g. retrieve privateData into a local var after the
nil check (or check task.PrivateData.Key only when task.PrivateData != nil) and
set key to privateData.Key if present otherwise fall back to channel.Key.

@Calcium-Ion
Calcium-Ion requested a review from seefs001 December 15, 2025 12:17
@seefs001 seefs001 added the ready to merge It will eventually merge, requiring a final check. label Dec 26, 2025
@seefs001
seefs001 merged commit 9cf756f into QuantumNous:main Jan 3, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge It will eventually merge, requiring a final check.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants