{"record":{"id":"d47f153c4d1db96e","repo":"langflow-ai/langflow","slug":"flow-creation-failed","errorCode":null,"errorMessage":"Flow creation failed.","messagePattern":"Flow creation failed\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/agentic/utils/assistant_runner.py","lineNumber":61,"sourceCode":"        if flow is None or (flow.user_id is not None and str(flow.user_id) != str(user_id)):\n            raise HTTPException(status_code=404, detail=\"Flow not found.\")\n        return flow, False\n\n    folder = await get_or_create_default_folder(session, user_id)\n    new_flow = FlowCreate(\n        name=DEFAULT_FLOW_NAME,\n        description=\"Created by the Langflow Assistant via MCP\",\n        data={\"nodes\": [], \"edges\": []},\n        folder_id=folder.id,\n        user_id=user_id,\n    )\n    storage_service = get_storage_service()\n    created = await _new_flow(session=session, flow=new_flow, user_id=user_id, storage_service=storage_service)\n    await session.commit()\n    # _new_flow returns a FlowRead; re-fetch the ORM row so later edits persist.\n    db_flow = await session.get(Flow, created.id)\n    if db_flow is None:\n        raise HTTPException(status_code=500, detail=\"Flow creation failed.\")\n    return db_flow, True\n\n\nclass _CanvasState:\n    \"\"\"Fallback event replay for headless runs when no working-flow snapshot exists.\n\n    Handles ``set_flow`` / ``add_component`` / ``connect``. The authoritative\n    source is the server-side working flow (it captures configure/remove/\n    tool-mode/select-output too); this replay only runs when that snapshot is\n    unavailable. ``changed`` flips on ANY ``flow_update`` so persistence is\n    gated on \"the agent mutated the canvas\", not on the subset replayed here.\n    \"\"\"\n\n    def __init__(self, initial_data: dict[str, Any] | None) -> None:\n        self.data: dict[str, Any] = copy.deepcopy(initial_data) if initial_data else {}\n        self.data.setdefault(\"nodes\", [])\n        self.data.setdefault(\"edges\", [])\n        self.name: str | None = None","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/utils/assistant_runner.py#L43-L79","documentation":"Raised when _new_flow successfully created a Flow and the session committed, but an immediate session.get(Flow, created.id) returned None. This indicates an inconsistency inside the same session/transaction (e.g. the commit silently rolled back, a flush issue, or a DB isolation anomaly), not user error. The 500 reflects that the just-created row vanished.","triggerScenarios":"Race where another process deletes the row between commit and re-fetch; a session whose commit was vetoed by a listener/extension; exotic SQLite/database locking behavior under concurrency.","commonSituations":"Very rare — effectively a backend invariant violation; most often seen with custom SQLAlchemy session instrumentation or aggressive concurrent cleanup jobs.","solutions":["Retry the assistant call — a transient isolation anomaly usually does not recur.","Inspect backend logs around the commit for warnings from SQLAlchemy event listeners or the storage service.","If reproducible, check for a database trigger or after-commit hook deleting new flows."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await run_assistant(...)\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Flow creation failed\" in e.response.text:\n        result = await run_assistant(...)  # one retry; invariant break is typically transient\n    else:\n        raise","preventionTips":["Treat this as a backend anomaly — capture server logs at the moment it occurs.","Avoid custom SQLAlchemy session listeners that veto commits for Flow inserts."],"tags":["database","invariant","assistant","http-500"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}