feat: add MiniMax H3 video generation - #6591
Conversation
WalkthroughChangesMiniMax Hailuo V2 integration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant RelayTask
participant HailuoV2TaskAdaptor
participant MiniMaxAPI
participant TaskPolling
Client->>RelayTask: Submit MiniMax-H3 video task
RelayTask->>HailuoV2TaskAdaptor: Validate and build task request
HailuoV2TaskAdaptor->>MiniMaxAPI: Create video task
MiniMaxAPI-->>HailuoV2TaskAdaptor: Return upstream task ID
TaskPolling->>HailuoV2TaskAdaptor: Fetch task status
HailuoV2TaskAdaptor->>MiniMaxAPI: Poll upstream task
MiniMaxAPI-->>TaskPolling: Return task status and video result
TaskPolling-->>Client: Return OpenAI video response
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
service/task_billing_test.go (1)
872-885: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGive the legacy mock a distinct non-zero quota to prove precedence.
mockAdaptor{}leavesadjustReturnat 0, so the legacy path returns 0. The test name states that the checked result takes priority, but the assertion cannot distinguish precedence from the legacy path simply returning nothing. Set a different non-zero legacy value.♻️ Proposed test change
task := makeTask(userID, channelID, preConsumed, tokenID, BillingSourceWallet, 0) adaptor := &checkedMockAdaptor{ - mockAdaptor: &mockAdaptor{}, + mockAdaptor: &mockAdaptor{adjustReturn: 4000}, checkedReturn: actualQuota,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@service/task_billing_test.go` around lines 872 - 885, Update the test setup around checkedMockAdaptor to assign mockAdaptor.adjustReturn a distinct non-zero quota different from actualQuota, then retain the existing assertion that task.Quota equals actualQuota to verify the checked result takes precedence over the legacy result.relay/channel/task/hailuo_v2/adaptor.go (1)
328-346: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLog the fallback when upstream usage is unavailable.
Every early return yields
0, so settlement keeps the pre-reserved quota. For a request with a reference video, that reservation includesmaxReferenceInputSeconds(15s), so the user pays the worst case whenevertask.Datafails to parse orTotalSecondsis zero. Add a log line on these paths so operators can detect silent overcharges.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/channel/task/hailuo_v2/adaptor.go` around lines 328 - 346, Update AdjustBillingOnCompleteChecked to log when upstream usage is unavailable before returning the zero adjustment for task.Data unmarshalling failures or nonpositive response.Task.Usage.TotalSeconds. Include enough context to identify the fallback and preserve the existing settlement behavior and other early returns.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@controller/relay.go`:
- Line 599: Update the PerCallBilling condition in the relay billing flow so
completion-billed tasks with result.SettleOnComplete set do not trigger
submit-time settlement; retain the existing price-patch and UsePrice checks for
tasks settled per call.
In `@relay/channel/task/hailuo_v2/adaptor.go`:
- Around line 63-70: Update validateVideoRequest’s invalid-duration error to
report the computed maxAllowedDuration rather than the hardcoded 15, while
retaining the existing minimum-bound validation and error code.
- Around line 250-272: Update ParseTaskResult to explicitly handle every
additional Hailuo V2 task status returned by the upstream API, mapping each to
the appropriate TaskInfo status and progress; alternatively, ensure the
downstream relay/task_polling flow handles that status without falling through
to an unknown-status error. Preserve the existing mappings for queued, running,
succeeded, failed, cancelled, and expired.
---
Nitpick comments:
In `@relay/channel/task/hailuo_v2/adaptor.go`:
- Around line 328-346: Update AdjustBillingOnCompleteChecked to log when
upstream usage is unavailable before returning the zero adjustment for task.Data
unmarshalling failures or nonpositive response.Task.Usage.TotalSeconds. Include
enough context to identify the fallback and preserve the existing settlement
behavior and other early returns.
In `@service/task_billing_test.go`:
- Around line 872-885: Update the test setup around checkedMockAdaptor to assign
mockAdaptor.adjustReturn a distinct non-zero quota different from actualQuota,
then retain the existing assertion that task.Quota equals actualQuota to verify
the checked result takes precedence over the legacy result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2d9f305c-8a52-4f65-8ae8-48490f5437bf
📒 Files selected for processing (14)
constant/task.gocontroller/relay.gorelay/channel/adapter.gorelay/channel/minimax/adaptor_test.gorelay/channel/minimax/constants.gorelay/channel/task/hailuo_v2/adaptor.gorelay/channel/task/hailuo_v2/adaptor_test.gorelay/channel/task/hailuo_v2/models.gorelay/relay_adaptor.gorelay/relay_adaptor_minimax_test.gorelay/relay_task.goservice/task_billing_test.goservice/task_polling.gosetting/ratio_setting/model_ratio.go
|
已核实并处理本轮审查意见(2d4ed91b0):
另外两项经核实无需修改:
本地验证通过: |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
relay/relay_task.go (1)
149-161: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDefine platform selection for action-only task submissions.
RelayTaskSubmitselectsplatformbeforeinfo.Actionpopulatesinfo.UpstreamModelName. Ifc.GetString("platform")can be empty while bothinfo.OriginModelNameandinfo.Actionare also empty,GetTaskPlatformForModelreturns an empty platform andGetTaskAdaptorreturnsinvalid_api_platform. Require or injectplatformbefore adaptor selection, or derive the action/model first.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/relay_task.go` around lines 149 - 161, Update RelayTaskSubmit so action-only submissions determine a non-empty platform before GetTaskAdaptor is called. When the request platform is absent, derive it after info.Action or the relevant model-population flow has established info.UpstreamModelName; otherwise require or inject a valid platform and preserve the existing invalid-platform handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@relay/relay_task.go`:
- Around line 149-161: Update RelayTaskSubmit so action-only submissions
determine a non-empty platform before GetTaskAdaptor is called. When the request
platform is absent, derive it after info.Action or the relevant model-population
flow has established info.UpstreamModelName; otherwise require or inject a valid
platform and preserve the existing invalid-platform handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 19787584-aee3-450c-87d4-284b1910e486
📒 Files selected for processing (5)
controller/relay.gorelay/channel/task/hailuo_v2/adaptor.gorelay/channel/task/hailuo_v2/adaptor_test.gorelay/relay_task.goservice/task_billing_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
- service/task_billing_test.go
- controller/relay.go
- relay/channel/task/hailuo_v2/adaptor_test.go
- relay/channel/task/hailuo_v2/adaptor.go
Important
📝 变更描述 / Description
新增 MiniMax Video Generation V2(
MiniMax-H3)任务适配器,支持/v1/videos提交、多模态内容校验、V2 任务状态轮询和 OpenAI Video 响应转换。同一 MiniMax 渠道会根据映射后的上游模型选择 V1 或 V2 任务平台,并将平台写入任务记录,确保后台轮询继续使用正确协议。计费按官方秒价预扣;参考视频按最大输入时长预留,任务完成后依据上游
usage安全结算,并记录额度饱和审计信息。远程媒体的格式、大小及尺寸等内容属性仍由 MiniMax 上游校验。本变更由 AI 辅助实现,并经过本地测试与代码规范检查。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
以下命令均在本地通过:
make testGOWORK=off go vet ./...GOWORK=off go build ./...cd relaykit && GOWORK=off go vet ./...cd relaykit && GOWORK=off go build ./...新增回归测试覆盖 V2 请求校验与上游转换、异步查询状态和结果 URL、MiniMax V1/V2 平台选择,以及完成任务后的计费结算。
Summary by CodeRabbit
New Features
Billing
Bug Fixes