Repository navigation
fix(sdk): restore tool registrations on remote attach - #5069
Conversation
Coverage Report •
|
||||||||||||||||||||||||||||||
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
07234c8 to
4e06cdb
Compare
Co-authored-by: openhands <openhands@all-hands.dev>
4e06cdb to
8d8664a
Compare
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Summary
The change is well-scoped and correctly closes the server side of the loop: ConversationService now persists server-resolved module qualnames onto StoredConversation (via get_tool_module_qualnames() + setdefault, preserving explicit custom mappings), ConversationInfo surfaces them (mirroring client_tools), and RemoteConversation._from_info imports them before the initial event sync. Error propagation for a missing package is clear and names both tool and module. Tests cover the round trip and the missing-module case, and all check runs on 80f8781 are green.
Material finding: the documented conversation_id attach path still fails
_restore_tool_registrations(...) is only called from _from_info (line 990), which covers attach() and create(). It is not called on the other supported attach path: the public constructor RemoteConversation(agent=..., workspace=..., conversation_id=<existing>) (and the Conversation(...) factory that forwards to it in openhands-sdk/openhands/sdk/conversation/conversation.py). That path is documented in the __init__ docstring as "Optional existing conversation id to attach to", and it performs the identical initial event sync (RemoteEventsList._do_full_sync() inside _initialize_connection).
Crucially, that constructor branch already collects the persisted metadata it needs before the sync — lines 805-810 read info["client_tools"] into attached_client_tools and pass them into _initialize_connection precisely so persisted ClientAction_* events deserialize. No equivalent read of info["tool_module_qualnames"] (or call to _restore_tool_registrations) was added there. So a fresh client that attaches to a service-created conversation by id still hits the exact symptom from #5067:
RemoteConversation(agent=agent, workspace=RemoteWorkspace(...), conversation_id=existing_id)
# -> Event.model_validate(...) raises: Unknown kind 'TerminalAction'
This is not hypothetical: tests/cross/test_remote_conversation_live_server.py::test_websocket_attach_wait_does_not_block_ready_endpoint attaches through Conversation(..., conversation_id=...), i.e. this constructor path. The issue's acceptance criterion — "RemoteConversation imports those modules before its initial persisted-event sync" — is therefore only half satisfied; attach() works, but the constructor/factory attach does not.
Suggested fix: in the conversation_id is not None existing-conversation branch (around lines 805-810), also capture info.get("tool_module_qualnames") and invoke _restore_tool_registrations(...) before _initialize_connection, mirroring the client_tools handling. A regression test that attaches via the constructor (not RemoteConversation.attach) and asserts the persisted module is imported would lock this in.
Non-blocking notes
- The
ConversationInfo.tool_module_qualnamesdescription is copied verbatim fromStartConversationRequestand still reads as request-side ("from the client's registry ... imported on the server"), which is misleading on a response field. Minor wording, not a defect. _restore_tool_registrationsimportsmodule_qualnamedirectly; the committed value is a module qualname (e.g.openhands.tools.terminal.definition), soimportlib.import_moduleis correct. No issue there.
🔄 CHANGES REQUESTED
_restore_tool_registrations() was called only from _from_info(), so the RemoteConversation(agent=..., conversation_id=<existing>) constructor path - also reachable via the Conversation(..., conversation_id=...) factory - left the conversation's persisted tool modules unimported and their ClientAction_* events undeserializable. Capture tool_module_qualnames alongside the already-captured client tool specs from the same GET response and restore before the initial event sync, matching _from_info(). Extend the test suite with a case that fails without the restore. Co-authored-by: openhands <openhands@all-hands.dev>
⏳ Review waiting on checksThe current head
No action is needed. The scheduled scan retries once every check on the head reports a conclusion. This is an automated check - no AI was used to generate this comment. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Summary
This revision closes the loop cleanly and the earlier concern about the constructor attach path is resolved.
Server side: when a lightweight client creates a conversation, ConversationService.start_conversation now resolves get_tool_module_qualnames(), merges those server-resolved modules onto the request's explicit tool_module_qualnames with setdefault (so explicit custom mappings stay authoritative), and persists the merged mapping via StoredConversation. ConversationInfo surfaces it, mirroring client_tools. The merge is correctly placed after profile resolution, so an injected browser tool is included, and before StoredConversation model_dump, so the field round-trips into meta.json.
Client side: _restore_tool_registrations() imports the persisted modules and raises a clear ImportError naming both the tool and module when a package is missing. It is now invoked on every attach entry point: _from_info (used by attach() and create()), and the constructor path, which captures tool_module_qualnames from the same GET /api/conversations/{id} response it already reads client_tools from and calls the restore immediately before _initialize_connection — so imports happen before the initial event sync in both cases. The create branch correctly passes an empty mapping (nothing persisted yet; the caller's own modules were already sent in the create payload), which I confirmed by exercising the constructor with a mocked create response.
Verification
- All check runs on
c4b13370cf79are green (no failing, non-skipped conclusions). tests/sdk/conversation/remote/test_remote_conversation.py— 59 passed, including the newtest_constructor_attach_restores_persisted_tool_modulesandtest_attach_reports_a_missing_tool_module.tests/agent_server/test_conversation_info_model.pyandtests/agent_server/test_conversation_service.py— 135 passed, includingtest_server_resolved_tool_modules_are_persisted.ruff checkpasses on all three changed source files; theMappingimport is already present.
No material findings remain. The new ConversationInfo.tool_module_qualnames field is additive and the TypeScript transport schema is regenerated through the existing release workflow, as the PR notes.
✅ APPROVED
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Summary
No material findings. The earlier concern on this PR — that _restore_tool_registrations() was reachable only through _from_info() (used by attach()/create()), leaving the constructor attach path to sync persisted events without importing the conversation's tool modules — is resolved on this head, and the review thread is closed.
Server side: when a lightweight client creates a conversation, ConversationService resolves get_tool_module_qualnames(), merges the server-resolved modules onto the request's explicit mapping with setdefault (explicit custom mappings stay authoritative), and persists the merged result on StoredConversation. ConversationInfo.tool_module_qualnames surfaces it, mirroring client_tools. The merge is placed after profile resolution (so an injected browser tool is captured) and before model_dump, so the field round-trips through meta.json.
Client side: the constructor now reads tool_module_qualnames from the same GET /api/conversations/{id} response it already uses to pick up client_tools, and calls _restore_tool_registrations() immediately before _initialize_connection — matching _from_info()'s ordering so imports happen before the initial event sync. The create branch correctly passes an empty mapping (nothing persisted yet; the caller's own qualnames were already sent in the create payload). A missing package raises an error naming both the tool and module.
Verification
- Head confirmed
c4b13370cf797df2d64e776b75db6a4a2a6fb56e; all check runs are green with none pending. tests/sdk/conversation/remote/test_remote_conversation.py,tests/agent_server/test_conversation_info_model.py,tests/agent_server/test_conversation_service.py— 194 passed, including the new constructor-attach restore and missing-module tests.- Linked issue #5067 is open with
ready-for-devandpriority:low.
The new ConversationInfo field is additive, and the TypeScript transport schema is regenerated from the canonical OpenAPI contract through the existing release workflow.
✅ APPROVED
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Summary
Re-reviewed the current head c4b13370cf79 (unchanged since the previous review). The implementation is sound and the earlier constructor-attach gap is fixed: _restore_tool_registrations() now runs on both attach entry points — _from_info (used by attach()/create()) and the constructor branch — before _initialize_connection performs the initial event sync. On the server, ConversationService.start_conversation merges get_tool_module_qualnames() onto the request mapping with setdefault (so explicit custom mappings stay authoritative) and persists the result; ConversationInfo surfaces it as an additive field. The ImportError for a missing package names both the tool and the module. The one open review thread is resolved.
Verification on this head
tests/agent_server/test_conversation_info_model.py+tests/agent_server/test_conversation_service.py— 135 passed.tests/sdk/conversation/remote/test_remote_conversation.py— 59 passed.ruff checkon the six changed files — passed.
Material finding: the head's Validate PR description check is failing
The only non-green check on c4b13370cf79 is Validate PR description (run 109037667724, conclusion failure); the PR's statusCheckRollup state is FAILURE and mergeStateStatus is UNSTABLE. Its annotation reads:
Add a short human-written note between
HUMAN:andAGENT:.
The HUMAN: section of the PR body is still the template placeholder. This is a required repository gate (.github/workflows/pr-description-check.yml -> .github/scripts/check_pr_description.py), and root AGENTS.md documents that AI agents must not edit, fill, or remove this field. No code change on the head can clear it: the author needs to add their own note between HUMAN: and AGENT: before the PR can merge. I am reporting it rather than editing the description, per that guidance.
No code-level defect was found on this head; the only outstanding item is the human-authored PR description note.
🔄 CHANGES REQUESTED
|
The remaining Validate PR description failure requires a short human-authored note between the protected |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Summary
Re-reviewing head c4b13370cf797df2d64e776b75db6a4a2a6fb56e after the latest comment. The code is unchanged since the previous approval, and no material findings remain. The earlier concern — that _restore_tool_registrations() was reachable only through _from_info() (used by attach()/create()), leaving the constructor attach path to sync persisted events without importing the conversation's tool modules — remains resolved, and the thread is closed.
Server side: when a lightweight client creates a conversation, ConversationService resolves get_tool_module_qualnames(), merges the server-resolved modules onto the request's explicit mapping with setdefault (explicit custom mappings stay authoritative), and persists the merged result on StoredConversation. ConversationInfo.tool_module_qualnames surfaces it. The merge is placed after profile resolution and before model_dump, so the field round-trips through meta.json.
Client side: the constructor reads tool_module_qualnames from the same GET /api/conversations/{id} response it already uses to pick up client_tools, and calls _restore_tool_registrations() immediately before _initialize_connection, matching _from_info()'s ordering so imports precede the initial event sync. A missing package raises an error naming both the tool and module.
Verification
- Head confirmed
c4b13370cf797df2d64e776b75db6a4a2a6fb56e; code and test suites (sdk-tests,agent-server-tests,tools-tests,cross-tests,workspace-tests,windows-tests,agent-server-stress-tests) are green. - Re-ran
tests/sdk/conversation/remote/test_remote_conversation.py,tests/agent_server/test_conversation_info_model.py,tests/agent_server/test_conversation_service.py— 194 passed, including the constructor-attach restore and missing-module tests. - Linked issue #5067 is open with
ready-for-devandpriority:low.
One non-code note: the Validate PR description check is failing because the protected HUMAN: section still needs a short human-authored note; that is a repository process gate, not a code defect, and no code change is implied. The new ConversationInfo field is additive, with the TypeScript transport schema regenerated from the canonical OpenAPI contract through the existing release workflow.
✅ APPROVED
HUMAN:
This was tested live and seems to be working.
AGENT:
Why
An SDK client can attach to a conversation whose Agent Server has registered external tool schemas, but the server does not return the persisted module mapping to that client. The attachment then rejects standard terminal, file-editor, and browser events as unknown even when the corresponding tool package is installed.
Summary
When an Agent Server resolves built-in tools on behalf of a lightweight client, persist the resolved module names with the conversation. Return that mapping in
ConversationInfoand import the modules beforeRemoteConversationperforms its initial event sync. This completes the reverse half of the existing creation and restoration mechanism; applications install the tool package but no longer need role-specific imports. Explicit mappings for custom tools remain authoritative.A missing package raises an error that identifies both the tool and module required by the conversation.
REST API contract changes
Compared with base OpenAPI
a8a9fc6e236afor public/api/**paths.Issue Number
Fixes #5067.
How to Test
make test-server-schemapassed with the existing 99 weak-schema locations; the allowlist is unchanged.Live proof: an isolated Canvas stack using the Docker runtime launched the airbnb-clone #64 triage subject in a 2 GiB/1 CPU container. The conversation API returned persisted module mappings for
terminal,file_editor,task_tracker, andbrowser_tool_set; the lightweight Automation client attached, loaded all 17 tool specs, completed the agent turn, and released the container. The resulting automated triage is visible at https://github.com/neubig/airbnb-clone/issues/64#issuecomment-5671813595.Type
Notes
This is an additive Agent Server response field. The generated TypeScript transport schema remains derived from the canonical OpenAPI contract through the existing release workflow.
Live main-vs-PR validation
Validated exact base
a8a9fc6e236a31c7adb876abb2be9e41e3c359b7against headc4b13370cf797df2d64e776b75db6a4a2a6fb56eusing a real local agent-server, a fresh remote client process, and an LLM-backed terminal turn.RemoteConversation.attach()failed on the first synchronized event withUnexpected kind 'TerminalTool' for ToolDefinition.TerminalAction, and executed a restored terminal tool end to end (PR5069_ATTACH_EXEC).Verdict: confirmed. The tested main implementation fails and this head fixes the failure. Local-server/terminal were exercised; cloud deployment and every tool type were not.
This validation section was added by an AI agent (OpenHands) on behalf of Graham Neubig.
🐳 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:c4b1337-pythonRun
All tags pushed for this build
About Multi-Architecture Support
c4b1337-python) is a multi-arch manifest supporting both amd64 and arm64c4b1337-python-amd64) are also available if needed