{"record":{"id":"40558435b6f160ea","repo":"headroomlabs-ai/headroom","slug":"magika-session-init-failed-0","errorCode":null,"errorMessage":"magika session init failed: {0}","messagePattern":"magika session init failed: (.+?)","errorType":"exception","errorClass":"MagikaDetectorError","httpStatus":null,"severity":"error","filePath":"crates/headroom-core/src/transforms/magika_detector.rs","lineNumber":311,"sourceCode":"fn dedup_existing_files(paths: Vec<PathBuf>) -> Vec<PathBuf> {\n    let mut out = Vec::new();\n    for path in paths {\n        if path.is_file() && !out.iter().any(|seen| seen == &path) {\n            out.push(path);\n        }\n    }\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`].","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/crates/headroom-core/src/transforms/magika_detector.rs#L293-L329","documentation":"Brotli is installed but brotli.decompress() raised — the body is not a valid brotli stream (helpers.py:2436). Usually caused by mislabeled, truncated, or double-encoded payloads.","triggerScenarios":"Body labeled 'br' that is actually gzip/plain; an upload cut mid-stream so the brotli frame is incomplete; an intermediary rewriting the body without updating Content-Encoding.","commonSituations":"Header/body mismatches from gateways; client bugs compressing twice; flaky connections producing partial bodies under load.","solutions":["Check the body standalone: python -c \"import brotli; brotli.decompress(open('body.bin','rb').read())\"","Ensure the client compresses exactly once with brotli.compress() and sets Content-Encoding: br only then","Fix any fronting proxy that alters bodies but forwards stale encoding headers"],"exampleFix":"# before\nrequests.post(url, data=plain_payload, headers={\"Content-Encoding\": \"br\"})\n\n# after\nrequests.post(url, data=brotli.compress(plain_payload), headers={\"Content-Encoding\": \"br\"})","handlingStrategy":"try-catch","validationCode":"import brotli\nbrotli.decompress(compressed_body)  # raises before send if invalid","typeGuard":null,"tryCatchPattern":"try:\n    body = await _read_request_body_bytes(request)\nexcept ValueError as exc:\n    return JSONResponse({\"error\": {\"message\": str(exc)}}, status_code=400)","preventionTips":["Round-trip check compressed payloads in tests","Keep compression and header assignment in one helper"],"tags":["compression","brotli","corrupt-body","request-body"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}