Skip to content

feat(mesh): add session singleton and peer registry#101

Open
cagataycali wants to merge 3 commits intostrands-labs:mainfrom
cagataycali:autonomous/mesh-session
Open

feat(mesh): add session singleton and peer registry#101
cagataycali wants to merge 3 commits intostrands-labs:mainfrom
cagataycali:autonomous/mesh-session

Conversation

@cagataycali
Copy link
Copy Markdown
Member

Summary

Add strands_robots/mesh_session.py — the foundation layer for Zenoh mesh networking. This is PR 1 of 6 in the mesh implementation plan.

What this PR adds

Session lifecycle (get_session / release_session):

  • Lazy, ref-counted zenoh.Session — one per process
  • First process listens on tcp/127.0.0.1:7447; subsequent processes fall back to client mode
  • atexit handler prevents session leaks
  • Configurable via ZENOH_CONNECT, ZENOH_LISTEN, STRANDS_MESH_PORT env vars

Peer registry (thread-safe, shared across all Mesh instances):

  • PeerInfo dataclass with age tracking and JSON serialisation
  • update_peer() / prune_peers() / get_peers() / get_peer()
  • Concurrent-safe with dedicated locks

Publish helper:

  • put(key, data) — fire-and-forget JSON publish, safe no-op when session is None

Dependency:

  • New [mesh] optional extra: eclipse-zenoh>=1.0.0,<2.0.0
  • zenoh.* added to mypy ignore_missing_imports
  • Zero zenoh import at module level (lazy inside get_session)

6-PR Roadmap

PR Scope Status
1 (this) Session singleton + peer registry 🔄
2 Mesh class + presence + peer discovery
3 tell/send/broadcast + response correlation
4 publish_step + subscribe + on_stream
5 emergency_stop + safety audit log
6 Wire mesh into Robot.init

Testing

  • 29 tests, all mocked (no network or zenoh install required)
  • 90% coverage on mesh_session.py
  • Concurrent peer update stress test (4 threads × 50 peers)
  • Full existing test suite passes (257 passed, 6 skipped)

Files changed

File Change
strands_robots/mesh_session.py New — session + peer registry (~240 LOC)
tests/mesh/__init__.py New — test package
tests/mesh/test_mesh_session.py New — 29 tests (~340 LOC)
pyproject.toml Add [mesh] extra, zenoh mypy override

🤖 AI agent response. Strands Agents. Feedback welcome!

@cagataycali
Copy link
Copy Markdown
Member Author

This is the canonical mesh-session PR. Closed duplicates: #100, #103.

Tracking issue: #98 (feat(mesh): Zenoh-based Robot Mesh)

strands-robots-agent and others added 3 commits April 23, 2026 00:27
Add strands_robots/mesh_session.py — the foundation layer for Zenoh mesh
networking.  This is PR 1 of 6 in the mesh implementation plan (issue
cagataycali/strands-gtc-nvidia#313).

Session lifecycle:
- get_session() / release_session(): lazy, ref-counted zenoh.Session
- First process listens on tcp/127.0.0.1:7447; second falls back to client
- atexit handler prevents session leaks on process exit
- Configurable via ZENOH_CONNECT, ZENOH_LISTEN, STRANDS_MESH_PORT env vars

Peer registry:
- PeerInfo dataclass with age tracking and serialisation
- Thread-safe upsert (update_peer), pruning (prune_peers), query (get_peers)
- Shared across all Mesh instances in a process

Publish helper:
- put(key, data): fire-and-forget JSON publish, no-op when session is None

Dependency:
- New [mesh] optional extra: eclipse-zenoh>=1.0.0,<2.0.0
- zenoh.* added to mypy ignore_missing_imports
- Zero zenoh import at module level (lazy inside get_session)

Tests: 29 tests, all mocked (no network required), 90% coverage on module
mypy requires generator functions (those using yield) to declare a
Generator/Iterator return type instead of None. Changed all 4 pytest
fixtures from -> None to -> Iterator[None] and removed the now-
unnecessary # type: ignore[misc] comments.

Fixes: 4 mypy [misc] errors on lines 78, 168, 315, 414
@cagataycali cagataycali force-pushed the autonomous/mesh-session branch from 5cb85d5 to 50b5d03 Compare April 23, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants