fix(task): support xAI grok-imagine-video task polling - #5927
Conversation
xAI grok-imagine-video returns a different response shape than OpenAI
Sora, causing tasks to fail with 'upstream returned unrecognized
message' even when the video was generated successfully.
Three issues are fixed:
1. Status mapping: xAI returns status 'done' on completion, but the
sora adaptor only recognized 'completed'. 'done' is now mapped to
TaskStatusSuccess.
2. Result URL extraction: xAI embeds the video URL directly in
video.url instead of exposing a separate /content endpoint. The
responseTask struct now includes a Video field, and on success the
URL is propagated to taskResult.Url.
3. Empty status handling: xAI returns {id, request_id} without a
status field in early polling phases. The previous code treated
this as an unrecognized error and failed the task immediately. It
now keeps the current status and waits for the next polling round.
Related issue: #5045
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR adds video URL support to the Sora/xAI task adaptor, expanding success status handling and populating result URLs from a new video field, and modifies task polling to treat unrecognized empty-status upstream responses as retryable instead of failing the task. ChangesVideo Task Result and Polling Updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Important
📝 变更描述 / Description
xAI
grok-imagine-video(以及grok-imagine-video-preview、grok-image-video等同系列模型)通过 OpenAI 渠道调用时,任务永远返回FAILURE,错误信息为upstream returned unrecognized message,但实际上游 xAI 已经成功生成视频。根因是 xAI 的任务响应格式与 OpenAI Sora 存在 3 处差异,sora adaptor 完全没有适配:
问题 1:完成状态值不同
status: "completed"status: "done"ParseTaskResult只匹配"completed",导致"done"落入default分支,状态为空。问题 2:视频 URL 位置不同
/v1/videos/{id}/contentvideo.urlresponseTaskstruct 没有video字段,URL 被丢弃 →result_url为空。问题 3:空 status 被误判为失败(最致命)
{"request_id":"b53c8bb4-...","id":"task_xxx"}taskResult.Status == ""时尝试解析为 OpenAI 错误格式,解析失败后直接调用FailTaskInfo("upstream returned unrecognized message")判定任务失败。"done"状态。修复
relay/channel/task/sora/adaptor.go:ParseTaskResult的 switch 增加"done"case 映射为TaskStatusSuccess;responseTask增加Video字段,成功时从video.url提取结果地址。service/task_polling.go:空 status 且无法识别为 OpenAI 错误时,return nil保持当前状态等待下一轮轮询,不再判定为失败。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
upstream returned unrecognized message,本 PR 的修复 3 直接缓解)✅ 提交前检查项 / Checklist
grok-imagine-video、grok-imagine-video-preview、grok-image-video、grok-video-1.5、grok-imagine-video-1.5-preview五个模型全部正常生成视频。📸 运行证明 / Proof of Work
修复前(任务卡在第一轮就被判失败):
修复后(正常完成并提取到视频 URL):
响应对比(修复后 polling 拿到的 xAI 上游响应被正确解析):
{ "data": { "status": "SUCCESS", "result_url": "https://vidgen.x.ai/xai-vidgen-bucket/xai-video-xxx.mp4", "data": { "status": "done", "video": {"url": "https://vidgen.x.ai/.../xxx.mp4", "duration": 8} } } }Summary by CodeRabbit
New Features
Bug Fixes