fix(lipsync): 修复 lipsync_tts 跨容器 import 错误导致 API/Worker 启动崩溃 #1849

Closed
xiaoxia wants to merge 1 commits from fix/lipsync-tts-deploy-crash into develop
Owner

问题

PR #1844 合并后 staging 部署失败(已自动回滚)。API 容器启动时 import lipsync_service → lipsync_tts 报错:

File "/app/apps/api/app/tasks/lipsync_tts.py", line 18
  from apps.worker.worker_app.celery_app import celery_app
ModuleNotFoundError: No module named 'apps.worker'

API 镜像不包含 apps/worker/ 目录(worker 是独立容器),从 worker 路径导入 celery_app 必然失败,健康检查 120s 超时触发自动回滚。

修复

  1. celery_app 导入路径:apps.worker.worker_app.celery_app → app.core.celery_app(API 侧 Celery app,API/Worker 镜像都复制了 core/)
  2. 去掉对 LipsyncService 反射依赖:LipsyncService.__new__ 调用 _sign_media_url 的 hacky 方式改为模块内独立 _sign_media_url() 函数(Worker 镜像不复制 services 目录,反射导入同样会崩)
  3. Worker 镜像补文件:worker.Dockerfile 补充 apps/api/app/tasks/、mediakit_client.py 及必需的 __init__.py,保证 Worker 能 import lipsync_tts task 并注册 Celery 路由。

测试

  • 56 个单元测试全部通过
  • 覆盖率:lipsync_tts.py 92% / lipsync_service.py 67% / 合计 76%
  • ruff/black/isort 均通过
## 问题 PR #1844 合并后 staging 部署失败(已自动回滚)。API 容器启动时 import lipsync_service → lipsync_tts 报错: ``` File "/app/apps/api/app/tasks/lipsync_tts.py", line 18 from apps.worker.worker_app.celery_app import celery_app ModuleNotFoundError: No module named 'apps.worker' ``` API 镜像不包含 `apps/worker/` 目录(worker 是独立容器),从 worker 路径导入 celery_app 必然失败,健康检查 120s 超时触发自动回滚。 ## 修复 1. **celery_app 导入路径**:`apps.worker.worker_app.celery_app` → `app.core.celery_app`(API 侧 Celery app,API/Worker 镜像都复制了 core/) 2. **去掉对 LipsyncService 反射依赖**:`LipsyncService.__new__` 调用 `_sign_media_url` 的 hacky 方式改为模块内独立 `_sign_media_url()` 函数(Worker 镜像不复制 services 目录,反射导入同样会崩) 3. **Worker 镜像补文件**:worker.Dockerfile 补充 `apps/api/app/tasks/`、`mediakit_client.py` 及必需的 `__init__.py`,保证 Worker 能 import lipsync_tts task 并注册 Celery 路由。 ## 测试 - 56 个单元测试全部通过 - 覆盖率:lipsync_tts.py 92% / lipsync_service.py 67% / 合计 76% - ruff/black/isort 均通过
xiaoxia added 1 commit 2026-09-10 20:51:05 +08:00
fix(lipsync): 修复 lipsync_tts 跨容器 import 错误导致 API/Worker 启动崩溃
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m5s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 29s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 15s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m40s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m2s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m21s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m29s
AI Code Review / AI Code Review (pull_request) Successful in 6m40s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m55s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 25m25s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 16s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 138h7m12s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 138h30m19s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 138h31m0s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 138h32m37s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 138h30m17s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 138h30m14s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 138h32m23s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 138h32m24s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 138h32m33s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 138h30m9s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 138h30m6s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 138h30m52s
72d8e99991
lipsync_tts.py 原从 apps.worker.worker_app 导入 celery_app,而 API 镜像中没有 apps.worker 目录,
导致 API 容器导入 lipsync_service 时 ModuleNotFoundError,健康检查失败触发自动回滚。

修复:
1. celery_app 改为从 app.core.celery_app 导入(API 侧 Celery app,API/Worker 镜像均存在)
2. _sign_media_url 改为模块内独立函数,去掉对 LipsyncService.__new__ 反射调用的依赖
   (Worker 镜像不复制 services 目录,反射导入会失败)
3. worker.Dockerfile 补充 apps/api/app/tasks/、mediakit_client.py 及必需的 __init__.py
   (Worker 进程需能 import lipsync_tts task 并注册 Celery 路由)

🚀 预览环境已部署

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

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

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

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

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

🗑️ 预览环境已清理

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

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

🗑️ **预览环境已清理** PR #1849 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Author
Owner

PR#1867 已合入 lipsync 三层防御(包含本 PR 的 celery_app 路径修复 + worker.Dockerfile COPY apps/api/app/ + @shared_task 改造),CI 全绿并部署 staging,本 PR 已被覆盖,关闭。

PR#1867 已合入 lipsync 三层防御(包含本 PR 的 celery_app 路径修复 + worker.Dockerfile COPY apps/api/app/ + @shared_task 改造),CI 全绿并部署 staging,本 PR 已被覆盖,关闭。
Some checks are pending
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m5s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 29s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 15s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m40s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 3m2s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m21s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 4m29s
AI Code Review / AI Code Review (pull_request) Successful in 6m40s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 8m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m55s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 25m25s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 16s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 138h7m12s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 138h30m19s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 138h31m0s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 138h32m37s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 138h30m17s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 138h30m14s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 138h32m23s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 138h32m24s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 138h32m32s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 138h32m33s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 138h6m58s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 138h6m59s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 138h30m9s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 138h30m6s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 138h30m52s

Pull request closed

Sign in to join this conversation.