Repository navigation
fix(task): treat unparseable task state as busy - #1663
Merged
harry0703 merged 2 commits intoOct 17, 2026
Merged
Conversation
Owner
|
已合并。Python 3.11、Python 3.13 和 Windows smoke CI 都通过了,本地也验证了异常状态不会误删任务文件,正常视频生成不受影响。谢谢这个修复和补充测试! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
app/services/task.py:is_task_busy()的 docstring 承诺"未识别状态统一视为忙碌",但代码try/except把int(state)失败时悄悄pass,让字符串状态在删除路径上变成 False。delete_video()接到这种 task 时会shutil.rmtree任务目录、把可能仍在生成视频或正在跨平台发布的任务直接取消——任务目录丢失,状态记录被清空,下游 pipeline 写入失败。Root Cause
state何时会变成字符串:update_task写入的state字段,参见app/services/state.py:RedisState)update_task(task_id, state="processing")这种非 int 调用——update_task签名是state: int,但 Python 运行时并不强制Fix
替换
pass为return True——遵守函数自身的 docstring,让删除 API 在无法判断状态时保守拒绝。is_task_busy唯一的删除调用方delete_video()已经会把 True 翻译成 409task is still running,用户路径不会破。旁路分支:若
cross_post_state已在活跃集合里,原来已经返回 True,新代码现在更早返回 True——结果一致。Testing
新增
test/services/test_is_task_busy_string_state.py,覆盖:cross_post_state→ True(这正是被原代码漏掉的删除路径)TASK_STATE_PROCESSING→ True(已有路径不变)TASK_STATE_COMPLETE+ 空闲cross_post_state→ False(已有路径不变)Nonetask → False(已有路径不变)并在
setUp/tearDown清理进程级_cross_post_futures字典,与test/services/test_task.py:TestTaskService的清理风格一致。Scope
update_task(),避免一次性放大改动面;如果需要让写入端也强制 int 转换可以放后续 PRis_task_busy()的签名或返回类型state不可解析这一窄路径,对正常 int 流程完全透明