{"record":{"id":"6c793615154e369b","repo":"ATH-MaaS/Pixelle-Video","slug":"msg-task-id-task-id","errorCode":null,"errorMessage":"可灵视频生成失败: {msg} (task_id={task_id})","messagePattern":"可灵视频生成失败: (.+?) \\(task_id=(.+?)\\)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/video_kling.py","lineNumber":313,"sourceCode":"        轮询任务直到完成或失败\n\n        Returns:\n            任务结果数据\n\n        Raises:\n            RuntimeError: 任务失败\n            TimeoutError: 超过最大轮询次数\n        \"\"\"\n        for attempt in range(self.max_polls):\n            result = self._query_task(task_id, endpoint=endpoint)\n            status = result.get(\"task_status\", \"\")\n\n            if status == \"succeed\":\n                logger.info(f\"KlingVideoClient: 任务完成 task_id={task_id}\")\n                return result\n            elif status == \"failed\":\n                msg = result.get(\"task_status_msg\", \"未知错误\")\n                raise RuntimeError(f\"可灵视频生成失败: {msg} (task_id={task_id})\")\n            else:\n                # submitted / processing\n                logger.debug(\n                    f\"KlingVideoClient: 任务进行中 task_id={task_id}, \"\n                    f\"status={status}, attempt={attempt + 1}/{self.max_polls}\"\n                )\n                time.sleep(self.poll_interval)\n\n        raise TimeoutError(f\"可灵视频生成超时 (task_id={task_id}, 已等待 {self.max_polls * self.poll_interval}s)\")\n\n    # ─── 下载视频 ───\n\n    @staticmethod\n    def _download_video(video_url: str, save_path: str) -> None:\n        \"\"\"从 URL 下载视频到本地\"\"\"\n        save_dir = os.path.dirname(save_path)\n        if save_dir:\n            os.makedirs(save_dir, exist_ok=True)","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/video_kling.py#L295-L331","documentation":"During polling, the Kling task reached task_status 'failed'. The client raises RuntimeError carrying task_status_msg (Kling's own failure reason) and the task_id, since the job will never produce a video.","triggerScenarios":"_poll_until_done observes result['task_status'] == 'failed' and raises with result.get('task_status_msg', '未知错误') (video_kling.py:310-312). Happens when Kling's generation job itself fails: content moderation rejection, invalid image (unreadable/base64-broken), unsupported parameter combination, or internal generation error.","commonSituations":"Prompt or input image violating Kling content policy, corrupted or too-large input image, mode/duration/sound combos the backend rejects at generation time (not submission time), or platform-side capacity failures reported as failed tasks.","solutions":["Read task_status_msg in the exception — it is Kling's authoritative failure reason; address it directly (content, image validity, or params).","If the image input is the cause, re-encode/resize the image (valid JPEG/PNG, within Kling's size limits) before resubmitting.","If moderation-related, adjust the prompt/negative_prompt or swap the input image and retry.","For transient/internal failures reported by the platform, wait and resubmit; consider automatic one-time resubmission with backoff."],"exampleFix":"# before\nraise RuntimeError(f\"可灵视频生成失败: {msg} (task_id={task_id})\")  # 每次都失败\n# after\n# 失败原因为内容审核时，调整 prompt 后重试\nprompt = sanitized_prompt  # 移除触发审核的内容\nclient.generate_video(prompt=prompt, ...)","handlingStrategy":"try-catch","validationCode":"# 提交前过滤提示词与图片，降低审核失败概率\nif contains_flagged_terms(prompt):\n    raise ValueError(\"prompt 可能触发内容审核\")\ncheck_image_format(image_path)  # 有效的 JPEG/PNG，且在大小限制内","typeGuard":null,"tryCatchPattern":"try:\n    url = client.generate_video(...)\nexcept RuntimeError as e:\n    if str(e).startswith(\"可灵视频生成失败\"):\n        reason = str(e)\n        if \"审查\" in reason or \"moderation\" in reason.lower():\n            prompt = sanitize(prompt)\n            url = client.generate_video(prompt=prompt, ...)\n        else:\n            logger.error(f\"任务失败不可重试: {reason}\")","preventionTips":["Sanitize prompts and vet input images for policy compliance before submission","Validate image files (format, size, integrity) before base64-encoding","Avoid exotic mode/duration/sound combos that fail at generation time","Parse task_status_msg to classify retryable vs permanent failures"],"tags":["kling","task-failed","polling","content-moderation"],"backgroundTag":"generation-task-failed","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}