Skip to content

fix(zenoh): reopen pooled sessions after fork - #3457

Open
jiajiayao wants to merge 4 commits into
dimensionalOS:mainfrom
jiajiayao:fix/zenoh-session-pool-after-fork
Open

fix(zenoh): reopen pooled sessions after fork#3457
jiajiayao wants to merge 4 commits into
dimensionalOS:mainfrom
jiajiayao:fix/zenoh-session-pool-after-fork

Conversation

@jiajiayao

@jiajiayao jiajiayao commented Aug 13, 2026

Copy link
Copy Markdown

Contribution path

Problem

With the Zenoh transport, dimos run ... --daemon builds the coordinator before double-forking. That can populate the process-default Zenoh session pool in the parent. The daemon grandchild inherits the Python session objects, but not Zenoh's runtime threads, so CoordinatorRPC.serve() reuses a dead session and out-of-process clients cannot reach Coordinator/ping.

The inherited pool lock is also unsafe to reuse if another parent thread held it when the process forked.

Solution

Make ZenohSessionPool process-aware:

  • keep the owning PID, session cache, and lock in one process-owned state object
  • replace that entire state when os.getpid() changes
  • open a fresh session for the child instead of reusing or closing inherited Zenoh handles
  • retain same-process session sharing and existing close_all() behavior

A regression test simulates the PID transition and verifies that the child opens a second session while leaving the inherited parent handle untouched.

How to Test

pytest dimos/protocol/service/test_zenohservice.py \
  dimos/protocol/rpc/test_spec.py \
  dimos/core/test_zenoh_transport.py \
  dimos/core/coordination/test_coordinator_rpc.py \
  dimos/core/test_daemon.py -q

Local result on macOS: 78 passed, 9 skipped. The skipped cases are existing macOS-specific RPC skips.

Also run:

ruff format --check dimos/protocol/service/zenohservice.py dimos/protocol/service/test_zenohservice.py
ruff check dimos/protocol/service/zenohservice.py dimos/protocol/service/test_zenohservice.py
mypy dimos/protocol/service/zenohservice.py
python -m compileall -q dimos/protocol/service/zenohservice.py dimos/protocol/service/test_zenohservice.py
git diff --check

All passed.

The repository-wide parallel fast suite was attempted locally but was not a clean signal on macOS: unrelated worker/relay/control E2E tests stalled or failed under the 16-worker run, and a serial test_e2e_daemon.py run stalled during worker bootstrap before executing a test. The focused Zenoh/RPC/daemon tests above were rerun after that attempt and remained green. A Linux reproduction of the actual --daemon command remains appropriate in CI or maintainer validation.

AI assistance

OpenAI Codex with GPT-5 assisted with issue analysis, implementation, tests, and PR preparation. The process-lifecycle behavior, two-file diff, and reported validation results were reviewed before submission.

Checklist

  • I have read and approved the CLA.

@github-actions github-actions Bot added the first-time-contributor PR opened by an author who had not previously committed to this repository label Aug 13, 2026
@jiajiayao
jiajiayao marked this pull request as ready for review August 13, 2026 12:09
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

@@            Coverage Diff             @@
##             main    #3457      +/-   ##
==========================================
+ Coverage   74.05%   74.06%   +0.01%     
==========================================
  Files        1283     1283              
  Lines      124704   124729      +25     
  Branches    11141    11142       +1     
==========================================
+ Hits        92349    92383      +34     
+ Misses      29493    29487       -6     
+ Partials     2862     2859       -3     
Flag Coverage Δ
OS-ubuntu-24.04-arm 70.44% <100.00%> (+<0.01%) ⬆️
OS-ubuntu-latest 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.10 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.11 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.12 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.13 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.14 72.22% <100.00%> (+<0.01%) ⬆️
Py-3.14t ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
dimos/protocol/service/test_zenohservice.py 100.00% <100.00%> (ø)
dimos/protocol/service/zenohservice.py 84.12% <100.00%> (+9.79%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

first-time-contributor PR opened by an author who had not previously committed to this repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--daemon + Zenoh: Coordinator RPC service unreachable after daemonize (Dimos.connect / out-of-process clients time out)

1 participant