{"record":{"id":"e52e49d392a66896","repo":"docling-project/docling","slug":"invalid-inference-header-content-length-value-e52e49","errorCode":null,"errorMessage":"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len}","messagePattern":"Invalid (.+?) value: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/kserve_v2_http.py","lineNumber":192,"sourceCode":"    header_len_text = response.headers.get(_INFERENCE_HEADER_CONTENT_LENGTH)\n    if header_len_text is None:\n        try:\n            return KserveV2InferResponse.model_validate(response.json())\n        except Exception as exc:\n            raise RuntimeError(\n                f\"Binary KServe response from {response.url} did not include \"\n                f\"{_INFERENCE_HEADER_CONTENT_LENGTH} and was not valid JSON: {exc}\"\n            ) from exc\n\n    try:\n        header_len = int(header_len_text)\n    except ValueError as exc:\n        raise RuntimeError(\n            f\"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len_text!r}\"\n        ) from exc\n\n    if header_len < 0 or header_len > len(response.content):\n        raise RuntimeError(\n            f\"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len}\"\n        )\n\n    try:\n        header_json = json.loads(response.content[:header_len].decode(\"utf-8\"))\n        return KserveV2InferResponse.model_validate(header_json)\n    except Exception as exc:\n        raise RuntimeError(\n            f\"Invalid binary inference response header from {response.url}: {exc}\"\n        ) from exc\n\n\n@dataclass(frozen=True)\nclass KserveV2HttpClient:\n    \"\"\"Minimal client for KServe v2 REST infer requests.\"\"\"\n\n    base_url: str\n    model_name: str","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/kserve_v2_http.py#L174-L210","documentation":"_decode_binary_response: Inference-Header-Content-Length parsed to an int, but the value is negative or larger than the total response body length. The JSON header cannot possibly live within the body, indicating truncation (Content-Length mismatch, early connection close) or a corrupted header value.","triggerScenarios":"Response body truncated by a proxy enforcing a max-response-size; connection cut mid-transfer but requests still returned partial content; header claims a length computed before the server re-serialized the header; chunked-encoding reassembly bug.","commonSituations":"Gateway/CDN response size limits on large binary inference payloads; flaky links dropping bytes; server-side header-size arithmetic bugs.","solutions":["Compare the header value with the actual body length (log len(response.content)) to confirm truncation","Raise or remove max-response-size limits on proxies in front of the model server","Retry once - transient truncation resolves; if persistent, capture a tcpdump and inspect at the server","Fall back to use_binary_data=False (JSON responses are smaller per-element but avoid the header split)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    outputs = client.infer(inputs=inputs, output_names=[...])\nexcept RuntimeError as e:\n    if \"Invalid Inference-Header-Content-Length value\" in str(e):\n        outputs = client.infer(inputs=inputs, output_names=[...])  # truncation may be transient\n    else:\n        raise","preventionTips":["Raise gateway max-response-size limits above your largest inference payload","Monitor for partial-content responses on the infer route","Keep use_binary_data=False as a low-risk default in constrained network paths"],"tags":["http","kserve","binary-data","truncation","gateway"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}