Skip to content

fix: OCI streaming hangs indefinitely — OCI does not send SSE [DONE] marker #756

@fede-kamel

Description

@fede-kamel

Bug

OciClient.chat_stream() and OciClientV2.chat_stream() hang indefinitely after receiving all content from the OCI Generative AI service. The stream never terminates.

Root Cause

The OCI Generative AI SSE endpoint does not send a data: [DONE] marker to signal end-of-stream. Instead, it sends a final event containing finishReason and then keeps the HTTP connection open. The SDK's stream wrapper (transform_oci_stream_wrapper) relies on data: [DONE] to emit closing events (message-end for V2, stream-end for V1) and terminate the generator. Since [DONE] never arrives, the generator blocks forever on the next chunk read.

Raw OCI stream behavior:

data: {"apiFormat":"COHEREV2","message":{"role":"ASSISTANT","content":[{"type":"TEXT","text":"Hi"}]}}
data: {"apiFormat":"COHEREV2","message":{"role":"ASSISTANT","content":[{"type":"TEXT","text":"!"}]}}
data: {"apiFormat":"COHEREV2","message":{"role":"ASSISTANT"},"finishReason":"COMPLETE"}
... connection stays open indefinitely, no [DONE] ...

Impact

  • Both V1 (OciClient) and V2 (OciClientV2) streaming are affected
  • chat_stream() calls never return
  • All OCI regions affected (tested on us-chicago-1)

Fix

When finishReason is present in an OCI event, emit closing events and return from the generator immediately, instead of waiting for [DONE]. The [DONE] path is preserved as a fallback for forward compatibility.

PR: (will link)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions