fix: send hook_config to server in RemoteConversation#2115
fix: send hook_config to server in RemoteConversation#2115
Conversation
The hook_config was being accepted but never sent to the server when creating a conversation via RemoteConversation. This meant that hooks for PreToolUse, PostToolUse, UserPromptSubmit, and Stop were never executed server-side. Changes: - Add hook_config to the payload when creating conversations on server - Update example to demonstrate hook configuration with RemoteConversation - Remove outdated warning since hooks are now sent to server Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
Taste Rating: 🟡 Acceptable - Core fix is correct, but example comments need updating.
VERDICT: ✅ Worth merging after fixing the outdated comments. The bug fix itself is solid.
examples/02_remote_agent_server/01_convo_with_local_agent_server.py
Outdated
Show resolved
Hide resolved
Verifies that hook_config is properly sent to the server when creating a RemoteConversation, ensuring server-side hooks (PreToolUse, PostToolUse, etc.) can execute. Co-authored-by: openhands <openhands@all-hands.dev>
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Add HookExecutionEvent to provide full observability into hook execution: - Create new event type HookExecutionEvent with fields for hook type, command, success/blocked status, stdout/stderr, and context - Update HookEventProcessor to emit HookExecutionEvent for all hook types (PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, SessionEnd, Stop) - Add emit_hook_events parameter to control event emission (default True) - Add 'hook' to SourceType for proper event typing - Export HookExecutionEvent from openhands.sdk public API - Add comprehensive tests for HookExecutionEvent emission - Fix existing tests to handle new events being emitted The HookExecutionEvent includes: - hook_event_type: Type of hook (PreToolUse, PostToolUse, etc.) - hook_command: The command that was executed - success/blocked/exit_code: Execution result - stdout/stderr: Command output - reason/additional_context/error: Hook response data - action_id/message_id: Related event IDs - hook_input: Input data passed to hook Co-authored-by: openhands <openhands@all-hands.dev>
…er.py Co-authored-by: OpenHands Bot <contact@all-hands.dev>
examples/02_remote_agent_server/01_convo_with_local_agent_server.py
Outdated
Show resolved
Hide resolved
- Add hook_config field to ConversationState for persistence - Add hook_config field to SystemPromptEvent for observability in event stream - Update visualize and __str__ methods to display hook info - Store final hook_config in state when plugins are loaded (LocalConversation) - Add hook_config property to RemoteState to fetch from server - Add hook_config to ConversationStateProtocol - Resolve HookConfig forward reference in SystemPromptEvent via model_rebuild This enables users to see what hooks are configured for a conversation via the state API and in the SystemPromptEvent at the start of conversation. Co-authored-by: openhands <openhands@all-hands.dev>
| ], | ||
| ) | ||
| ], | ||
| ) |
There was a problem hiding this comment.
@OpenHands can we add a on_stop hook, and make sure we assert that the current post_tool_use hook and the on_stop hook both works? We should also assert that the client will receive the new HookExecutionEvent before say this is implemented
There was a problem hiding this comment.
I'm on it! xingyaoww can track my progress at all-hands.dev
There was a problem hiding this comment.
Summary
I addressed the PR review comment requesting enhanced test coverage for the test_hook_config_sent_to_server test.
Changes Made (commit 2444bd1e)
File: tests/cross/test_remote_conversation_live_server.py
- ✅ Added
on_stophook - Configured bothpost_tool_useandstophooks in the test - ✅ Patched LLM to trigger hooks - Created a fake completion that returns a
finishtool call, which triggers:PostToolUsehook (after finish tool executes)Stophook (when agent attempts to stop)
- ✅ Assert
HookExecutionEventreceived - Added verification that the client receivesHookExecutionEventfor both hook types with:- Correct
hook_event_type("PostToolUse"and"Stop") success == Trueblocked == Falseexit_code == 0- Correct
hook_commandpath
- Correct
- ✅ Added
HookExecutionEventimport to the test file
Verification
- Pre-commit hooks pass (ruff format, ruff lint, pycodestyle, pyright)
- Changes have been pushed to the
fix/remote-conversation-hook-configbranch
The test now comprehensively validates that hook_config is properly sent to the server and that both PostToolUse and Stop hooks execute correctly, with HookExecutionEvent events properly received by the client.
- Add on_stop hook in addition to post_tool_use hook - Use patched LLM that returns finish tool call to trigger hooks - Assert HookExecutionEvent events are received for both PostToolUse and Stop - Verify hook execution details (success, blocked, exit_code, command) Co-authored-by: openhands <openhands@all-hands.dev>
Use git commit 2444bd1e66191598f07e7f91adcd6f1c69b78dac from OpenHands/software-agent-sdk#2115 This includes the fix for sending hook_config to server in RemoteConversation. Co-authored-by: openhands <openhands@all-hands.dev>
Summary
Fixed a bug where
hook_configwas being accepted byRemoteConversationbut never sent to the server when creating a conversation.Problem
When using
RemoteConversationwithhook_config, hooks forPreToolUse,PostToolUse,UserPromptSubmit, andStopwere never executed server-side because thehook_configwasn't included in the conversation creation payload.The client was showing a misleading warning "RemoteConversation only supports SessionStart/SessionEnd hooks" when it should have been sending the hook configuration to the server where these hooks would be executed.
Changes
hook_configto the payload when creating conversations via the REST API02_remote_agent_server/01_convo_with_local_agent_server.pyto demonstrate hook configuration withRemoteConversationTesting
Ran the modified example to verify:
Related Documentation
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang: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:559e236-pythonRun
All tags pushed for this build
About Multi-Architecture Support
559e236-python) is a multi-arch manifest supporting both amd64 and arm64559e236-python-amd64) are also available if needed