fix(voices): 配音素材上传卡「处理中…」修复 #1552

Merged
auto-approve-bot merged 2 commits from fix/voice-upload-polling-dedup into develop 2026-08-30 11:46:05 +08:00
Owner

背景

配音素材上传弹窗卡在「处理中…」,根本原因:轮询循环里判断的成功状态写成了 "ready",但后端 IngestJobStatus 枚举是 pending/processing/completed/failed"ready" 是音色克隆(voice-clones)的状态,此处误用导致循环永远不退出,直到 maxRetries=60(5分钟)超时。

另外,后端 complete 接口在同库已存在相同 file_hash 素材时会返回 { duplicated: true, ingest_job_id: "" },当前代码直接解构 ingest_job_id 去轮询空 id,必卡死。

改动

1. 轮询成功状态修正

jobStatus !== "ready"jobStatus !== "completed"

2. 去重命中分支

uploadAssetDirect 调 complete 接口后,若 duplicated === trueingest_job_id 为空,不轮询、直接按上传成功处理(刷新列表、关闭弹窗、toast 提示)。

3. 轮询体验优化

complete 后立即查第一次(后端实际不到 1s 就处理完),未完成再每 5s 轮询。原代码先 sleep 5s 才首次查询,浪费时间。

4. 两个上传 hook 同步修改

  • pages/voices/hooks/useVoiceUpload.ts(旧配音库页,菜单实际入口)
  • pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts(新配音库页;去重命中时跳过轮询 + 打标签,直接走 onSuccess)

5. API 类型补齐

api/assets/types.tsDirectUploadCompleteResult 补上 duplicated?: booleanasset_id?: string 字段。

验收

  • staging 上传 m4a → 弹窗几秒内自动关闭、toast「上传成功」、列表立即出现新素材
  • 同一文件再传 → 不卡弹窗、toast「上传成功」、列表正常(后端返回 duplicated=true)
  • CI 全绿
## 背景 配音素材上传弹窗卡在「处理中…」,根本原因:轮询循环里判断的成功状态写成了 `"ready"`,但后端 IngestJobStatus 枚举是 `pending/processing/completed/failed`,`"ready"` 是音色克隆(voice-clones)的状态,此处误用导致循环永远不退出,直到 `maxRetries=60`(5分钟)超时。 另外,后端 `complete` 接口在同库已存在相同 `file_hash` 素材时会返回 `{ duplicated: true, ingest_job_id: "" }`,当前代码直接解构 `ingest_job_id` 去轮询空 id,必卡死。 ## 改动 ### 1. 轮询成功状态修正 `jobStatus !== "ready"` → `jobStatus !== "completed"` ### 2. 去重命中分支 `uploadAssetDirect` 调 complete 接口后,若 `duplicated === true` 或 `ingest_job_id` 为空,**不轮询、直接按上传成功处理**(刷新列表、关闭弹窗、toast 提示)。 ### 3. 轮询体验优化 complete 后**立即查第一次**(后端实际不到 1s 就处理完),未完成再每 5s 轮询。原代码先 sleep 5s 才首次查询,浪费时间。 ### 4. 两个上传 hook 同步修改 - `pages/voices/hooks/useVoiceUpload.ts`(旧配音库页,菜单实际入口) - `pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts`(新配音库页;去重命中时跳过轮询 + 打标签,直接走 onSuccess) ### 5. API 类型补齐 `api/assets/types.ts` 的 `DirectUploadCompleteResult` 补上 `duplicated?: boolean` 和 `asset_id?: string` 字段。 ## 验收 - staging 上传 m4a → 弹窗几秒内自动关闭、toast「上传成功」、列表立即出现新素材 - 同一文件再传 → 不卡弹窗、toast「上传成功」、列表正常(后端返回 duplicated=true) - CI 全绿
xiaoxia added 1 commit 2026-08-30 11:26:42 +08:00
fix(voices): 配音素材上传卡「处理中…」修复
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4m1s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 4m5s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 4m30s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m45s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m51s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m54s
AI Code Review / AI Code Review (pull_request) Failing after 5m57s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
166028094c
- 轮询成功状态从 'ready' 改为 'completed'('ready' 是 voice-clones 状态,误用)
- 去重命中分支:complete 接口返回 duplicated=true 或 ingest_job_id 为空时,
  不轮询直接按上传成功处理(刷新列表、关闭弹窗)
- 轮询优化:complete 后立即查第一次(后端通常 <1s 处理完),未完成再每 5s 轮询
- 两个上传 hook 同步修改:
  - pages/voices/hooks/useVoiceUpload.ts(旧配音库页)
  - pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts
    (新配音库页;去重命中时跳过轮询和打标签)
- api/assets/types.ts 的 DirectUploadCompleteResult 补充 duplicated/asset_id 字段

🚀 预览环境已部署

项目 详情
PR号 #1552
预览链接 https://pr-1552.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1552 | | 预览链接 | [https://pr-1552.preview.xiaoxiajianji.com](https://pr-1552.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:是
  • 阻塞级问题数量:2 个

📊 审查概览

  • 整体评价:需修改
  • 建议级问题数量:1 个

🔴 阻塞级问题(必须修复)

  1. [apps/web/src/pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts: 54] 去重逻辑导致流程中断

    • 问题类型:逻辑bug
    • 问题描述:代码中 if (complete.duplicated === true || !complete.ingest_job_id) { return } 会直接退出函数。根据注释“直接走 onSuccess”,意图是让上传流程正常结束并触发成功回调。但直接 return 会跳过后续的 onSuccess 调用(通常位于 try 块末尾),导致 UI 不刷新或无成功提示。此外,这也跳过了“打标签”步骤,如果用户本次上传选择了标签,去重后这些标签将丢失。
    • 修改建议:不应直接 return。应跳过轮询逻辑,但需确保后续的 onSuccess 仍能被调用。如果需要打标签,应使用返回的 complete.asset_id 对已存在的素材进行打标签。
  2. [apps/web/src/pages/voices/hooks/useVoiceUpload.ts: 40] 去重逻辑导致流程中断

    • 问题类型:逻辑bug
    • 问题描述:同上,if (complete.duplicated === true || !complete.ingest_job_id) { return } 会直接退出函数。注释明确要求“直接按上传成功处理(onSuccess 分支 toast + 刷新列表)”,但代码实现直接返回,导致用户看不到成功提示且列表不刷新。
    • 修改建议:移除 return,改为设置标志位或调整逻辑流,确保能走到 onSuccess 分支。
  3. [apps/web/src/pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts: 54] 异常状态被误判为成功

    • 问题类型:逻辑bug
    • 问题描述:判断条件 !complete.ingest_job_id 过于宽泛。如果后端因错误未返回 ingest_job_idduplicated 不为 true,代码会将其误判为去重成功而直接返回,掩盖了真实的上传失败。
    • 修改建议:精确判断条件,应为 if (complete.duplicated === true)。对于 !complete.ingest_job_id 且非 duplicated 的情况,应抛出错误或进行重试。

💡 改进建议(不阻塞合并)

  1. [apps/web/src/api/assets/types.ts: 143] 类型定义增强
    • 具体内容:建议使用更严格的类型约束来表示 duplicatedingest_job_id 的互斥关系,虽然 TS 难以完美运行时约束,但可以通过注释或 Discriminated Union 提示开发者这两个字段的关系。

良好实践

  • 轮询优化:在 useVoiceMaterialsuseVoiceUpload 中,将轮询逻辑改为“先立即查询一次,未完成再轮询”,这能有效减少快速完成任务时的等待时间,提升用户体验。
  • 状态修正:在 useVoiceUpload.ts 中修正了轮询状态的判断,从错误的 "ready" 改为正确的 "completed",修复了潜在的死循环或状态误判问题。

🤖 由 AI 代码审查机器人自动生成 | 2026-08-30 03:32:39 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:2 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:1 个 ### 🔴 阻塞级问题(必须修复) 1. **[apps/web/src/pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts: 54] 去重逻辑导致流程中断** - 问题类型:逻辑bug - 问题描述:代码中 `if (complete.duplicated === true || !complete.ingest_job_id) { return }` 会直接退出函数。根据注释“直接走 onSuccess”,意图是让上传流程正常结束并触发成功回调。但直接 `return` 会跳过后续的 `onSuccess` 调用(通常位于 try 块末尾),导致 UI 不刷新或无成功提示。此外,这也跳过了“打标签”步骤,如果用户本次上传选择了标签,去重后这些标签将丢失。 - 修改建议:不应直接 `return`。应跳过轮询逻辑,但需确保后续的 `onSuccess` 仍能被调用。如果需要打标签,应使用返回的 `complete.asset_id` 对已存在的素材进行打标签。 2. **[apps/web/src/pages/voices/hooks/useVoiceUpload.ts: 40] 去重逻辑导致流程中断** - 问题类型:逻辑bug - 问题描述:同上,`if (complete.duplicated === true || !complete.ingest_job_id) { return }` 会直接退出函数。注释明确要求“直接按上传成功处理(onSuccess 分支 toast + 刷新列表)”,但代码实现直接返回,导致用户看不到成功提示且列表不刷新。 - 修改建议:移除 `return`,改为设置标志位或调整逻辑流,确保能走到 `onSuccess` 分支。 3. **[apps/web/src/pages/voice-materials/hooks/useVoiceMaterials/actions/useVoiceUpload.ts: 54] 异常状态被误判为成功** - 问题类型:逻辑bug - 问题描述:判断条件 `!complete.ingest_job_id` 过于宽泛。如果后端因错误未返回 `ingest_job_id` 且 `duplicated` 不为 true,代码会将其误判为去重成功而直接返回,掩盖了真实的上传失败。 - 修改建议:精确判断条件,应为 `if (complete.duplicated === true)`。对于 `!complete.ingest_job_id` 且非 duplicated 的情况,应抛出错误或进行重试。 ### 💡 改进建议(不阻塞合并) 1. **[apps/web/src/api/assets/types.ts: 143] 类型定义增强** - 具体内容:建议使用更严格的类型约束来表示 `duplicated` 与 `ingest_job_id` 的互斥关系,虽然 TS 难以完美运行时约束,但可以通过注释或 Discriminated Union 提示开发者这两个字段的关系。 ### ✅ 良好实践 - **轮询优化**:在 `useVoiceMaterials` 和 `useVoiceUpload` 中,将轮询逻辑改为“先立即查询一次,未完成再轮询”,这能有效减少快速完成任务时的等待时间,提升用户体验。 - **状态修正**:在 `useVoiceUpload.ts` 中修正了轮询状态的判断,从错误的 `"ready"` 改为正确的 `"completed"`,修复了潜在的死循环或状态误判问题。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-30 03:32:39 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia added 1 commit 2026-08-30 11:34:12 +08:00
fix(voices): 精确判断去重分支 + 非 duplicated 时 ingest_job_id 缺失抛错
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4m16s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m28s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 4m25s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 4m34s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 5m15s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 6m35s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 7m6s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m14s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 3m40s
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 4m2s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 10m2s
CI/CD Pipeline / CI Gate (pull_request) Successful in 1m52s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 4m39s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 5m33s
008664512f
- 去重判断从 `duplicated === true || !ingest_job_id` 改为先判 duplicated
- 非 duplicated 但 ingest_job_id 缺失时抛错(避免掩盖真实上传失败)
- 回应 AI Code Review #1552 阻塞问题
xiaoxia force-pushed fix/voice-upload-polling-dedup from 01ff4b6777 to 008664512f 2026-08-30 11:34:12 +08:00 Compare
auto-approve-bot approved these changes 2026-08-30 11:45:34 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-08-30 11:45:34 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot merged commit 1106ba5c45 into develop 2026-08-30 11:46:05 +08:00
auto-approve-bot deleted branch fix/voice-upload-polling-dedup 2026-08-30 11:46:06 +08:00

🗑️ 预览环境已清理

PR #1552 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1552 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.