{"record":{"id":"0c81293e769fac7c","repo":"iflytek/astron-agent","slug":"file-invalid-type-error","errorCode":"FILE_INVALID_TYPE_ERROR","errorMessage":"File size is missing from response headers","messagePattern":"File size is missing from response headers","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/entities/file.py","lineNumber":162,"sourceCode":"                input_file_url, allow_redirects=True, timeout=timeout\n            )\n            response.raise_for_status()\n            content_length = cls._extract_content_length(response.headers)\n            if content_length:\n                return content_length\n\n            # Some OSS gateways do not return Content-Length for HEAD requests.\n            response = requests.get(\n                input_file_url,\n                allow_redirects=True,\n                stream=True,\n                timeout=timeout,\n            )\n            try:\n                response.raise_for_status()\n                content_length = cls._extract_content_length(response.headers)\n                if not content_length:\n                    raise CustomException(\n                        err_code=CodeEnum.FILE_INVALID_TYPE_ERROR,\n                        cause_error=\"File size is missing from response headers\",\n                    )\n                return content_length\n            finally:\n                response.close()\n        except CustomException as err:\n            raise err\n        except Exception as e:\n            raise CustomException(\n                err_code=CodeEnum.FILE_INVALID_TYPE_ERROR, cause_error=str(e)\n            ) from e\n\n    @classmethod\n    async def check_file_var_isvalid(\n        cls, input_file_url: str, allowed_file_type: str, span_context: Span\n    ) -> None:\n        \"\"\"","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/entities/file.py#L144-L180","documentation":"File.get_file_size performs a HEAD/ranged HTTP request against a file URL and raises FILE_INVALID_TYPE_ERROR (with cause 'File size is missing from response headers') when Content-Length cannot be extracted from the response headers. The engine requires a size to validate the file variable, and a response without a usable size header cannot be checked. This wraps the header-extraction step; the actual network call succeeded (raise_for_status passed) but the server omitted size information.","triggerScenarios":"Calling check_file_var_isvalid on a file URL whose server responds 200 but without Content-Length (chunked transfer encoding, HEAD not honoring Content-Length, proxies stripping headers, or presigned URLs that omit the header).","commonSituations":"Object storage behind CDNs/proxies that strip Content-Length; servers using chunked encoding without length; MinIO/S3 configs returning multipart or compressed responses; custom file servers that don't set Content-Length on HEAD requests.","solutions":["Configure the file server/storage to return Content-Length on HEAD/GET responses","Bypass or reconfigure proxies/CDN layers that strip Content-Length headers","If downloads are chunked, serve the file with a fixed length or switch to a storage backend that reports size","Extend the check to fetch size via a ranged GET (Range: bytes=0-0 with Content-Range) when Content-Length is absent"],"exampleFix":"# before: server response\nHTTP/1.1 200 OK\nTransfer-Encoding: chunked\n# after: ensure server sends\nHTTP/1.1 200 OK\nContent-Length: 1048576","handlingStrategy":"try-catch","validationCode":"import requests\nh = requests.head(url, allow_redirects=True, timeout=10).headers\nassert h.get(\"Content-Length\"), \"server does not report Content-Length\"","typeGuard":"def has_content_length(headers):\n    return bool(headers.get(\"Content-Length\") or headers.get(\"content-length\"))","tryCatchPattern":"try:\n    ok = await File.check_file_var_isvalid(url, allowed, span)\nexcept CustomException as e:\n    if e.err_code == CodeEnum.FILE_INVALID_TYPE_ERROR and \"missing from response headers\" in (e.cause_error or \"\"):\n        # fall back to a ranged GET or skip size validation\n        ...\n    raise","preventionTips":["Serve files from storage that always returns Content-Length","Avoid proxies/CDN configs that strip response headers","Prefer presigned object-storage URLs over dynamic streaming endpoints"],"tags":["http","file","headers","validation"],"backgroundTag":"unexpected-response-shape","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}