ATH-MaaS/Pixelle-Video · error · RuntimeError

可灵视频生成失败: {msg} (task_id={task_id})

Error message

可灵视频生成失败: {msg} (task_id={task_id})

What it means

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.

Source

Thrown at pixelle_video/services/api_services/video_kling.py:313

        轮询任务直到完成或失败

        Returns:
            任务结果数据

        Raises:
            RuntimeError: 任务失败
            TimeoutError: 超过最大轮询次数
        """
        for attempt in range(self.max_polls):
            result = self._query_task(task_id, endpoint=endpoint)
            status = result.get("task_status", "")

            if status == "succeed":
                logger.info(f"KlingVideoClient: 任务完成 task_id={task_id}")
                return result
            elif status == "failed":
                msg = result.get("task_status_msg", "未知错误")
                raise RuntimeError(f"可灵视频生成失败: {msg} (task_id={task_id})")
            else:
                # submitted / processing
                logger.debug(
                    f"KlingVideoClient: 任务进行中 task_id={task_id}, "
                    f"status={status}, attempt={attempt + 1}/{self.max_polls}"
                )
                time.sleep(self.poll_interval)

        raise TimeoutError(f"可灵视频生成超时 (task_id={task_id}, 已等待 {self.max_polls * self.poll_interval}s)")

    # ─── 下载视频 ───

    @staticmethod
    def _download_video(video_url: str, save_path: str) -> None:
        """从 URL 下载视频到本地"""
        save_dir = os.path.dirname(save_path)
        if save_dir:
            os.makedirs(save_dir, exist_ok=True)

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Read task_status_msg in the exception — it is Kling's authoritative failure reason; address it directly (content, image validity, or params).
  2. If the image input is the cause, re-encode/resize the image (valid JPEG/PNG, within Kling's size limits) before resubmitting.
  3. If moderation-related, adjust the prompt/negative_prompt or swap the input image and retry.
  4. For transient/internal failures reported by the platform, wait and resubmit; consider automatic one-time resubmission with backoff.

Example fix

# before
raise RuntimeError(f"可灵视频生成失败: {msg} (task_id={task_id})")  # 每次都失败
# after
# 失败原因为内容审核时,调整 prompt 后重试
prompt = sanitized_prompt  # 移除触发审核的内容
client.generate_video(prompt=prompt, ...)
Defensive patterns

Strategy: try-catch

Validate before calling

# 提交前过滤提示词与图片,降低审核失败概率
if contains_flagged_terms(prompt):
    raise ValueError("prompt 可能触发内容审核")
check_image_format(image_path)  # 有效的 JPEG/PNG,且在大小限制内

Try / catch

try:
    url = client.generate_video(...)
except RuntimeError as e:
    if str(e).startswith("可灵视频生成失败"):
        reason = str(e)
        if "审查" in reason or "moderation" in reason.lower():
            prompt = sanitize(prompt)
            url = client.generate_video(prompt=prompt, ...)
        else:
            logger.error(f"任务失败不可重试: {reason}")

Prevention

When it happens

Trigger: _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.

Common situations: 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.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/6c793615154e369b. Report an issue: GitHub.