Repository navigation
fix(sdk): deliver streamed deltas to RemoteConversation token_callbacks - #5965
Conversation
Conversation(token_callbacks=[...]) with a RemoteWorkspace forwarded the callbacks to RemoteConversation, which swallowed them in **_. Hand each StreamingDeltaEvent frame from the events socket to the token callbacks as an LLMStreamChunk, and drop the map's known-bug marker for F33.conversation-token-callbacks. Fixes #5959 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed at head bc379ab41c0254ad70e9a3582e2e7cf52bedd937 (unchanged from the review request).
Scope. This belongs in this repository: it fixes the SDK's RemoteConversation (the factory path that Conversation(agent=..., workspace=RemoteWorkspace(...)) uses), inside the Python SDK's conversation layer. No cross-repo move or product decision is needed.
What I verified on the current head.
- The bug and the fix are consistent with the code:
Conversation(...)already forwardstoken_callbacks(factory line ~200), andRemoteConversation.__init__previously swallowed it in**_. The head now acceptstoken_callbacks, threads it through_initialize_connection, and appends one adapter event callback that converts eachStreamingDeltaEventfrom the events socket into anLLMStreamChunk(choices[0].delta.content/reasoning_content), matching what a local conversation's token callbacks receive. - The server side actually streams deltas on the events socket:
_WebSocketSubscribersetsreceives_streaming_deltas = True, and_publish_stream_deltapublishesStreamingDeltaEventdirectly to PubSub (not persisted).StreamingDeltaEventround-trips throughEvent.model_validateback to the same type, so the adapter'sisinstancedispatch fires. - No-op when unused: with
token_callbacks=Noneno callback is appended, and the adapter never writes tostate.events— so the "nothing changes otherwise" claim holds. uv run pytest tests/sdk/conversation/-> 867 passed, including the newtest_token_callbacks_receive_streamed_deltas;uv run pre-commit run --files <changed>(ruff, pycodestyle, pyright, import rules) passes;control-agent-server map check-> ok (935 ids, no problems). Current-head GitHub Actions for this SHA show no failing checks.
Acceptance. The PR's live before/after evidence (map --repeat 2: xfail on main, xpass on this branch, then pass after the marker is dropped, with a real stream=True model) exercises the real supported entry point, and the map prose/asserts match the implemented behavior. This environment has no model key, so I did not re-run the live map myself.
Notes (not defects). RemoteConversation.create() / attach() still take no token callbacks; that predates this change and is out of the reported bug's scope, so it is not a regression here. The adapter's dependence on StreamingDeltaEvent on the legacy socket is a known, documented transition point to the session-socket Delta frames.
No material correctness, security, compatibility, or acceptance-criterion defect found.
✅ APPROVED
…n-callbacks Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S978x74H7Drsnw7bzoGWc8
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-agent-server.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Why
Conversation(agent=..., workspace=RemoteWorkspace(...), token_callbacks=[cb])never calledcb: the factory forwardstoken_callbackstoRemoteConversation, whose constructor swallowed it in**_. The server already streams every token delta on the events socket as aStreamingDeltaEvent(event callbacks receive them), so a remote user asking for token streaming silently got nothing.Summary
RemoteConversation.__init__acceptstoken_callbacks(added as the last named parameter, so positional callers are unaffected) and passes it to_initialize_connection.StreamingDeltaEventfrom the socket into anLLMStreamChunk(choices[0].delta.content/reasoning_content), the same type a local conversation's token callbacks receive. Nothing changes when no token callbacks are passed; event callbacks andstate.eventsare untouched.# bugmarker fromF33.conversation-token-callbacksand rewrites its prose and the matching Gotchas line.Issue Number
Fixes #5959
How to Test
tests/sdk/conversation/remote/test_remote_conversation.py::TestRemoteConversation::test_token_callbacks_receive_streamed_deltas(goes through the publicConversation(...)factory): fails on main (0 == 1token calls), passes here.uv run pytest tests/sdk/conversation/-> 867 passed.stream=TrueDeepSeek agent LLM:6e7a853):control-agent-server map run --file F33 --only F33.conversation-token-callbacks --fresh --repeat 2 --checkout <main checkout>->xfail,xfail.xpass,xpass.control-agent-server map checkok;map run --only F33.conversation-token-callbacks --fresh->pass.uv run pre-commit run --files <changed files>(ruff, pycodestyle, pyright, import rules) passes.Video/Screenshots
n/a
Type
Notes
RemoteConversation(...)constructor path the factory uses;RemoteConversation.create(...)/attach(...)take no token callbacks today and are unchanged.StreamingDeltaEventon the legacy socket, this adapter should move to the session socket'sDeltaframes. The sibling bug of deltas being kept instate.events(F33.conversation-streaming-state) is left for a separate PR.🤖 Generated with Claude Code
https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
Generated by Claude Code
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:a3a0608-pythonRun
All tags pushed for this build
About Multi-Architecture Support
a3a0608-python) is a multi-arch manifest supporting both amd64 and arm64a3a0608-python-amd64) are also available if needed