{"record":{"id":"7247c4811d01f103","repo":"odysseus-dev/odysseus","slug":"mlx-swift-bridge-completed-but-did-not-write-out","errorCode":null,"errorMessage":"MLX Swift bridge completed but did not write {out_path}","messagePattern":"MLX Swift bridge completed but did not write (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"scripts/mlx_image_server.py","lineNumber":410,"sourceCode":"    n: int = Form(1),\n    size: str = Form(\"1024x1024\"),\n    response_format: str = Form(\"b64_json\"),\n):\n    active_model = model or _args.model\n    if _is_lama_inpaint(active_model) or _is_ddcolor(active_model):\n        image_raw = await image.read()\n        mask_raw = await mask.read() if mask is not None else None\n        out_images = []\n        count = max(1, min(int(n or 1), 4))\n        for _ in range(count):\n            with tempfile.TemporaryDirectory(prefix=\"odysseus-mlx-edit-\") as td:\n                out_path = Path(td) / \"image.png\"\n                if _is_ddcolor(active_model):\n                    _run_ddcolor_bridge(active_model, image_raw, out_path)\n                else:\n                    _run_inpaint_bridge(active_model, image_raw, mask_raw, out_path)\n                if not out_path.exists():\n                    raise HTTPException(500, f\"MLX Swift bridge completed but did not write {out_path}\")\n                out_images.append({\"b64_json\": base64.b64encode(out_path.read_bytes()).decode(\"ascii\")})\n        return {\"created\": 0, \"data\": out_images}\n    raise HTTPException(\n        422,\n        \"This MLX image endpoint supports text-to-image generation only. \"\n        \"Use /v1/images/generations, or serve an edit/img2img-capable model.\",\n    )\n\n\n@app.post(\"/v1/images/harmonize\")\ndef harmonize_image(req: HarmonizeRequest):\n    active_model = _args.model\n    if _is_lama_inpaint(active_model) or _is_ddcolor(active_model):\n        try:\n            image_raw = base64.b64decode(req.image.split(\",\", 1)[-1])\n            mask_b64 = req.body_mask or req.mask\n            mask_raw = base64.b64decode(mask_b64.split(\",\", 1)[-1]) if mask_b64 else None\n        except Exception as e:","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/scripts/mlx_image_server.py#L392-L428","documentation":"Raised in /v1/images/edits of scripts/mlx_image_server.py with HTTP 500 when the MLX Swift bridge (DDColor colorize or LaMa/MI-GAN inpaint) exited successfully but did not create the promised out_path image.png in the per-request temp directory. It is the edits-path twin of error 956.","triggerScenarios":"A bridge call returns exit code 0 yet writes nothing or writes to another path: bridge version whose --output semantics changed, bridge succeeding on a dry-run/help invocation, sandboxed Swift process blocked from writing the temp dir.","commonSituations":"Upgraded odysseus-mlx-inpaint/mlx-lama-serve CLI where flags were renamed; temp dir under /var/folders hit by sandbox restrictions for signed binaries; out_path passed as a file:// URL vs plain path mismatch across versions.","solutions":["Run the bridge command manually with the same args in a kept directory and see where/whether it writes","Pin the bridge package to the version whose --output contract matches the server","Check the process can write to the temp dir (try a manual touch as the same user; inspect macOS sandbox/profile denial)","Reinstall the bridge if it silently no-ops (e.g. missing weights bundled at build time)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import shutil, subprocess, tempfile, pathlib\nbridge = shutil.which('odysseus-mlx-inpaint')\nwith tempfile.TemporaryDirectory() as td:\n    out = pathlib.Path(td) / 'o.png'\n    subprocess.run([bridge, '--model', w, '--image', i, '--mask', m, '--output', str(out), '--mode', 'inpaint'], check=True)\n    assert out.exists(), 'bridge output contract broken'","typeGuard":null,"tryCatchPattern":"except HTTPException as e:\n    if 'did not write' in str(e.detail):\n        out_path = rerun_bridge_with_kept_dir_and_locate()  # fallback: capture actual write location\n    else:\n        raise","preventionTips":["Contract-test each bridge version after upgrade","Run the bridge in a kept directory once to learn its real output layout","Pin bridge package versions alongside the server"],"tags":["mlx","swift","subprocess","contract","http-500"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}