Skip to content

Profile-launched conversations never enable LLM streaming — on_token crash on switch_llm #4014

Closed

Description

@simonrosenberg

Summary

A conversation started from an AgentProfile (agent_profile_id) instead of an inline agent_settings payload never gets LLM token streaming wired up — and a later switch_llm call that assumes streaming is already enabled (a legitimate, pre-existing behavior on the agent_settings path) crashes the run with:

ValueError: Streaming requires an on_token callback

This is the same profile-launch path exercised by agent-canvas#1571, and the same category of gap as #3967 (exec tools / public skills silently dropped on agent_profile_id launches) — this time for streaming.

Root cause (traced)

  • LocalConversation.__init__ decides once, at conversation construction, whether to wire the on_token streaming callback, via streaming_enabled = isinstance(agent, ACPAgent) or any(llm.stream for llm in agent.get_all_llms()) (openhands-agent-server/openhands/agent_server/event_service.py). This is never re-evaluated afterward — confirmed by reading LocalConversation.switch_llm (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py): it swaps self.agent's LLM via model_copy(update={"llm": new_llm, ...}) but never touches self._on_token.
  • On the legacy agent_settings path, a consuming client can force stream=True on the inline LLM config it sends at conversation-start (agent-canvas does this — see below), so streaming_enabled is correctly True from construction.
  • On the agent_profile_id path, _build_openhands_settings (openhands-sdk/openhands/sdk/profiles/resolver.py) does "llm": llm — the loaded LLM profile object as-is, with no forced stream=True override. So streaming_enabled depends entirely on whatever stream value happens to be persisted on the referenced LLM profile (SDK default: False).
  • Consequence: any profile-launched conversation whose LLM profile was never explicitly saved with stream: true gets on_token=None for its entire lifetime. The first turn's completion is fine (no streaming requested), but a client that later calls switch_llm with stream: true (assuming parity with how conversation-start behaves) crashes the very next completion, since on_token can never be (re-)wired post-construction.

Confirmed via real agent-server tracebacks in agent-canvas#1571's CI (both mock-llm-e2e and mock-llm-docker-e2e), reproducing on both a /model slash-command switch and, intermittently under Docker, on a preset-automation dispatch.

Why this is an SDK-level gap, not just a client bug

The asymmetry is structural: _build_openhands_settings never gives OpenHands profile resolution a way to guarantee stream=True the way an agent_settings-launching client can. Every consumer of agent_profile_id (agent-canvas, the cloud app-server, eval) inherits this gap identically, since all three build the agent purely from the stored profile fields.

Proposed fix

  • _build_openhands_settings (or resolve_agent_profile) should force llm.stream = True on the resolved LLM for OpenHands profiles, mirroring what agent_settings-launching clients already do at their end — closing the asymmetry at the source rather than leaving every consumer to work around it independently.
  • Longer-term/more robust: consider making streaming_enabled/on_token wiring re-evaluated per-call (or at least per switch_llm) rather than frozen at LocalConversation.__init__, and/or have acompletion/aresponses gracefully downgrade to non-streaming instead of hard-raising when stream=True is requested but no on_token is wired — a silent capability mismatch shouldn't crash the whole run.

Current workaround (agent-canvas)

agent-canvas#1571 works around this client-side only, since streaming (PR agent-canvas#1474) is a pre-existing, independently-shipped feature that must not regress — ruling out simply dropping the switch_llm stream:true call (would silently disable streaming-after-switch for the legacy path, which works today), and since existing users' LLM profiles predate any fix, a "default at next profile-save" approach alone would still crash on their first profile-launched conversation post-deploy.

The workaround (ensureLlmProfileStreams in src/hooks/mutation/use-create-conversation.ts, commit 65a429f8) self-heals the referenced LLM profile's persisted stream field to true the first time it's used to launch a profile conversation — the one call site guaranteed to run for every agent_profile_id launch (already fetching the LLM-profiles list to validate llm_profile_ref exists). It's explicitly a migration shim, safe to delete once this issue's root fix ships upstream (regardless of individual user migration state at that point).

Context / tracking

Activity

  1. added
    bug
    on Jul 7, 2026
  2. simonrosenberg commented on Jul 7, 2026

    @simonrosenberg
    MemberAuthor

    Consolidated into #4017 — this is one of four faces of the same root cause (the profile resolver builds a minimal agent from scratch and drops the defaults the agent_settings path sets). #4017 proposes fixing the class (defaults-then-override, mirroring how #3968 already fixed the tools face) rather than patching streaming in isolation. Keeping this open for the streaming-specific detail (the on_token wiring frozen at LocalConversation construction); the resolver stream=True default lives in #4017.

  3. simonrosenberg commented on Jul 10, 2026

    @simonrosenberg
    MemberAuthor

    Fixed by #4018 (merged as 1877912, released in SDK v1.33.0). Profile launches now force streaming at the agent-server layer, and LLM completion gracefully degrades when no on_token callback is present. Agent Canvas currently pins agent-server 1.33.0 and no longer contains ensureLlmProfileStreams.

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