Unitree connection module refactor#2643
Conversation
Greptile SummaryThis PR refactors the Unitree connection layer by splitting the monolithic
Confidence Score: 4/5The refactor is structurally sound and most paths are safe, but the subclass stop() overrides introduce a deadlock if stop() is called more than once. Both Go2WebRTCConnection.stop() and G1WebRTCConnection.stop() call publish() before the base class guards run. When the event loop is already stopped, publish() reaches asyncio.run_coroutine_threadsafe(...).result() with no timeout; the future is never resolved and the calling thread hangs indefinitely. The base class stop() was specifically designed and tested to be idempotent, but the subclass overrides break that property on every double-stop path. dimos/robot/unitree/go2/go2_webrtc.py and dimos/robot/unitree/g1/g1_webrtc.py — the stop() overrides in both files need a self.loop.is_running() guard before calling publish(). Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class Resource {
+start()
+stop()
}
class UnitreeWebRTCConnection {
+ip: str
+mode: str
+conn: LegionConnection
+loop: asyncio.EventLoop
+thread: Thread
+connect()
+stop()
+publish(topic, data, msg_type)
+publish_request(topic, data)
+subscribe(topic_name)
}
class Go2WebRTCConnection {
+twist_mode: TwistMode
+_move_seq: int
+_rage_active: bool
+_stop_handle: TimerHandle
+move(twist, duration)
+stop()
+set_rage_mode(enable)
+raw_video_stream()
+lidar_stream()
+odom_stream()
}
class G1WebRTCConnection {
+_stop_handle: TimerHandle
+move(twist, duration)
+stop()
+standup()
+liedown()
}
class ReplayConnection {
+dataset: str
+connect()
+stop()
+lidar_stream()
+odom_stream()
}
class CompositeResource {
+stop()
}
Resource <|-- UnitreeWebRTCConnection
UnitreeWebRTCConnection <|-- Go2WebRTCConnection
UnitreeWebRTCConnection <|-- G1WebRTCConnection
Go2WebRTCConnection <|-- ReplayConnection
CompositeResource <|-- ReplayConnection
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
classDiagram
class Resource {
+start()
+stop()
}
class UnitreeWebRTCConnection {
+ip: str
+mode: str
+conn: LegionConnection
+loop: asyncio.EventLoop
+thread: Thread
+connect()
+stop()
+publish(topic, data, msg_type)
+publish_request(topic, data)
+subscribe(topic_name)
}
class Go2WebRTCConnection {
+twist_mode: TwistMode
+_move_seq: int
+_rage_active: bool
+_stop_handle: TimerHandle
+move(twist, duration)
+stop()
+set_rage_mode(enable)
+raw_video_stream()
+lidar_stream()
+odom_stream()
}
class G1WebRTCConnection {
+_stop_handle: TimerHandle
+move(twist, duration)
+stop()
+standup()
+liedown()
}
class ReplayConnection {
+dataset: str
+connect()
+stop()
+lidar_stream()
+odom_stream()
}
class CompositeResource {
+stop()
}
Resource <|-- UnitreeWebRTCConnection
UnitreeWebRTCConnection <|-- Go2WebRTCConnection
UnitreeWebRTCConnection <|-- G1WebRTCConnection
Go2WebRTCConnection <|-- ReplayConnection
CompositeResource <|-- ReplayConnection
|
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
5db442f to
33f904f
Compare
33f904f to
2a29be8
Compare
Problem
Multiple
connection.pyfiles exist in therobot/unitreefolder each doing its thing + a lot of dependency on each other.Closes DIM-XXX
Solution
We rename files for less confusion and also refactor to make holistic connection module for go2 and g1
How to Test
all unitree-go2 and g1 blueprints should run without any problem
Contributor License Agreement