{"record":{"id":"ef88ddb498654d03","repo":"calesthio/OpenMontage","slug":"kling-turbo-poll-response-missing-data-0-data","errorCode":null,"errorMessage":"Kling Turbo poll response missing data[0]: {data}","messagePattern":"Kling Turbo poll response missing data\\[0\\]: (.+?)","errorType":"exception","errorClass":"KlingAPIError","httpStatus":null,"severity":"error","filePath":"tools/_kling/client.py","lineNumber":121,"sourceCode":"    def create_turbo(self, path: str, payload: dict[str, Any]) -> str:\n        data = self.post(path, payload)\n        task_id = ((data.get(\"data\") or {}).get(\"id\"))\n        if not task_id:\n            raise KlingAPIError(f\"Kling Turbo create response missing data.id: {data}\")\n        return str(task_id)\n\n    def poll_turbo(\n        self,\n        task_id: str,\n        timeout_seconds: int = 900,\n        poll_interval: float = 5.0,\n    ) -> list[dict[str, Any]]:\n        deadline = time.time() + timeout_seconds\n        while time.time() < deadline:\n            data = self.get(\"/tasks\", params={\"task_ids\": task_id})\n            records = data.get(\"data\") or []\n            if not records:\n                raise KlingAPIError(f\"Kling Turbo poll response missing data[0]: {data}\")\n            record = records[0]\n            status = record.get(\"status\") or record.get(\"task_status\")\n            if status == TURBO_SUCCESS_STATUS:\n                outputs = record.get(\"outputs\") or []\n                if not isinstance(outputs, list):\n                    raise KlingAPIError(\"Kling Turbo result path data[0].outputs is not a list\")\n                return outputs\n            if status == TURBO_FAILURE_STATUS:\n                message = record.get(\"message\") or record.get(\"error\") or \"Kling Turbo task failed\"\n                raise KlingAPIError(str(message), code=record.get(\"code\"), request_id=record.get(\"request_id\"), response=data)\n            if status not in TURBO_PENDING_STATUSES:\n                raise KlingAPIError(f\"Unexpected Kling Turbo task status {status!r}\", response=data)\n            time.sleep(min(poll_interval, max(0.0, deadline - time.time())))\n        raise TimeoutError(f\"Kling Turbo task {task_id} timed out after {timeout_seconds}s\")\n\n    def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:\n        url = self._url(path)\n        last_error: KlingAPIError | None = None","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/client.py#L103-L139","documentation":"Raised when the Turbo poll GET /tasks?task_ids=<id> returns an empty (or non-list) data array. poll_turbo() immediately indexes records[0] after the emptiness check, so a first poll that arrives before the task registry has indexed the new task fails instead of waiting.","triggerScenarios":"Polling immediately after create_turbo() and the backend has not yet registered the task (eventual-consistency delay); querying with a task_id from a different base_url/deployment where it does not exist; the gateway filtering out tasks owned by another API key.","commonSituations":"Race between create and first poll on a load-balanced Turbo gateway; wrong region base URL so the task_id is unknown; task already expired and pruned from the registry.","solutions":["Add a short initial delay (2–5s) between create_turbo() and poll_turbo()","Verify base_url and task_id belong to the same deployment","If the gateway is eventually consistent, tolerate empty data for the first few polls before raising","Confirm the task_id string was not truncated or transformed"],"exampleFix":"// before\ntask_id = client.create_turbo(path, payload)\noutputs = client.poll_turbo(task_id)\n\n// after\nimport time\ntask_id = client.create_turbo(path, payload)\ntime.sleep(5)  # let the task registry index the new task\noutputs = client.poll_turbo(task_id)","handlingStrategy":"retry","validationCode":"def turbo_task_visible(client, task_id: str) -> bool:\n    data = client.get('/tasks', params={'task_ids': task_id})\n    return bool(data.get('data'))","typeGuard":null,"tryCatchPattern":"from tools._kling.errors import KlingAPIError\n\nfor attempt in range(3):\n    try:\n        outputs = client.poll_turbo(task_id)\n        break\n    except KlingAPIError as e:\n        if 'missing data[0]' not in str(e) or attempt == 2:\n            raise\n        time.sleep(3)  # registry propagation delay, then re-poll","preventionTips":["Sleep 2-5s between create_turbo() and the first poll_turbo() call","Keep create and poll on the same base_url/deployment","Treat an empty first poll as 'not yet visible', not as task failure"],"tags":["kling","api","turbo","polling","race-condition"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}