Skip to content

fix: stream LLM tokens for cloud conversations and profile switches - #15021

Merged
VascoSch92 merged 3 commits into
mainfrom
vasco/cloud-llm-streaming
Jun 30, 2026
Merged

VascoSch92 merged 3 commits into
mainfrom
vasco/cloud-llm-streaming

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Enable streaming in settings.

  • A human has tested these changes.

AGENT:

Evidence:

  • uv run pytest tests/unit/app_server/test_app_conversation_router.py tests/unit/app_server/test_live_status_app_conversation_service.py tests/unit/app_server/test_profiles_api.py → 203 passed, including the two extended happy-path assertions: the switch_profile endpoint sends stream: true to the agent-server's switch_llm, and _configure_llm returns llm.stream is True.
  • Pre-commit on commit ran the full backend suite (ruff, ruff format, mypy) → all passed. ruff@0.12.5 format --check and ruff check are clean on the changed files.
  • Not done here: a live deployed-app-server token-streaming check (needs a running sandbox); see the HUMAN checkbox.

Why

Cloud agent conversations never enabled LLM token streaming. The app-server resolves the agent LLM from the user's saved settings (_configure_llm) and from saved profiles (resolve_profile_llm), both of which default stream=False (the SDK LLM default). With stream=False the SDK never invokes the on_token callback, so no StreamingDeltaEvents are emitted and the UI receives whole messages at once. The GUI sets stream=True explicitly on the local start/switch paths, but the server-resolved cloud paths had no equivalent — so a cloud conversation (and any cloud profile switch) silently lost streaming.

Summary

  • _configure_llm (conversation start) now forces stream=True on the resolved agent LLM.
  • resolve_profile_llm (profile switch endpoint + the agent-server profile-store sync) now forces stream=True, so a switched-to profile keeps streaming.

Issue Number

N/A

How to Test

  • Unit: uv run pytest tests/unit/app_server/test_app_conversation_router.py tests/unit/app_server/test_live_status_app_conversation_service.py (203 pass).
  • Manual (needs a deployed app-server): start a cloud conversation and confirm assistant tokens render incrementally; switch the LLM profile mid-conversation (composer switcher or /model <name>) and confirm it keeps streaming.

Video/Screenshots

Not captured; live token-streaming verification is pending human testing against a deployed app-server.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Companion frontend PR: feat: support LLM profiles on cloud backends agent-canvas#1532 (surfaces cloud LLM profiles + chat-level switching, which is what exposed this streaming gap).
  • Scope: only the main agent LLM. The condenser LLM (agent.condenser.llm) and the ACP path (acp_settings.llm, which streams natively) are built separately and intentionally untouched.

To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   --name openhands-app-5fdd1b8   docker.openhands.dev/openhands/openhands:5fdd1b8

Cloud agent conversations never enabled LLM token streaming. The app-server builds the agent LLM from the user's saved settings (_configure_llm) and from saved profiles (resolve_profile_llm), both of which default stream=False (the SDK LLM default), so no StreamingDeltaEvents were emitted and the UI received whole messages at once. The GUI sets stream=True explicitly on the local start and switch paths; the server-resolved cloud paths had no equivalent.

Force stream=True in both resolvers so cloud conversations stream at start and stay streaming after a profile switch (resolve_profile_llm feeds the agent-server's switch_llm).
@VascoSch92
VascoSch92 force-pushed the vasco/cloud-llm-streaming branch from aea5a4f to bb7e727 Compare June 29, 2026 13:02
@VascoSch92
VascoSch92 marked this pull request as ready for review June 29, 2026 13:03
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/settings
  llm_profiles.py 62
Project Total  

This report was generated by python-coverage-comment-action

@hieptl hieptl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @VascoSch92,

Would you mind including a short demo video showing how streaming works for cloud conversations? It would be very helpful for reviewing the implementation.

Also, have you had a chance to test this feature when running the SaaS application locally or using a feature deployment?

Thank you very much! 🙏

The cloud-streaming fix makes the agent server emit StreamingDeltaEvents,
but the v1 frontend ignored them and only rendered whole messages. Render
those token deltas live:

- Add the StreamingDeltaEvent type, type guard, and event-union entry.
- Merge consecutive deltas into one growing bubble (skipping interleaved
  ConversationStateUpdateEvent metrics) and reconcile the final
  MessageEvent / FinishAction into it rather than appending a duplicate
  (ported from agent-canvas).
- Keep merged deltas in the event store so the chat's allEvents lookup
  resolves them (a delta missing from that list renders empty).
- Render the streamed answer as the assistant bubble and the streamed
  reasoning as a collapsible "Thinking" section, reusing GenericEventMessage
  (new EVENT$THINKING i18n key).
- Fix Messages memo: it only re-rendered on messages.length change, so a
  streaming bubble growing in place never repainted until the next event
  changed the length; fall back to the default shallow comparison.

Add reducer unit tests for delta merge, mid-stream metrics interleave,
final-message reconciliation, and the non-streamed path.
@VascoSch92

Copy link
Copy Markdown
Member Author
Screen.Recording.2026-06-30.at.11.24.04.mov

@VascoSch92

Copy link
Copy Markdown
Member Author

Hey,

to answer your comments: both problems are already fixed in the sdk (OpenHands/software-agent-sdk#3925 and OpenHands/software-agent-sdk#3901) but are not released yet.

We can also wait with this PR until the agent-server version is bumped.

@hieptl hieptl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙏

@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.9.0.

@openhands-release-bot openhands-release-bot Bot added the released: cloud-1.41.0 Shipped in cloud-1.41.0 label Jul 6, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in cloud-1.41.0.

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

Labels

released: cloud-1.41.0 Shipped in cloud-1.41.0 released: 1.9.0 Shipped in 1.9.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants