{"record":{"id":"3510323e4359d9ea","repo":"langflow-ai/langflow","slug":"unexpected-error-exc-s","errorCode":null,"errorMessage":"Unexpected error: {exc!s}","messagePattern":"Unexpected error: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/build.py","lineNumber":327,"sourceCode":"\n            # Return as NDJSON format - each line is a complete JSON object\n            content = \"\\n\".join([event for event in events if event is not None])\n            return Response(content=content, media_type=\"application/x-ndjson\")\n        except asyncio.CancelledError as exc:\n            await logger.ainfo(f\"Event polling was cancelled for job {job_id}\")\n            raise HTTPException(status_code=499, detail=\"Event polling was cancelled\") from exc\n        except asyncio.TimeoutError:\n            await logger.awarning(f\"Timeout while waiting for events for job {job_id}\")\n            return Response(content=\"\", media_type=\"application/x-ndjson\")  # Return empty response instead of error\n\n    except JobQueueNotFoundError as exc:\n        await logger.aerror(f\"Job not found: {job_id}. Error: {exc!s}\")\n        raise HTTPException(status_code=404, detail=f\"Job not found: {exc!s}\") from exc\n    except Exception as exc:\n        if isinstance(exc, HTTPException):\n            raise\n        await logger.aexception(f\"Unexpected error processing flow events for job {job_id}\")\n        raise HTTPException(status_code=500, detail=f\"Unexpected error: {exc!s}\") from exc\n\n\nasync def create_flow_response(\n    queue: asyncio.Queue,\n    event_manager: EventManager,\n    event_task: asyncio.Task | None,\n    *,\n    queue_service: JobQueueService | None = None,\n    job_id: str | None = None,\n) -> DisconnectHandlerStreamingResponse:\n    \"\"\"Create a streaming response for the flow build process.\n\n    When *queue_service* and *job_id* are provided and the service exposes a\n    ``signal_cancel`` method (RedisJobQueueService with cancel_channel_enabled),\n    a client disconnect on a non-owner worker (``event_task is None``) publishes\n    a cross-worker cancel so the producer worker stops emitting events promptly\n    instead of running the build to natural completion.\n    \"\"\"","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/build.py#L309-L345","documentation":"Final catch-all in the flow-events handler: any exception other than JobQueueNotFoundError and non-HTTPException types is logged with aexception and re-raised as 500 'Unexpected error: {exc!s}'. HTTPExceptions raised inside the inner try are re-raised untouched (explicit isinstance check).","triggerScenarios":"Failures while consuming the event stream: queue decode errors (value.decode('utf-8') on corrupt data), event_manager callback exceptions, asyncio primitives misbehaving, or bugs in delivery-mode-specific branches.","commonSituations":"Corrupt queue payloads after a version upgrade changed the event schema; bugs in custom event-manager extensions; Redis returning unexpected types.","solutions":["Read the aexception traceback in the logs — the detail string alone rarely identifies the failing branch.","If it recurs after an upgrade, clear old job/event keys in Redis so stale-schema events are not replayed.","Report with the traceback if the failure is inside Langflow's own event pipeline."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    events = await get_flow_events(job_id)\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Unexpected error\" in e.response.text:\n        capture_server_logs(job_id)  # aexception logged the real traceback server-side\n        raise\n    raise","preventionTips":["Correlate client-side 500s with server aexception logs via job_id before debugging client code.","Flush old Redis event keys after upgrading Langflow to avoid decoding stale-schema events.","Report recurring occurrences with the full traceback — this path indicates an internal bug."],"tags":["http-500","catch-all","event-stream","build"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}