{"record":{"id":"17d38586baec8080","repo":"headroomlabs-ai/headroom","slug":"magika-inference-failed-0","errorCode":null,"errorMessage":"magika inference failed: {0}","messagePattern":"magika inference failed: (.+?)","errorType":"exception","errorClass":"MagikaDetectorError","httpStatus":null,"severity":"error","filePath":"crates/headroom-core/src/transforms/magika_detector.rs","lineNumber":317,"sourceCode":"    }\n    out\n}\n\n/// Errors from the magika detector. Wraps the underlying `magika::Error`\n/// so callers can match on whether init or inference broke without\n/// pulling magika types into their imports.\n#[derive(Debug, Error)]\npub enum MagikaDetectorError {\n    /// One-time session initialization failed (model load, ONNX init).\n    /// Once we hit this, every subsequent call also fails — there is no\n    /// retry path here. The router should surface and stop.\n    #[error(\"magika session init failed: {0}\")]\n    Init(String),\n\n    /// Inference call failed for this input. Usually transient; future\n    /// calls may succeed. The error message is the magika-side text;\n    /// we don't try to wrap it.\n    #[error(\"magika inference failed: {0}\")]\n    Inference(String),\n\n    /// Singleton lock was poisoned (a previous holder panicked while\n    /// holding it). The detector is unusable until the process\n    /// restarts. We don't auto-recover — a panicked detector means\n    /// something is corrupt and continuing would mask it.\n    #[error(\"magika session lock poisoned\")]\n    Poisoned,\n}\n\n/// One-process singleton holding the magika session. Lazily\n/// initialized on first call to [`magika_detect`].\n///\n/// `Mutex<Result<Session, ...>>` rather than `Result<Mutex<Session>>`\n/// so init failure is recorded once and replayed cheaply on every\n/// subsequent call (no re-attempting the load — if the model file is\n/// missing or ort can't init, retrying just wastes cycles).\nstatic MAGIKA_SESSION: OnceLock<Mutex<Result<Session, String>>> = OnceLock::new();","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/crates/headroom-core/src/transforms/magika_detector.rs#L299-L335","documentation":"The request carries a Content-Encoding value other than the supported set (zstd/zstandard, gzip, deflate, br, identity), so headroom refuses to guess how to decode it (helpers.py:2438). Anything non-empty that is not 'identity' hits this branch, including compound values like 'gzip, br'.","triggerScenarios":"Sending 'Content-Encoding: gzip, br', 'Content-Encoding: compress', a vendor-specific token, or a value with different casing/spacing that fails the exact string match (the code lowercases/strips, so 'GZIP' works but 'gzip;br' does not).","commonSituations":"Clients that apply layered compression and join encodings with commas; copy-pasted headers from responses into requests; future/new encodings like zstd variants before headroom supports them.","solutions":["Send a single supported encoding: identity, gzip, deflate, br, or zstd","If you need layered compression, decompress on your side and send one encoding","Omit Content-Encoding entirely for plain JSON bodies"],"exampleFix":"# before\nheaders = {\"Content-Encoding\": \"gzip, br\"}\n\n# after\nheaders = {\"Content-Encoding\": \"gzip\"}","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"\", \"identity\", \"gzip\", \"deflate\", \"br\", \"zstd\", \"zstandard\"}\nenc = request.headers.get(\"content-encoding\", \"\").lower().strip()\nif enc not in SUPPORTED:\n    return JSONResponse({\"error\": f\"Unsupported Content-Encoding: {enc}\"}, status_code=400)","typeGuard":null,"tryCatchPattern":"try:\n    body = await _read_request_body_bytes(request)\nexcept ValueError as exc:\n    return JSONResponse({\"error\": str(exc)}, status_code=400)","preventionTips":["Never join multiple encodings with commas in a request header","Centralize Content-Encoding handling in your HTTP client layer"],"tags":["compression","content-encoding","request-body","headers"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}