{"record":{"id":"063d4435b64de5f1","repo":"odysseus-dev/odysseus","slug":"detail-4000","errorCode":null,"errorMessage":"detail[-4000:]","messagePattern":"detail\\[-4000:\\]","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"scripts/mlx_image_server.py","lineNumber":211,"sourceCode":"        img = Image.open(io.BytesIO(raw))\n        if img.mode == \"RGBA\":\n            # OpenAI edits mask convention: transparent = regenerate.\n            alpha = img.getchannel(\"A\")\n            mask = alpha.point(lambda p: 255 if p < 128 else 0)\n        else:\n            mask = img.convert(\"L\")\n        mask.save(out_path, format=\"PNG\")\n    except Exception as e:\n        raise HTTPException(400, f\"Invalid mask image: {e}\") from e\n\n\ndef _run_bridge(cmd: list[str]) -> None:\n    env = os.environ.copy()\n    proc = subprocess.run(cmd, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n    if proc.returncode != 0:\n        detail = (proc.stderr or proc.stdout or \"MLX Swift bridge failed\").strip()\n        logger.error(\"MLX Swift bridge failed (%s): %s\\n%s\", proc.returncode, \" \".join(cmd), detail[-4000:])\n        raise HTTPException(500, detail[-4000:])\n\n\ndef _run_ddcolor_bridge(model: str, image_raw: bytes, out_path: Path) -> None:\n    bridge = _resolve_bridge([\"odysseus-mlx-colorize\", \"mlx-ddcolor-serve\"])\n    if not bridge:\n        raise _unsupported_swift_mlx_runtime(model)\n    with tempfile.TemporaryDirectory(prefix=\"odysseus-ddcolor-\") as td:\n        inp = Path(td) / \"input.png\"\n        _write_bridge_input_image(image_raw, inp)\n        weights = _weights_path(model)\n        tier = \"tiny\" if \"tiny\" in model.lower() else \"large\"\n        _run_bridge([\n            bridge,\n            \"--model\", str(weights),\n            \"--image\", str(inp),\n            \"--output\", str(out_path),\n            \"--tier\", tier,\n        ])","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/scripts/mlx_image_server.py#L193-L229","documentation":"This is not a fixed message: _run_bridge raises HTTPException(500, detail[-4000:]) when the MLX Swift bridge subprocess (odysseus-mlx-inpaint / mlx-lama-serve / odysseus-mlx-colorize / mlx-ddcolor-serve) exits non-zero. The detail is the last 4000 chars of the bridge's stderr (or stdout), also logged server-side, so the visible text is the underlying Swift/MLX failure.","triggerScenarios":"Any /v1/images/edits or /v1/images/harmonize call on LaMa/MI-GAN/DDColor models where the bridge process fails: missing weights, out-of-memory, incompatible Swift toolchain, bad weights path, or unsupported image dimensions.","commonSituations":"First run before model weights are downloaded; macOS or Xcode/Swift version mismatch for the MLX Swift package; large input image exhausting unified memory; passing a safetensors file the bridge doesn't support; bridge binary half-installed after a partial pip/brew install.","solutions":["Read the embedded stderr tail (and server log line 'MLX Swift bridge failed') to identify the real cause","Re-run with a smaller image (resize to e.g. 1024px max) if the tail shows a memory error","Verify the bridge executable runs standalone with --help, and reinstall the MLX Swift package if it doesn't","Ensure model weights resolved correctly (see errors 941/942) and are compatible with the bridge tier"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import shutil\nbridge = shutil.which('odysseus-mlx-inpaint') or shutil.which('mlx-lama-serve')\nassert bridge, 'MLX Swift bridge not installed'","typeGuard":null,"tryCatchPattern":"except HTTPException as e:\n    tail = e.detail[-500:]\n    if 'out of memory' in tail.lower():\n        shrink_image_to(1024); retry_once()\n    else:\n        surface_bridge_stderr(tail)","preventionTips":["Run the bridge standalone on a sample image before wiring clients","Cap input image dimensions client-side","Log the full bridge command on failure for reproducibility"],"tags":["mlx","swift","subprocess","http-500","inpainting"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}