calesthio/OpenMontage · error · TimeoutError

Kling Classic task {task_id} timed out after {timeout_second

Error message

Kling Classic task {task_id} timed out after {timeout_seconds}s

What it means

Raised as a TimeoutError when the poll_classic() loop runs past its deadline (timeout_seconds, defaulting per the caller) while the task never reaches a terminal status. The sleep at the end of each iteration is capped so the loop never sleeps past the deadline, making the timeout accurate to roughly one poll interval.

Source

Thrown at tools/_kling/client.py:101

    ) -> list[dict[str, Any]]:
        deadline = time.time() + timeout_seconds
        while time.time() < deadline:
            data = self.get(f"{path.rstrip('/')}/{task_id}")
            payload = data.get("data") or {}
            status = payload.get("task_status") or payload.get("status")
            if status == CLASSIC_SUCCESS_STATUS:
                task_result = payload.get("task_result") or {}
                outputs = task_result.get(result_key) or []
                if not isinstance(outputs, list):
                    raise KlingAPIError(f"Kling Classic result path data.task_result.{result_key} is not a list")
                return outputs
            if status == CLASSIC_FAILURE_STATUS:
                message = payload.get("task_status_msg") or payload.get("message") or "Kling Classic task failed"
                raise KlingAPIError(str(message), code=payload.get("task_status"), response=data)
            if status not in CLASSIC_PENDING_STATUSES:
                raise KlingAPIError(f"Unexpected Kling Classic task status {status!r}", response=data)
            time.sleep(min(poll_interval, max(0.0, deadline - time.time())))
        raise TimeoutError(f"Kling Classic task {task_id} timed out after {timeout_seconds}s")

    def create_turbo(self, path: str, payload: dict[str, Any]) -> str:
        data = self.post(path, payload)
        task_id = ((data.get("data") or {}).get("id"))
        if not task_id:
            raise KlingAPIError(f"Kling Turbo create response missing data.id: {data}")
        return str(task_id)

    def poll_turbo(
        self,
        task_id: str,
        timeout_seconds: int = 900,
        poll_interval: float = 5.0,
    ) -> list[dict[str, Any]]:
        deadline = time.time() + timeout_seconds
        while time.time() < deadline:
            data = self.get("/tasks", params={"task_ids": task_id})
            records = data.get("data") or []

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Increase timeout_seconds (e.g. 900–1800) for long generations or premium models
  2. Manually GET the task endpoint with the task_id to check whether it eventually completes, and resume polling instead of resubmitting (avoid double billing)
  3. Verify the task_id still exists — a deleted/expired task can pend forever from the client's view
  4. Wrap in retry logic that resumes polling the same task_id rather than creating a new task

Example fix

// before
outputs = client.poll_classic(path, task_id, 'videos', timeout_seconds=300)

// after
outputs = client.poll_classic(path, task_id, 'videos', timeout_seconds=1800, poll_interval=10.0)
Defensive patterns

Strategy: retry

Try / catch

try:
    outputs = client.poll_classic(path, task_id, 'videos', timeout_seconds=900)
except TimeoutError:
    # resume polling the SAME task instead of resubmitting (avoids double billing)
    outputs = client.poll_classic(path, task_id, 'videos', timeout_seconds=1800, poll_interval=15.0)

Prevention

When it happens

Trigger: A Kling Classic task stays in a pending status longer than timeout_seconds (e.g. queue congestion during peak hours, very long video generations); the task is genuinely stuck server-side; timeout_seconds was set too low by the caller relative to realistic generation time for the model (premium 1080p generations can take several minutes).

Common situations: Default timeout too short for high-resolution or long-duration generations; Kling queue backlogs during promotional periods; polling a task created with a different account whose status never resolves visible.

Understand the failure class

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/2cae1091141acf08. Report an issue: GitHub.