Skip to content

Laminar litellm instrumentation breaks streaming: acompletion(stream=True) returns async_generator, failing assert in _atransport_call #3972

Closed

Description

@aivong-openhands

Summary

When Laminar observability is active (LMNR_PROJECT_API_KEY set), every streaming LLM call fails with a bare AssertionError at openhands/sdk/llm/llm.py:2065 (_atransport_call), which surfaces as ConversationRunError on the first agent step. This is deterministic, affects all models, and — because the app server now forces stream: true for cloud conversations (OpenHands/OpenHands#15021) — it fails 100% of conversations on any Laminar-instrumented deployment.

Root cause

lmnr's litellm instrumentation replaces the return value of litellm.acompletion(stream=True). When the wrapped call returns a coroutine, lmnr returns its own process_streaming_coroutine() async generator instead of litellm's CustomStreamWrapper:

# lmnr/opentelemetry_lib/opentelemetry/instrumentation/litellm/wrappers/__init__.py (lmnr 0.7.49)
if kwargs.get("stream"):
    # For streaming, we need to return an async generator function
    # that awaits the coroutine and then delegates to the streaming processor
    async def process_streaming_coroutine():
        ...

(The same file even contains the comment # This will likely cause issues but matches the original behavior.)

The SDK's streaming path then asserts litellm's concrete type and dies:

# openhands-sdk/openhands/sdk/llm/llm.py:2056-2065 (v1.30.0)
ret = await litellm_acompletion(...)
if enable_streaming and on_token is not None:
    assert isinstance(ret, CustomStreamWrapper)   # <- AssertionError: ret is an async_generator

Note this is not a new lmnr regression sneaking past the lmnr>=0.7.47,<0.7.53 pin from #3662 — the behavior exists in lmnr 0.7.49, inside the pin. The path was simply never exercised until streaming was turned on by default for cloud conversations. The same assert exists in v1.29.0 (llm.py:1965), so all released versions are affected once stream=True is used with Laminar active.

Minimal repro

In any environment with openhands-sdk (observed with SDK 1.30.0, litellm 1.84.1, lmnr 0.7.49):

import os
os.environ["LMNR_PROJECT_API_KEY"] = "<any value - instrumentation activates on presence>"
import openhands.sdk   # initializes Laminar instrumentation
import litellm

ret = await litellm.acompletion(model=..., messages=[...], stream=True)
print(type(ret))       # <class 'async_generator'>  -> SDK assert fails

Without importing openhands.sdk (or with LMNR_PROJECT_API_KEY unset), the same call returns litellm.CustomStreamWrapper and the SDK streaming path works.

Verified end-to-end A/B on two otherwise identical deployments (same agent-server 1.30.0-python, same app image, same model/proxy): the one with LMNR_* env set fails every conversation with the traceback below; the one without works.

Traceback

Traceback (most recent call last):
  File "openhands/sdk/conversation/impl/local_conversation.py", line 1841, in arun
  File "openhands/sdk/observability/laminar.py", line 178, in async_wrapper
  File "lmnr/opentelemetry_lib/decorators/__init__.py", line 385, in wrap
  File "openhands/sdk/agent/agent.py", line 827, in astep
  File "openhands/sdk/agent/utils.py", line 708, in amake_llm_completion
  File "openhands/sdk/llm/llm.py", line 1544, in acompletion
  File "openhands/sdk/llm/llm.py", line 1523, in acompletion
  File "tenacity/asyncio/__init__.py", ... (retry wrapper)
  File "openhands/sdk/llm/llm.py", line 1507, in _one_attempt
  File "openhands/sdk/llm/llm.py", line 2065, in _atransport_call
AssertionError

The above exception was the direct cause of the following exception:
  ...
openhands.sdk.conversation.exceptions.ConversationRunError: Conversation run failed for id=<conversation>

Suggested fix

One (or more) of:

  1. Make _atransport_call / _transport_call tolerate the lmnr-wrapped stream — accept any async iterable of ModelResponseStream chunks instead of asserting CustomStreamWrapper (the chunks themselves pass through unchanged; only the container type differs).
  2. Exclude litellm from lmnr's instrumentation set in openhands/sdk/observability/laminar.py — the SDK already has its own telemetry around the transport call, and lmnr's litellm wrapper is what breaks the contract.
  3. Fix upstream in lmnr so the instrumentation preserves litellm's return type for streaming calls (worth filing there too, but the SDK needs a defense regardless since the pin range already contains the broken behavior).

This issue was drafted by an AI agent on behalf of the user.

Activity

  1. added
    bug
    on Jul 2, 2026
  2. all-hands-bot commented on Jul 5, 2026

    @all-hands-bot
    Collaborator

    [Automatic Post]: This issue has been waiting for triage. @xingyaoww @neubig @enyst, could you
    please take a look and add the appropriate priority label when you have a chance?

    This comment was posted by an AI agent (OpenHands) on behalf of the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions