Skip to content

CLI: Duplicated actions cause duplicated lines #840

Closed as not planned
Closed as not planned

Description

@simonrosenberg

There seems to be an issue of duplicated actions in the CLI, which leads to the same line being added twice, which leads to the agent having to remove one line.

`
Agent running... (Press Ctrl-P to pause)
┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/state.py is edited with 1 changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│(content after edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│+4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Now I'll add a private attribute to store the conversation reference:

┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/state.py is edited with 1 changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│(content after edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│+4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)
┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/state.py is edited with 1 changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│ 4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│-5| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│(content after edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│ 4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

I see there's a duplicate line. Let me fix that:

┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/state.py is edited with 1 changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│ 4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│-5| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│(content after edit) │
│ 1| _lock: FIFOLock = PrivateAttr( │
│ 2| default_factory=FIFOLock │
│ 3| ) # FIFO lock for thread safety │
│ 4| _conversation: Any = PrivateAttr(default=None) # Reference to parent conversation │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)
┌──────────────────────────────────────────────────────────────────────────────| File Read |───────────────────────────────────────────────────────────────────────────────┐
│Here's the result of running cat -n on /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conver│
│sation.py: │
│ 85 │
│ 86 # Create-or-resume: factory inspects BASE_STATE to decide │
│ 87 desired_id = conversation_id or uuid.uuid4() │
│ 88 self._state = ConversationState.create( │
│ 89 id=desired_id, │
│ 90 agent=agent, │
│ 91 workspace=self.workspace, │
│ 92 persistence_dir=self.get_persistence_dir(persistence_dir, desired_id) │
│ 93 if persistence_dir │
│ 94 else None, │
│ 95 max_iterations=max_iteration_per_run, │
│ 96 stuck_detection=stuck_detection, │
│ 97 ) │
│ 98 │
│ 99 # Default callback: persist every event to state │
│ 100 def _default_callback(e): │
│ 101 self._state.events.append(e) │
│ 102 │
│ 103 composed_list = (callbacks if callbacks else []) + [_default_callback] │
│ 104 # Add default visualizer if requested │
│ 105 if visualize: │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Now I need to modify the LocalConversation to set this reference when creating the state. Let me find where the state is created and add the conversation reference:

┌──────────────────────────────────────────────────────────────────────────────| File Read |───────────────────────────────────────────────────────────────────────────────┐
│Here's the result of running cat -n on /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conver│
│sation.py: │
│ 85 │
│ 86 # Create-or-resume: factory inspects BASE_STATE to decide │
│ 87 desired_id = conversation_id or uuid.uuid4() │
│ 88 self._state = ConversationState.create( │
│ 89 id=desired_id, │
│ 90 agent=agent, │
│ 91 workspace=self.workspace, │
│ 92 persistence_dir=self.get_persistence_dir(persistence_dir, desired_id) │
│ 93 if persistence_dir │
│ 94 else None, │
│ 95 max_iterations=max_iteration_per_run, │
│ 96 stuck_detection=stuck_detection, │
│ 97 ) │
│ 98 │
│ 99 # Default callback: persist every event to state │
│ 100 def _default_callback(e): │
│ 101 self._state.events.append(e) │
│ 102 │
│ 103 composed_list = (callbacks if callbacks else []) + [_default_callback] │
│ 104 # Add default visualizer if requested │
│ 105 if visualize: │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)
┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py is edited with 1│
│ changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 7| else None, │
│ 8| max_iterations=max_iteration_per_run, │
│ 9| stuck_detection=stuck_detection, │
│ 10| ) │
│(content after edit) │
│ 7| else None, │
│ 8| max_iterations=max_iteration_per_run, │
│ 9| stuck_detection=stuck_detection, │
│ 10| ) │
│+11| │
│+12| # Set reference to this conversation in the state for delegation registration │
│+13| self._state._conversation = self │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

I need to add the conversation reference after the state is created:

┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py is edited with 1│
│ changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 7| else None, │
│ 8| max_iterations=max_iteration_per_run, │
│ 9| stuck_detection=stuck_detection, │
│ 10| ) │
│(content after edit) │
│ 7| else None, │
│ 8| max_iterations=max_iteration_per_run, │
│ 9| stuck_detection=stuck_detection, │
│ 10| ) │
│+11| │
│+12| # Set reference to this conversation in the state for delegation registration │
│+13| self._state._conversation = self │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Agent running... (Press Ctrl-P to pause)
┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py is edited with 1│
│ changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| ) │
│ 2| │
│ 3| # Set reference to this conversation in the state for delegation registration │
│ 4| self._state._conversation = self │
│-5| │
│-6| # Set reference to this conversation in the state for delegation registration │
│-7| self._state._conversation = self │
│(content after edit) │
│ 1| ) │
│ 2| │
│ 3| # Set reference to this conversation in the state for delegation registration │
│ 4| self._state._conversation = self │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

I see there's a duplicate line again. Let me fix that:

┌──────────────────────────────────────────────────────────────────────────────| File Edit |───────────────────────────────────────────────────────────────────────────────┐
│[Existing file /Users/simonrosenberg/Desktop/work/repositories/All-Hands-AI/agent-sdk/openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py is edited with 1│
│ changes.] │
│[begin of edit 1 / 1] │
│(content before edit) │
│ 1| ) │
│ 2| │
│ 3| # Set reference to this conversation in the state for delegation registration │
│ 4| self._state._conversation = self │
│-5| │
│-6| # Set reference to this conversation in the state for delegation registration │
│-7| self._state._conversation = self │
│(content after edit) │
│ 1| ) │
│ 2| │
│ 3| # Set reference to this conversation in the state for delegation registration │
│ 4| self._state._conversation = self │
│[end of edit 1 / 1] │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
`

Activity

  1. all-hands-bot commented on Dec 30, 2025

    @all-hands-bot
    Collaborator

    This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

  2. all-hands-bot commented on Jan 9, 2026

    @all-hands-bot
    Collaborator

    This issue was automatically closed due to 50 days of inactivity. We do this to help keep the issues somewhat manageable and focus on active issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions