refactor(acp): extract session_update dispatch into typed per-update handlers#3801
Open
tksrmz wants to merge 2 commits into
Open
refactor(acp): extract session_update dispatch into typed per-update handlers#3801tksrmz wants to merge 2 commits into
session_update dispatch into typed per-update handlers#3801tksrmz wants to merge 2 commits into
Conversation
Collaborator
|
[Automatic Post]: I have assigned @neubig as a reviewer based on git blame information. Thanks in advance for the help! This comment was created by an AI agent (OpenHands) on behalf of the user. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Splitting up the giant session-update dispatcher so it's easier to read and extend. Pure cleanup, no behavior change — please sanity-check that I moved every branch faithfully.
AGENT:
Why
The dispatch block in
_OpenHandsACPBridge._handle_session_updateinlined the logic for every update kind (AgentMessageChunk/AgentThoughtChunk/UsageUpdate/ToolCallStart/ToolCallProgress, plus the fork-session branch) directly inside a singleif/elifchain. The method had grown large, hurting readability and testability. Extracting each branch into its own handler method — and annotating the arguments with concrete update types instead ofAny— clarifies responsibilities and improves type safety.This is a pure refactor with no behavioral change.
Summary
_handle_session_updateinto dedicated methods:_handle_fork_update/_handle_message_chunk/_handle_thought_chunk/_handle_usage_update/_handle_tool_call_start/_handle_tool_call_progress(masking logic and the terminal-event emission conditions are unchanged).updateargument with its concrete type (AgentMessageChunk/AgentThoughtChunk/UsageUpdate/ToolCallStart/ToolCallProgress) instead ofAny.Issue Number
No related issue.
How to Test
The change touches a single file:
openhands-sdk/openhands/sdk/agent/acp_agent.py.Run the related unit tests:
→
397 passed. These cover every branch touched by this change: ACP message accumulation, thought/usage handling, tool-call start/progress, secret masking, and terminal-event dedup/truncation.Type-check (to validate the concrete type annotations):
→
0 errors, 0 warnings, 0 informations.Video/Screenshots
No GUI change is involved (internal refactor), so screenshots are not applicable.
The execution logs of the commands above serve as evidence instead:
Type
Notes