Skip to content

feat: record perf metrics when async tasks reach terminal status - #7481

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/b8e318c4b
Sep 20, 2026
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/b8e318c4b

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

视频任务监控状态条显示

  • Closes #

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

📝 变更描述 / Description

模型广场的状态条只在同步 relay 里采样(RecordRelayResult),异步任务(视频/音乐等)从不采样,任务计费模型的状态条永远是灰的。

本 PR 在任务终态补上采样:

  • pkg/perf_metrics 新增 RecordTaskResult:任务转 SUCCESS/FAILURE 时记一次样本。成功率进状态条;延迟取 submit→finish 的端到端任务时长(秒级);上游报了 token 的任务(如豆包视频)带 token 吞吐,没报的照旧显示 —。
  • service/task_polling.go 把三处终态收尾(批量轮询、单任务轮询、连续轮询失败切断)收拢成 finalizeTerminalTask,采样挂在这一个点上,状态 CAS 赢家调用,每任务恰好一次。

范围取舍:提交阶段失败不采样(多为业务拒绝,零样本显示灰色"无数据"比假数据诚实);提交即终态的 immediate 路径与超时清扫本次不动。前端零改动,卡片有样本后自动出格子。

📸 运行证明 / Proof of Work

image

✅ 提交前检查项 / Checklist

  • 人工确认: 无论描述是否由 AI 生成,我已审阅并精炼全文,仅保留可复核的要点,并声明对其准确性与完整性负责。PR 正文及后续评论均未直接粘贴未经人工过滤的大段 AI 文本。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • 新功能关联 Issue: 若此 PR 标记为 New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。
  • 事前沟通: 若改动较大或涉及方向性变更,已在关联 Issue 中与维护者沟通并达成一致。
  • 功能范围: 本 PR 不是 Coding Plan、逆向渠道、第三方封装接口,也不是对 Codex 渠道类型的改动。
  • 非透传: 本 PR 不是针对开启透传后的转发行为;透传会直接发送内容,不会经过 new-api 的逻辑处理。
  • 范围聚焦: 本 PR 为一项聚焦改动,未包含无关代码。
  • 本地验证: 已按变更路径实际验证,并写明命令与观察结果。仅声明 go build 通过或测试通过,不视为有效证明。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 77ff9c90-ee4f-449f-995f-f4f8b832ec44

📥 Commits

Reviewing files that changed from the base of the PR and between 2fddb86 and a886cfb.

📒 Files selected for processing (3)
  • pkg/perf_metrics/metrics.go
  • pkg/perf_metrics/metrics_test.go
  • service/task_polling.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The change adds terminal task performance metrics and centralizes terminal finalization in finalizeTerminalTask. Batch, video, and polling failure paths now use this helper for metrics, billing settlement, and failure refunds.

Changes

Terminal task metrics

Layer / File(s) Summary
Metrics recording and validation
pkg/perf_metrics/metrics.go, pkg/perf_metrics/metrics_test.go
RecordTaskResult records task status, latency, output tokens, and generation duration using the available task data. Tests validate aggregation for successful, failed, and incomplete results.
Polling finalization integration
service/task_polling.go
updateBatchTasks, updateVideoSingleTask, and failTaskFromPoll use finalizeTerminalTask for result sampling, billing settlement, and failure refund fallback.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant TaskPolling
  participant finalizeTerminalTask
  participant RecordTaskResult
  participant Billing
  TaskPolling->>finalizeTerminalTask: finalize terminal task
  finalizeTerminalTask->>RecordTaskResult: record terminal metrics
  finalizeTerminalTask->>Billing: settle billing
  finalizeTerminalTask->>TaskPolling: apply failure refund fallback when required
Loading

Suggested reviewers: calcium-ion

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: recording performance metrics when asynchronous tasks reach a terminal status.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

A rabbit records each task’s final beat
Tokens and timings line up neat
Failed hops still mark the way
Billing settles at end of day
One helper keeps the trail complete

Comment @coderabbitai help to get the list of available commands.

@Calcium-Ion
Calcium-Ion merged commit 3abbb81 into QuantumNous:main Sep 20, 2026
3 checks passed
GuDong2003 pushed a commit to GuDong2003/new-api that referenced this pull request Sep 25, 2026
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.

2 participants