Skip to content

fix: accept fractional usage.duration in Ali video task results - #6174

Open
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/fix-intvalue-fractional
Open

fix: accept fractional usage.duration in Ali video task results#6174
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/fix-intvalue-fractional

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 13, 2026

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

阿里视频任务(如 happyhorse-1.0-video-edit)成功后,查询响应里的 usage.duration 可能是浮点数(实测返回过 13.9320.02)。dto.IntValue 之前只按 int → string 两步解析,无法解析小数。

改为先按 float64 解析再截断取整,字符串分支同样换成 ParseFloat,int / 浮点 / 数字字符串三种形式都能解。这条路径的 usage 不参与计费(ParseTaskResult 只读状态和 URL),截断没有计费影响。附了表驱动测试。

🚀 变更类型 / 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

$ go test ./dto/... -run TestIntValue -v
--- PASS: TestIntValueUnmarshalNumericForms (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/int (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/float (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/whole_float (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/int_string (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/float_string (0.00s)
    --- PASS: TestIntValueUnmarshalNumericForms/negative_float (0.00s)
PASS
ok  	github.com/QuantumNous/new-api/dto	0.299s

Successful Ali video tasks can report fractional usage durations
(e.g. "duration": 13.93). IntValue tried int then string, and Go
refuses to decode a float literal into int, so the whole task result
unmarshal failed: the succeeded video URL was never persisted,
settlement never ran, and every polling round repeated the error.

Parse as float64 and truncate, with a ParseFloat fallback for string
forms.
@feitianbubu feitianbubu changed the title fix: 兼容阿里视频任务 usage.duration 浮点值 fix: accept fractional usage.duration in Ali video task results Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

IntValue.UnmarshalJSON now accepts floating-point JSON values and numeric strings by parsing them as float64 before converting to int. Tests cover integer, float, negative, string, non-numeric, and boolean inputs.

Changes

Numeric IntValue parsing

Layer / File(s) Summary
Numeric parsing and validation
dto/values.go, dto/values_test.go
IntValue parses numeric values and strings with floating-point support, while table-driven tests verify accepted numeric forms and rejected non-numeric inputs.

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

Possibly related PRs

  • QuantumNous/new-api#4155: Updates Ali usage fields to use dto.IntValue, directly relating to this parser compatibility change.

Poem

A rabbit saw numbers hop and sway,
From "5.0" to 13.93.
IntValue caught them with a grin,
Floats and strings now tumble in.
Bad inputs stay outside the den! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed [#6166] IntValue now accepts float and numeric string duration values, which matches the issue's required compatibility fix.
Out of Scope Changes check ✅ Passed The only code changes are the parser fix and matching tests, both directly tied to the issue.
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 matches the main change: accepting fractional usage.duration values in Ali video task results.
✨ 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.

JacksonsY added a commit to JacksonsY/new-api that referenced this pull request Jul 19, 2026
移植上游 PR QuantumNous#6174。

阿里视频任务成功时 usage.duration 可能是小数(如 13.93),而 IntValue
先按 int 解码,Go 拒绝把浮点字面量解进 int,导致整个 task result 解析
失败:视频 URL 从未落库、结算从不执行、每轮轮询重复报错。改为按
float64 解析后截断,字符串形式回退 ParseFloat。

在上游方案上补饱和转换:改走 float64 后,超出 int 范围的上游数值
(如 1e300)转 int 是未定义行为,而原先的 int 解码会正确报错。IntValue
承载的正是上游用量数字(ali usage.duration、doubao duration),按
AGENTS.md 的计费安全不变量必须饱和而非回绕,并补溢出回归测试。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
JacksonsY added a commit to JacksonsY/new-api that referenced this pull request Jul 19, 2026
移植上游 PR QuantumNous#4810。

- ModelList 补 wan2.7-r2v / wan2.7-videoedit 与 happyhorse 1.0/1.1
- 补齐新版请求字段:reference_video_urls、reference_voice、ratio、
  audio_setting、shot_type,以及 usage 的 size/ratio/输入输出时长
- 新增 multipart.go:把 image_url / video_url / audio_url 表单字段按
  模型映射进 input.media(r2v 与 videoedit 归 reference_image,
  videoedit 的视频归 video,其余归 reference_video)
- 校验入口从 ValidateMultipartDirect 统一为 ValidateBasicTaskRequest,
  后者同样执行 validateTaskDurationBounds 且原生支持 multipart,
  时长上界校验不丢失
- EstimateBilling 保留 min(Duration, MaxTaskDurationSeconds) 钳制

上游 PR QuantumNous#4078(万相 wan2.7)未单独移植:仓库已含 wan2.7-i2v/t2v,其余
内容(四个 wan2.7 模型、ratio/audio_setting、usage 扩展、分辨率倍率)
均为本 PR 的子集;其 AliUsage.Duration 改 float64 的方案也已由 QuantumNous#6174
的 IntValue 饱和解码更完整地覆盖。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
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.

[Bug] 阿里渠道 happyhorse-1.0-video-edit 轮询结果时无法解析 usage.duration

1 participant