musistudio/claude-code-router · error
The CCR artifact response length did not match its headers.
Error message
The CCR artifact response length did not match its headers.
What it means
The number of bytes actually streamed did not equal the declared Content-Length. This guards against truncated or padded responses and against misleading size metadata before the bytes are sniffed and returned.
Source
Thrown at packages/core/src/agents/codex/media-preview-bridge.ts:333
throw new Error("Compressed CCR media artifacts are not accepted for inline preview.");
}
if (!response.body) throw new Error("The CCR artifact response had no body.");
const reader = response.body.getReader();
const chunks: Buffer[] = [];
let total = 0;
while (true) {
const part = await reader.read();
if (part.done) break;
if (!part.value?.byteLength) continue;
total += part.value.byteLength;
if (total > maxBytes) {
await reader.cancel();
throw new Error("The CCR media artifact exceeds the inline preview size limit.");
}
chunks.push(Buffer.from(part.value));
}
if (!total) throw new Error("The CCR artifact response was empty.");
if (declaredLength && total !== declaredLength) throw new Error("The CCR artifact response length did not match its headers.");
const bytes = Buffer.concat(chunks, total);
const detectedMimeType = detectMediaMimeType(bytes);
if (!detectedMimeType || mediaKind(detectedMimeType) !== declaredKind) {
throw new Error("The CCR artifact content did not match its declared media type.");
}
return { bytes, mimeType: detectedMimeType };
}
function detectMediaMimeType(buffer: Buffer): string | undefined {
if (buffer.byteLength >= 8 && buffer.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) return "image/png";
if (buffer.byteLength >= 3 && buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) return "image/jpeg";
if (buffer.byteLength >= 12 && buffer.subarray(0, 4).toString("ascii") === "RIFF" && buffer.subarray(8, 12).toString("ascii") === "WEBP") return "image/webp";
if (buffer.byteLength >= 12 && buffer.subarray(4, 8).toString("ascii") === "ftyp") {
const brand = buffer.subarray(8, 12).toString("ascii");
if (["avif", "avis", "mif1", "msf1"].includes(brand)) return "image/avif";
return "video/mp4";
}
if (buffer.byteLength >= 4 && buffer.subarray(0, 4).equals(Buffer.from([0x1a, 0x45, 0xdf, 0xa3]))) return "video/webm";View on GitHub (pinned to 99f24806c6)
Solutions
- Compare curl's reported downloaded size against the response Content-Length to see which side is wrong
- If a proxy is altering the body, bypass it or make it pass responses through verbatim
- If truncation is network-related, retry the artifact fetch — transient truncation resolves on a stable connection
Defensive patterns
Strategy: retry
Type guard
function isLengthMismatchRejection(e: unknown): boolean {
return e instanceof Error && e.message.includes('length did not match');
} Try / catch
try {
const media = await bridge.artifact(ref);
} catch (e) {
if (isLengthMismatchRejection(e)) {
await sleep(500);
return bridge.artifact(ref); // truncated transfers are often transient
}
throw e;
} Prevention
- Avoid intermediaries that rewrite or decompress response bodies
- Retry once on length mismatches — truncation is frequently network-related
- If mismatches persist for one URL, treat that artifact as corrupt server-side
When it happens
Trigger: Connection dropped mid-transfer and the stream ended early; a proxy rewrote the body (e.g. injected content, or decompressed a response after Content-Length was computed for the compressed size); server sends an inaccurate Content-Length.
Common situations: Intermediaries modifying bodies (ad injection, TLS-terminating middleboxes), decompression proxies, flaky networks truncating responses, or servers with off-by-one/broken length computation.
Related errors
- The CCR media artifact exceeds the inline preview size limit
- Claude App profiles do not support agent arguments.
- The CCR artifact request failed.
- The CCR artifact endpoint returned a non-media content type.
- Compressed CCR media artifacts are not accepted for inline p
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/bd3fd8dc1c8eff79.
Report an issue: GitHub.