{"record":{"id":"92153caf814a6241","repo":"BoundaryML/baml","slug":"baml-internal-error-stream-did-not-complete-successfully","errorCode":null,"errorMessage":"BAML Internal error: Stream did not complete successfully. Please report this issue.","messagePattern":"BAML Internal error: Stream did not complete successfully\\. Please report this issue\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"engine/language_client_python/python_src/baml_py/stream.py","lineNumber":221,"sourceCode":"\n                if done_seen:\n                    break\n        except Exception as e:\n            raise e\n        finally:\n            if self.__task and self.__task.is_alive():\n                self.__task.join(timeout=5.0)\n\n    def get_final_response(self):\n        self.__drive_to_completion_in_bg()\n        if self.__task is not None:\n            self.__task.join()\n\n        if self.__exception is not None:\n            raise self.__exception\n\n        if self.__result is None:\n            raise Exception(\n                \"BAML Internal error: Stream did not complete successfully. Please report this issue.\"\n            )\n\n        return self.__final_coerce(self.__result)\n","sourceCodeStart":203,"sourceCodeEnd":226,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_python/python_src/baml_py/stream.py#L203-L226","documentation":"baml_py.stream.get_final_response() raises this generic Exception when a streamed BAML call ends without an exception but also without a result, meaning the stream's internal state machine finished in a neither-success-nor-failure state. The library considers this impossible under normal operation and asks for a bug report.","triggerScenarios":"Calling stream.get_final_response() after joining the streaming task when self.__result is None and self.__exception is None — e.g. the async streaming task ended without invoking either the result or error callback.","commonSituations":"Killed or cancelled stream tasks mid-flight (process interrupts, event-loop shutdown) that bypass both callbacks; engine/FFI bugs in rare partial-response paths; forcing final response on a stream that never started consuming.","solutions":["Check server/network conditions: retry the request, since a dropped stream can leave no result and no exception.","Guard with streaming callbacks to ensure the stream is fully consumed before calling get_final_response().","Upgrade baml-py and the BAML CLI to the latest versions — this state may be a fixed engine bug.","If reproducible on latest versions, report it (the message explicitly asks for a bug report) with a minimal repro."],"exampleFix":"# before\nstream = b.MyFunc.stream(prompt)\nresult = stream.get_final_response()  # may hit internal error on abrupt stream end\n\n# after\nstream = b.MyFunc.stream(prompt)\nfor partial in stream:\n    pass  # fully consume the stream\ntry:\n    result = stream.get_final_response()\nexcept Exception as e:\n    result = fallback_completion(prompt)","handlingStrategy":"try-catch","validationCode":"if not stream.has_pending_items() and stream.get_final_response_cache() is None:\n    # stream never produced output; re-issue instead of forcing final response\n    stream = client.call.stream(...)","typeGuard":"def stream_completed(stream) -> bool:\n    try:\n        stream.get_final_response()\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    result = stream.get_final_response()\nexcept Exception as e:\n    if \"Stream did not complete successfully\" in str(e):\n        result = retry_stream(client, prompt)  # re-issue the request\n    else:\n        raise","preventionTips":["Fully consume the stream before calling get_final_response()","Avoid cancelling the event loop / process mid-stream","Retry transiently failed streams rather than forcing a final response","Keep baml-py and the engine up to date; report reproducible cases"],"tags":["python","streaming","internal-error","async"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}