iflytek/astron-agent · error · CustomException
FILE_INVALID_TYPE_ERROR
FILE_INVALID_TYPE_ERROR
Error message
File size is missing from response headers
What it means
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.
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
Example fix
# before: server response HTTP/1.1 200 OK Transfer-Encoding: chunked # after: ensure server sends HTTP/1.1 200 OK Content-Length: 1048576
Defensive patterns
Strategy: try-catch
Validate before calling
import requests
h = requests.head(url, allow_redirects=True, timeout=10).headers
assert h.get("Content-Length"), "server does not report Content-Length" Type guard
def has_content_length(headers):
return bool(headers.get("Content-Length") or headers.get("content-length")) Try / catch
try:
ok = await File.check_file_var_isvalid(url, allowed, span)
except CustomException as e:
if e.err_code == CodeEnum.FILE_INVALID_TYPE_ERROR and "missing from response headers" in (e.cause_error or ""):
# fall back to a ranged GET or skip size validation
...
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/0c81293e769fac7c.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/engine/entities/file.py:162
input_file_url, allow_redirects=True, timeout=timeout
)
response.raise_for_status()
content_length = cls._extract_content_length(response.headers)
if content_length:
return content_length
# Some OSS gateways do not return Content-Length for HEAD requests.
response = requests.get(
input_file_url,
allow_redirects=True,
stream=True,
timeout=timeout,
)
try:
response.raise_for_status()
content_length = cls._extract_content_length(response.headers)
if not content_length:
raise CustomException(
err_code=CodeEnum.FILE_INVALID_TYPE_ERROR,
cause_error="File size is missing from response headers",
)
return content_length
finally:
response.close()
except CustomException as err:
raise err
except Exception as e:
raise CustomException(
err_code=CodeEnum.FILE_INVALID_TYPE_ERROR, cause_error=str(e)
) from e
@classmethod
async def check_file_var_isvalid(
cls, input_file_url: str, allowed_file_type: str, span_context: Span
) -> None:
"""View on GitHub (pinned to 5e758547a8)