feat(mesh): add MeshSession singleton — ref-counted Zenoh session per process#103
Closed
cagataycali wants to merge 1 commit intostrands-labs:mainfrom
Closed
feat(mesh): add MeshSession singleton — ref-counted Zenoh session per process#103cagataycali wants to merge 1 commit intostrands-labs:mainfrom
cagataycali wants to merge 1 commit intostrands-labs:mainfrom
Conversation
… process Add strands_robots/mesh_session.py — a process-level singleton that manages a single zenoh.Session shared by all Mesh instances in the same process. Key design decisions: - Ref-counted: multiple Mesh instances share one session, closed at 0 - Fork-aware: detects PID change and re-initialises (stale session) - Lazy import: 'import zenoh' only on first MeshSession.open() - Env config: ZENOH_CONNECT and ZENOH_LISTEN override endpoints - Programmatic config: config_overrides dict for CI/testing - atexit hook: best-effort cleanup at interpreter shutdown - Fail-fast: RuntimeError if zenoh.open() fails (no silent fallback) - Returns None if eclipse-zenoh not installed (graceful degradation) pyproject.toml: - Add [mesh] optional extra: eclipse-zenoh>=0.11.0,<1.0.0 - Include [mesh] in [all] extras - Add zenoh.* to mypy ignore_missing_imports - Add mesh_session mypy override (warn_return_any=false) Tests: 15 new tests (0.4s), all mock zenoh — no network required: - Lifecycle: open/close/refcount/reuse - Import failure: graceful None when zenoh absent - Env config: ZENOH_CONNECT, ZENOH_LISTEN, multi-endpoint - Config overrides: programmatic JSON5 injection - Fork detection: PID change → re-init - Open failure: RuntimeError propagation - Thread safety: 10 concurrent open + 10 concurrent close - atexit cleanup: session closed, noop when no session Part 1 of 6 for Zenoh mesh (strands-labs#95).
Member
Author
This was referenced Apr 21, 2026
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.
Summary
Add
strands_robots/mesh_session.py— a process-level singleton that manages a singlezenoh.Sessionshared by all Mesh instances in the same process.This is PR 1 of 6 for the Zenoh mesh feature (#95).
What this PR does
strands_robots/mesh_session.py(219 LOC)A
MeshSessionclass that provides:Meshinstances share one session; actual close at refcount=0os.fork)import zenohonly on firstMeshSession.open()— zero cost at package importZENOH_CONNECTandZENOH_LISTENoverride endpointsconfig_overridesdict for CI/testingRuntimeErrorifzenoh.open()fails — no silent fallbackNoneifeclipse-zenohnot installedUsage (future PRs will use this)
pyproject.tomlchanges[mesh]optional extra:eclipse-zenoh>=0.11.0,<1.0.0[mesh]in[all]extraszenoh.*to mypyignore_missing_importsTests
15 tests in
tests/test_mesh_session.py— all mock zenoh, no network required:Nonewhen zenoh absentResults: 15 passed, 0.4s. Full suite: 243 passed, 6 skipped, 0 failures.
Checklist
pytest tests/test_mesh_session.py— 15/15)pytest tests/— 243/243)ruff check+ruff format)import zenohat package level<1.0.0)Closes #95 (partially — PR 1 of 6)
🤖 AI agent response. Strands Agents. Feedback welcome!