Skip to content

Streamline transport start/stop methods#1062

Merged
leshy merged 2 commits intodevfrom
miguel_streamline_transport
Jan 20, 2026
Merged

Streamline transport start/stop methods#1062
leshy merged 2 commits intodevfrom
miguel_streamline_transport

Conversation

@Kaweees
Copy link
Member

@Kaweees Kaweees commented Jan 19, 2026

Several transport classes (LCMTransport, JpegLcmTransport, pSHMTransport, SHMTransport, JpegShmTransport) had empty start() and stop() method stubs (...). These are now fully implemented to properly start/stop the underlying transport and manage the _started flag.

uv run pytest -svm tool dimos/protocol/pubsub/benchmark/test_benchmark.py

@Kaweees Kaweees requested a review from a team January 19, 2026 15:31
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 19, 2026

Greptile Summary

This PR refactors transport lifecycle management by implementing previously empty start() and stop() method stubs across multiple transport classes (pLCMTransport, LCMTransport, JpegLcmTransport, pSHMTransport, SHMTransport, JpegShmTransport).

Key changes:

  • Centralized transport initialization logic into dedicated start() methods instead of inlining it in broadcast() and subscribe()
  • stop() methods now properly reset the _started flag to False, enabling proper restart capability
  • Improved code reusability by replacing duplicate transport.start() + _started = True blocks with calls to self.start()
  • All transport classes now properly fulfill the abstract Resource interface requirements

The refactoring maintains backward compatibility as the lazy initialization behavior (starting on first use) remains unchanged.

Confidence Score: 4/5

  • Safe to merge with good refactoring that improves code organization
  • The refactoring is well-structured and maintains backward compatibility. The changes centralize transport lifecycle management, making the code more maintainable. The PR doesn't introduce new bugs - it simply reorganizes existing logic into dedicated methods. The existing race condition (check-then-act on _started flag) was present before this change and is not introduced by this refactoring.
  • No files require special attention

Important Files Changed

Filename Overview
dimos/core/transport.py Implements start/stop methods in transport classes, centralizes transport lifecycle management

Sequence Diagram

sequenceDiagram
    participant Client
    participant Transport as Transport (LCM/SHM)
    participant Backend as Backend (lcm/shm)
    
    Note over Client,Backend: Before: Inline start logic
    Client->>Transport: broadcast(msg) / subscribe(callback)
    Transport->>Transport: Check _started flag
    alt not started
        Transport->>Backend: lcm.start() / shm.start()
        Transport->>Transport: Set _started = True
    end
    Transport->>Backend: publish(msg) / subscribe(callback)
    
    Note over Client,Backend: After: Centralized start() method
    Client->>Transport: broadcast(msg) / subscribe(callback)
    Transport->>Transport: Check _started flag
    alt not started
        Transport->>Transport: start()
        Transport->>Backend: lcm.start() / shm.start()
        Transport->>Transport: Set _started = True
    end
    Transport->>Backend: publish(msg) / subscribe(callback)
    
    Note over Client,Backend: Lifecycle management
    Client->>Transport: stop()
    Transport->>Backend: lcm.stop() / shm.stop()
    Transport->>Transport: Set _started = False
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (6)

  1. dimos/core/transport.py, line 63-66 (link)

    style: pLCMTransport wasn't refactored to use self.start() like the other transport classes. Should call self.start() instead for consistency.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  2. dimos/core/transport.py, line 73-75 (link)

    style: Same as in broadcast() - should use self.start() for consistency.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  3. dimos/core/transport.py, line 78 (link)

    style: pLCMTransport.start() should implement the method body like other transport classes.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  4. dimos/core/transport.py, line 80-81 (link)

    style: pLCMTransport.stop() should reset _started flag like other transport classes.

  5. dimos/core/transport.py, line 142-146 (link)

    style: pSHMTransport.broadcast() wasn't refactored to use self.start() like the other transport classes. Should call self.start() for consistency.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  6. dimos/core/transport.py, line 149-152 (link)

    style: Same as in broadcast() - should use self.start() for consistency.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

1 file reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

@Kaweees
Copy link
Member Author

Kaweees commented Jan 19, 2026

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 64 to +65
if not self._started:
self.lcm.start()
self._started = True
self.start()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: check-then-act race condition in concurrent scenarios - if two threads call broadcast() simultaneously when _started is False, both could call start() leading to multiple start calls on the underlying transport

Suggested change
if not self._started:
self.lcm.start()
self._started = True
self.start()
with getattr(self, '_start_lock', threading.Lock()):
if not self._started:
self.start()

Copy link
Contributor

@leshy leshy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually greptile is pointing out a legitimate issue here, LCM start() is instant and almost cannot fail (udp cannot fail to connect) so this is why we are so chill, ignoring start() and autostarting in broadcast() to save some resources.

Other protocols are slower, have legitimate slower blocking Start() processes, that can fail with "connection failiure" and such, so we expect them to have fat start() functions (ROS, some TCP connection etc, even SSH)

It makes sense to remove autostart from LCM if we want to be extra nitpicky, that's ok.
but definitely other protocols are not supposed to autostart like this and should have legitimate start() implementations

since we want our broadcast() and subscribe() functions to be instant, we are assuming tge transport is ready at that point, these shouldn't trigger unanticipated slow connection attempts, (especially without locks as greptile mentions, for like camera you'll get actual 30 parallel connection attempts per second - if we run DDS over ssh for agibot, this will be 100reds of SSH connection attemps, or (with a lock) a weird invisible message buffer filling)

Copy link
Contributor

@leshy leshy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are autoiniting SHM and LCM which are instant so this is fine, but we won't be doing the same for other protocols

@leshy leshy merged commit 405f158 into dev Jan 20, 2026
14 checks passed
spomichter added a commit that referenced this pull request Jan 23, 2026
… Unitree Go2 Navigation & Exploration Beta

Pre-Release v0.0.8: Unitree Go2 Navigation & Exploration Beta, Transport Updates, Documentation updates, Rerun fixes, Person follow, Readme updates

## What's Changed
* Small docs clarification about stream getters by @leshy in #1043
* Fix split view on wide monitors by @jeff-hykin in #1048
* Docs: Install & Develop  by @jeff-hykin in #1022
* Add uv to nix and fix resulting problems by @jeff-hykin in #1021
* v0.0.8 by @paul-nechifor in #1050
* Style changes in docs by @paul-nechifor in #1051
* Revert "Add uv to nix and fix resulting problems" by @leshy in #1053
* Transport benchmarks + Raw ros transport by @leshy in #1038
* feat: default to rerun-web and auto-open browser on startup (browser … by @Nabla7 in #1019
* bbox detections visual check by @leshy in #1017
* fix: only auto-open browser for rerun-web viewer backend by @Nabla7 in #1066
* move slow tests to integration by @paul-nechifor in #1063
* Streamline transport start/stop methods by @Kaweees in #1062
* Person follow skill with EdgeTAM by @paul-nechifor in #1042
* fix: increase costmap floor z_offset to avoid z-fighting by @Nabla7 in #1073
* Fixed issue #1074 by @alexlin2 in #1075
* ROS transports initial by @leshy in #1057
* Fix System Config Values for LCM on MacOS and Refactor by @jeff-hykin in #1065
* SHM Transport basic fixes by @leshy in #1041
* commented out Mem Transport test case by @leshy in #1077
* Docs/advanced streams update 2 by @leshy in #1078
* Fix more tests by @paul-nechifor in #1071
* feat: navigation docker updates from bona_local_dev by @baishibona in #1081
* Fix missing dependencies by @Kaweees in #1085
* Release readme fixes by @spomichter in #1076

## New Contributors
* @baishibona made their first contribution in #1081

**Full Changelog**: v0.0.7...v0.0.8
@Kaweees Kaweees deleted the miguel_streamline_transport branch January 24, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants