Skip to content

fix(sdk): deliver streamed deltas to RemoteConversation token_callbacks - #5965

Merged
enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-remote-token-callbacks
Oct 17, 2026
Merged

enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-remote-token-callbacks

Conversation

@enyst

@enyst enyst commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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 called cb: the factory forwards token_callbacks to RemoteConversation, whose constructor swallowed it in **_. The server already streams every token delta on the events socket as a StreamingDeltaEvent (event callbacks receive them), so a remote user asking for token streaming silently got nothing.

Summary

  • RemoteConversation.__init__ accepts token_callbacks (added as the last named parameter, so positional callers are unaffected) and passes it to _initialize_connection.
  • When token callbacks are given, a small event callback converts each StreamingDeltaEvent from the socket into an LLMStreamChunk (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 and state.events are untouched.
  • Map: drops the # bug marker from F33.conversation-token-callbacks and rewrites its prose and the matching Gotchas line.

Issue Number

Fixes #5959

How to Test

  • Unit test tests/sdk/conversation/remote/test_remote_conversation.py::TestRemoteConversation::test_token_callbacks_receive_streamed_deltas (goes through the public Conversation(...) factory): fails on main (0 == 1 token calls), passes here. uv run pytest tests/sdk/conversation/ -> 867 passed.
  • Map proof with a real stream=True DeepSeek agent LLM:
    • main (6e7a853): control-agent-server map run --file F33 --only F33.conversation-token-callbacks --fresh --repeat 2 --checkout <main checkout> -> xfail, xfail.
    • this branch (marker still in place): same command, branch checkout -> xpass, xpass.
    • after dropping the marker: control-agent-server map check ok; 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

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

Notes

🤖 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:a3a0608-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-a3a0608-python \
  ghcr.io/openhands/agent-server:a3a0608-python

All tags pushed for this build

ghcr.io/openhands/agent-server:a3a0608-golang-amd64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-golang-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-golang-amd64
ghcr.io/openhands/agent-server:a3a0608-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:a3a0608-golang-arm64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-golang-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-golang-arm64
ghcr.io/openhands/agent-server:a3a0608-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:a3a0608-java-amd64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-java-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-java-amd64
ghcr.io/openhands/agent-server:a3a0608-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:a3a0608-java-arm64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-java-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-java-arm64
ghcr.io/openhands/agent-server:a3a0608-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:a3a0608-python-amd64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-amd64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-amd64
ghcr.io/openhands/agent-server:a3a0608-python-arm64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-arm64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-arm64
ghcr.io/openhands/agent-server:a3a0608-python-minimal-amd64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-minimal-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-minimal-amd64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:a3a0608-python-minimal-arm64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-minimal-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-minimal-arm64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:a3a0608-python-slim-amd64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-slim-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-slim-amd64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:a3a0608-python-slim-arm64
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-slim-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-slim-arm64
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:a3a0608-golang
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-golang
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-golang
ghcr.io/openhands/agent-server:a3a0608-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:a3a0608-java
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-java
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-java
ghcr.io/openhands/agent-server:a3a0608-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:a3a0608-python-minimal
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-minimal
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-minimal
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-minimal
ghcr.io/openhands/agent-server:a3a0608-python-slim
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python-slim
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python-slim
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime-slim
ghcr.io/openhands/agent-server:a3a0608-python
ghcr.io/openhands/agent-server:a3a0608bf155047dcc7317d31aa87c267e33d492-python
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-remote-token-callbacks-python
ghcr.io/openhands/agent-server:a3a0608-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., a3a0608-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., a3a0608-python-amd64) are also available if needed

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
@enyst enyst self-assigned this Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/conversation/impl
   remote_conversation.py8138689%134, 209, 236, 249, 251–254, 280, 298–299, 310–313, 320–321, 326–329, 413, 423–425, 431, 515–516, 658–661, 663, 689–693, 698–701, 704, 720, 827, 861, 919–920, 924–925, 939, 1006, 1012, 1119–1122, 1171–1172, 1196–1197, 1237–1238, 1256, 1266, 1270, 1279–1280, 1319, 1473–1474, 1573–1574, 1578, 1583–1587, 1611, 1616, 1663, 1911–1912, 1920–1921
TOTAL491131326473% 

@enyst
enyst marked this pull request as ready for review October 14, 2026 03:14
@enyst
enyst requested a review from all-hands-bot October 14, 2026 03:16

@all-hands-bot all-hands-bot 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.

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 forwards token_callbacks (factory line ~200), and RemoteConversation.__init__ previously swallowed it in **_. The head now accepts token_callbacks, threads it through _initialize_connection, and appends one adapter event callback that converts each StreamingDeltaEvent from the events socket into an LLMStreamChunk (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: _WebSocketSubscriber sets receives_streaming_deltas = True, and _publish_stream_delta publishes StreamingDeltaEvent directly to PubSub (not persisted). StreamingDeltaEvent round-trips through Event.model_validate back to the same type, so the adapter's isinstance dispatch fires.
  • No-op when unused: with token_callbacks=None no callback is appended, and the adapter never writes to state.events — so the "nothing changes otherwise" claim holds.
  • uv run pytest tests/sdk/conversation/ -> 867 passed, including the new test_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
@enyst
enyst merged commit b301ee0 into main Oct 17, 2026
43 checks passed
@enyst
enyst deleted the claude/umbrella-bug-fixes-tgz9ai-remote-token-callbacks branch October 17, 2026 01:27
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
1 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Conversation(token_callbacks=[...]) with a RemoteWorkspace silently ignores the callbacks

3 participants