Skip to content

fix: Use channel proxy settings for task query scenarios - #2398

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/video-proxy
Dec 9, 2025
Merged

fix: Use channel proxy settings for task query scenarios#2398
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/video-proxy

Conversation

@seefs001

@seefs001 seefs001 commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

fix #2392

Summary by CodeRabbit

  • New Features
    • Added proxy support for task operations. Task requests can now be routed through configured proxies for flexible network routing and improved request path control.

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

@coderabbitai

coderabbitai Bot commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds proxy support to video task status fetching by introducing a proxy parameter to the TaskAdaptor.FetchTask interface and threading proxy settings from channel configuration through all adaptor implementations, enabling task status queries to route through configured proxy addresses.

Changes

Cohort / File(s) Summary
Interface Definition
relay/channel/adapter.go
Updated TaskAdaptor.FetchTask signature to accept a fourth proxy string parameter, making the change required across all implementations.
Controller Updates
controller/task.go, controller/task_video.go, controller/video_proxy_gemini.go, relay/relay_task.go
Extract proxy from channel.GetSetting().Proxy and pass it to adaptor.FetchTask invocations.
Proxy Request Handling
controller/video_proxy.go
Replace hard-coded HTTP client with proxy-aware client from service.GetHttpClientWithProxy(proxy), add 60-second timeout context, and update error handling for proxy client creation.
TaskAdaptor Implementations
relay/channel/task/ali/adaptor.go, relay/channel/task/doubao/adaptor.go, relay/channel/task/gemini/adaptor.go, relay/channel/task/hailuo/adaptor.go, relay/channel/task/jimeng/adaptor.go, relay/channel/task/kling/adaptor.go, relay/channel/task/sora/adaptor.go, relay/channel/task/suno/adaptor.go, relay/channel/task/vidu/adaptor.go
Accept proxy string parameter in FetchTask, create proxy-enabled HTTP client via service.GetHttpClientWithProxy(proxy), and execute requests using the proxy client instead of default client.
Vertex Adaptor
relay/channel/task/vertex/adaptor.go
Accept proxy string parameter in FetchTask, thread proxy through both token acquisition (vertexcore.AcquireAccessToken) and HTTP client creation, use proxy-configured client for request execution.
Service Utility
service/http_client.go
Add new exported function GetHttpClientWithProxy(proxyURL string) (*http.Client, error) that returns default client if proxy is empty, otherwise returns proxy-enabled client.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Interface change requires verification across 10 TaskAdaptor implementations — ensure all adaptors correctly accept the new proxy parameter and use GetHttpClientWithProxy consistently
  • Error handling consistency — verify error messages for proxy client creation failures follow the same format across all adaptors
  • Controller proxy extraction — confirm proxy is correctly extracted from channel.GetSetting().Proxy and passed at all FetchTask call sites
  • Vertex adaptor complexity — additional threading of proxy through AcquireAccessToken requires extra scrutiny beyond the standard pattern
  • Service utility safety — verify GetHttpClientWithProxy correctly handles empty proxy strings and returns appropriate default or proxy client

Possibly related PRs

  • PR #2107: Adds proxy-aware HTTP client wiring for channel outbound requests, same pattern of threading proxy through HTTP client creation.
  • PR #1341: Modifies channel settings to include a Proxy field and threads the proxy through request code paths; foundational for this PR.
  • PR #1659: Threads proxy parameter through TaskAdaptor implementations including Vertex adaptor, overlapping scope with this PR.

Suggested reviewers

  • creamlike1024

Poem

🐰 Through channels we hop, with proxies in tow,
Task status now flows where the proxies go,
No more timeouts when socks5's the way,
Video tasks fetch and save the day! 🎬✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: applying channel proxy settings to task query scenarios, which directly addresses the linked issue about proxy settings not being used for GET task status requests.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #2392 by implementing proxy support across all task query adapters and call sites, ensuring channel proxy settings are applied to GET task status requests that were previously timing out.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of applying proxy settings to task queries. The signature updates to TaskAdaptor.FetchTask and corresponding implementations across all adapter files are necessary to support this objective.
✨ 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: 0

🧹 Nitpick comments (2)
service/http_client.go (1)

82-85: Consider aligning empty-proxy behavior with GetHttpClientWithProxy.

NewProxyHttpClient("") returns http.DefaultClient, while GetHttpClientWithProxy("") returns the properly initialized httpClient from GetHttpClient(). This inconsistency is unlikely to cause issues since callers should use GetHttpClientWithProxy, but could be confusing for future maintainers.

 func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
 	if proxyURL == "" {
-		return http.DefaultClient, nil
+		return GetHttpClient(), nil
 	}
relay/channel/task/vertex/adaptor.go (1)

123-127: Guard against nil ChannelSetting when deriving proxy

The proxy extraction is fine, but if info.ChannelSetting is ever a pointer type that can be nil, info.ChannelSetting.Proxy (Line [125]) would panic. If there’s any doubt, consider an additional nil-check around ChannelSetting or centralizing proxy resolution to one helper.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ebc713 and 5889571.

📒 Files selected for processing (17)
  • controller/task.go (1 hunks)
  • controller/task_video.go (2 hunks)
  • controller/video_proxy.go (3 hunks)
  • controller/video_proxy_gemini.go (1 hunks)
  • relay/channel/adapter.go (1 hunks)
  • relay/channel/task/ali/adaptor.go (2 hunks)
  • relay/channel/task/doubao/adaptor.go (2 hunks)
  • relay/channel/task/gemini/adaptor.go (2 hunks)
  • relay/channel/task/hailuo/adaptor.go (2 hunks)
  • relay/channel/task/jimeng/adaptor.go (2 hunks)
  • relay/channel/task/kling/adaptor.go (2 hunks)
  • relay/channel/task/sora/adaptor.go (2 hunks)
  • relay/channel/task/suno/adaptor.go (2 hunks)
  • relay/channel/task/vertex/adaptor.go (4 hunks)
  • relay/channel/task/vidu/adaptor.go (2 hunks)
  • relay/relay_task.go (1 hunks)
  • service/http_client.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (12)
relay/channel/task/jimeng/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/suno/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/doubao/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/gemini/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/vidu/adaptor.go (1)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/kling/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/ali/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
service/http_client.go (1)
common/constants.go (2)
  • RelayMaxIdleConns (124-124)
  • RelayMaxIdleConnsPerHost (125-125)
relay/channel/task/sora/adaptor.go (2)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/vertex/adaptor.go (3)
relay/channel/vertex/service_account.go (1)
  • AcquireAccessToken (143-149)
relay/channel/adapter.go (1)
  • TaskAdaptor (34-53)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
relay/channel/task/hailuo/adaptor.go (1)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
controller/video_proxy.go (2)
service/http_client.go (1)
  • GetHttpClientWithProxy (62-67)
logger/logger.go (1)
  • LogError (65-67)
🔇 Additional comments (17)
relay/relay_task.go (1)

329-337: LGTM! Proxy correctly passed to FetchTask for task status queries.

The changes properly extract the proxy setting from channel configuration and pass it to adaptor.FetchTask, which aligns with the PR objective to fix task status queries not using the channel proxy. This ensures GET requests for task status will route through the configured proxy (e.g., socks5://127.0.0.1:1080).

service/http_client.go (1)

61-67: LGTM! Clean abstraction for proxy-enabled HTTP clients.

The new GetHttpClientWithProxy function provides a convenient wrapper that returns the default client when no proxy is configured, or a proxy-enabled client otherwise. This aligns well with the PR's goal of threading proxy settings through task fetch calls.

controller/task.go (1)

119-122: LGTM! Proxy support added for Suno task polling.

The proxy is correctly extracted from channel settings and passed to adaptor.FetchTask, ensuring that background task status polling for Suno tasks also routes through the configured proxy.

relay/channel/adapter.go (1)

49-50: LGTM! Interface updated to support proxy parameter.

The FetchTask signature change enables all task adaptors to receive proxy settings. This is a breaking change for any external implementations of TaskAdaptor, but necessary to fulfill the PR objective of routing task queries through channel proxies.

relay/channel/task/jimeng/adaptor.go (1)

213-258: LGTM! Proxy support correctly implemented for Jimeng adaptor.

The FetchTask method properly:

  1. Accepts the new proxy parameter per the updated interface
  2. Creates a proxy-enabled HTTP client via GetHttpClientWithProxy(proxy)
  3. Handles client creation errors appropriately
  4. Uses the proxy-enabled client to execute the request

This implementation correctly enables task status queries to route through the channel's configured proxy.

controller/task_video.go (1)

70-80: LGTM! Proxy support correctly added for task status queries.

The changes properly extract the proxy from channel settings and pass it to FetchTask, ensuring that task status queries now respect the channel's configured proxy. This directly addresses the issue where GET requests for task status were timing out due to missing proxy configuration.

relay/channel/task/hailuo/adaptor.go (1)

113-134: LGTM! Proxy-enabled task fetching correctly implemented.

The implementation follows the correct pattern:

  1. Accepts proxy parameter in the updated signature
  2. Creates a proxy-aware HTTP client via GetHttpClientWithProxy
  3. Handles client creation errors appropriately
  4. Uses the proxy-enabled client for the request

This ensures Hailuo task status queries will route through the configured channel proxy.

relay/channel/task/gemini/adaptor.go (1)

203-231: LGTM! Gemini adaptor correctly implements proxy support.

The changes properly integrate proxy support into the Gemini task fetching flow. The implementation is consistent with other adaptors and ensures that Gemini video generation task queries will use the channel's configured proxy.

relay/channel/task/suno/adaptor.go (1)

135-161: LGTM! Proxy support correctly added for Suno task fetching.

The implementation properly integrates proxy support following the same pattern as other adaptors. The proxy-enabled client will ensure Suno task status queries route through the configured channel proxy.

relay/channel/task/doubao/adaptor.go (1)

149-171: LGTM! Doubao adaptor correctly implements proxy support.

The changes properly add proxy support to the Doubao task fetching implementation. The pattern is consistent with other adaptors and ensures task status queries will respect the channel's proxy configuration.

controller/video_proxy.go (1)

80-105: LGTM! Video proxy endpoint now correctly uses channel proxy settings.

The implementation properly:

  1. Extracts proxy from channel settings
  2. Creates a proxy-aware HTTP client with comprehensive error handling
  3. Adds a 60-second timeout context for resilience
  4. Provides clear error messages for proxy-related failures

This ensures video content retrieval will route through the configured channel proxy, addressing the core issue.

relay/channel/task/sora/adaptor.go (1)

128-148: LGTM! Sora adaptor correctly implements proxy support.

The changes properly integrate proxy support into the Sora task fetching flow. The implementation is consistent with other adaptors and ensures task status queries will use the channel's configured proxy settings.

controller/video_proxy_gemini.go (1)

38-42: LGTM! Gemini video URL resolution now uses channel proxy.

The changes correctly extract the proxy from channel settings and pass it to the Gemini adaptor's FetchTask method, ensuring that Gemini video URL resolution respects the channel's proxy configuration.

relay/channel/task/ali/adaptor.go (1)

395-416: Proxy-enabled FetchTask implementation looks correct

FetchTask now correctly routes the GET through service.GetHttpClientWithProxy(proxy) and handles client-construction failures before executing client.Do(req). This satisfies the requirement that task status queries respect the channel proxy while remaining a no-op when proxy == "".

relay/channel/task/vertex/adaptor.go (1)

222-273: Vertex FetchTask now fully proxy-aware (token + HTTP client)

FetchTask correctly uses the supplied proxy both for vertexcore.AcquireAccessToken(*adc, proxy) and for the HTTP client via service.GetHttpClientWithProxy(proxy), with proper error propagation on client construction. This aligns with the intended behavior that operation polling goes through the channel’s proxy.

relay/channel/task/vidu/adaptor.go (1)

191-212: Vidu FetchTask proxy plumbing is consistent and correct

FetchTask now obtains its client via service.GetHttpClientWithProxy(proxy) and surfaces construction errors with context, while preserving existing URL and header logic. This ensures Vidu task status polling respects channel proxy settings.

relay/channel/task/kling/adaptor.go (1)

201-236: Kling FetchTask correctly migrated to proxy-aware client

The updated FetchTask keeps the existing URL/JWT behavior and swaps execution to service.GetHttpClientWithProxy(proxy) with proper error handling. This brings Kling task polling in line with other adaptors for honoring channel proxy configuration.

@Calcium-Ion
Calcium-Ion merged commit e346f0b into QuantumNous:main Dec 9, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
fix: Use channel proxy settings for task query scenarios
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.

视频生成功能的get任务状态不通过【代理地址】

2 participants