{"record":{"id":"9a16edaa2e6ca73a","repo":"langflow-ai/langflow","slug":"failed-to-write-flow-to-filesystem-e","errorCode":null,"errorMessage":"Failed to write flow to filesystem: {e}","messagePattern":"Failed to write flow to filesystem: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/v1/flows_helpers.py","lineNumber":195,"sourceCode":"        if not await safe_path.exists():\n            await safe_path.touch()\n\n\nasync def _save_flow_to_fs(flow: Flow, user_id: UUID, storage_service: StorageService) -> None:\n    \"\"\"Save flow data to the filesystem at the validated path.\"\"\"\n    if not flow.fs_path:\n        return\n\n    try:\n        safe_path = _get_safe_flow_path(flow.fs_path, user_id, storage_service)\n        await safe_path.parent.mkdir(parents=True, exist_ok=True)\n        async with aiofiles.open(str(safe_path), \"w\") as f:\n            await f.write(flow.model_dump_json())\n    except HTTPException:\n        raise\n    except OSError as e:\n        await logger.aexception(\"Failed to write flow %s to path %s\", flow.name, flow.fs_path)\n        raise HTTPException(status_code=500, detail=f\"Failed to write flow to filesystem: {e}\") from e\n\n\nasync def _deduplicate_flow_name(session: AsyncSession, name: str, user_id: UUID) -> str:\n    \"\"\"Return a unique flow name for *user_id*, appending ``(N)`` if needed.\"\"\"\n    if not (await session.exec(select(Flow).where(Flow.name == name).where(Flow.user_id == user_id))).first():\n        return name\n\n    flows = (\n        await session.exec(\n            select(Flow).where(Flow.name.like(f\"{name} (%\")).where(Flow.user_id == user_id)  # type: ignore[attr-defined]\n        )\n    ).all()\n\n    # Extract copy-number suffixes: \"MyFlow (2)\" → 2\n    extract_number = re.compile(rf\"^{re.escape(name)} \\((\\d+)\\)$\")\n    numbers = [int(m.group(1)) for f in flows if (m := extract_number.search(f.name))]\n\n    return f\"{name} ({max(numbers) + 1})\" if numbers else f\"{name} (1)\"","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/flows_helpers.py#L177-L213","documentation":"HTTP 500 from _save_flow_to_fs: an OSError occurred while writing the flow JSON to the validated filesystem path (mkdir of parents, aiofiles.open for write, or the write itself). The original HTTPExceptions from path validation are re-raised untouched; this branch is purely I/O failure after validation passed, and the exception is logged with the flow name and path via logger.aexception.","triggerScenarios":"Flow create/update with a valid fs_path where the server cannot write: disk full, permission denied on <data_dir>/flows/<user_id>, directory replaced by a read-only mount, or the file is a directory at that name.","commonSituations":"Docker container where the data volume is read-only or owned by a different uid; disk exhaustion; SELinux/AppArmor denying writes; an existing directory named exactly like the target .json file.","solutions":["Check disk space (df -h) and permissions on <data_dir>/flows/<user_id> for the backend user.","In containers, ensure the mounted volume is writable by the container user (chown/chmod or runAsUser match).","Remove any directory that collides with the target filename.","Read the server log: the aexception line names the flow and fs_path that failed."],"exampleFix":"# before: read-only volume\ndocker run -v /srv/flows:/data/flows:ro ...\n# after\ndocker run -v /srv/flows:/data/flows:rw ...","handlingStrategy":"fallback","validationCode":"# pre-flight on the server\nimport os; d = f\"{DATA_DIR}/flows/{user_id}\"; assert os.access(d, os.W_OK), 'flows dir not writable'","typeGuard":null,"tryCatchPattern":"try { await saveFlow(body) } catch (e) { if (e.status === 500 && 'filesystem' in e.detail) { alertOpsDisk(); body = {...body, fs_path: null}; return await saveFlow(body); } throw e; }","preventionTips":["Monitor disk space and volume writability in containers","Ensure uid/gid match on mounted volumes","Read the aexception log line for flow name and path"],"tags":["filesystem","io","http-500","fs-path","permissions"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}