Skip to content

fix: run one moss node per process, not per conversation - #39

Merged
ForeverInLaw merged 2 commits into
mainfrom
fix/one-node-per-process
Jul 29, 2026
Merged

fix: run one moss node per process, not per conversation#39
ForeverInLaw merged 2 commits into
mainfrom
fix/one-node-per-process

Conversation

@ForeverInLaw

Copy link
Copy Markdown
Contributor

What

0.7.3 put every DM on one moss node. Public channels, private groups and orgs
each still started their own. Node identity is per process, so a client sitting
in three channels and two groups announced one peer id from six ports — the
exact pattern 0.7.3 measured: a remote peer keeps one session per identity,
closes the rest on arrival, and declines to dial the others because it already
holds that id.

Channels, groups and orgs now join a room on the same node the DMs use. A whole
client is one node, one port.

How

  • New mosh-core/src/shared_node.rs: SharedMossNode owns the process's node,
    refcounted — acquire starts it on first demand, the last release stops it.
    Born in mosh-dm/1, the room DM nodes have used since 0.7.3, so the substrate
    a released client sees does not move.
  • src-tauri/src/lib.rs hands the SAME holder to all four runtimes.
  • Channels/groups/orgs: join_room + subscribe_room on open, publish_room
    on every send, unsubscribe_room + leave_room + release on close.
  • from_shared still mints a private holder, so tests running two peers in one
    process keep two nodes.

Wire-compatible: a joined room is byte-identical to the same room owned
outright, so 0.7.4 still talks to 0.7.3 and 0.7.2.

Also fixed

  • Closing a channel/group/org kept its subscriptions alive. With a node per
    conversation, dropping the node ended them. On a shared node it has to be said
    out loud.
  • The joiner's first KeyPackage went to the wrong room. accept_invite
    published it room-less, which since 0.7.3 means the shared node's substrate
    room rather than the invite's. The handshake only recovered because the drain
    loop re-publishes it correctly until the Welcome arrives.

Tests

cargo test -p mosh-core: 190 passed, 0 failed, 5 ignored (real moss.dll).

New, mirroring the existing DM test:

  • channels_share_one_node_and_leave_releases_it
  • groups_share_one_node_and_close_releases_it

Each asserts one node pointer across two conversations, distinct mesh_ids, and
that the node survives the first close but not the last.

Manual check after release

Open two DMs, two public channels and a group — Diagnostics must show the same
Listen port for all of them. A different port anywhere means a room-less publish
survived; it will show as MOSS_ERR_NOT_IN_ROOM (-14) in the log rather than
silently lost messages.

Not in this PR

The relay node keeps its own node (own mesh, own callbacks, own send worker).
That is one extra port under the same identity, not N.

0.7.3 consolidated DMs onto a single node; public channels, private
groups and orgs each still started their own. Node identity is per
process, so a client in three channels and two groups announced one peer
id from six ports — a remote peer keeps one session per identity, closes
the rest on arrival and declines to dial the others.

Channels, groups and orgs now join a room on the shared node
(SharedMossNode holds it, refcounted; the last release stops moss).
Every publish is room-scoped, and closing a conversation unsubscribes
and leaves its room, which dropping a per-conversation node used to do.

Also fixes accept_invite publishing its first KeyPackage room-less,
i.e. into the shared node's substrate room instead of the invite's.

Wire-compatible: a joined room is byte-identical to the same room owned
outright, so 0.7.4 still talks to 0.7.3 and 0.7.2.
@ForeverInLaw
ForeverInLaw merged commit bd21826 into main Jul 29, 2026
3 checks passed
@ForeverInLaw
ForeverInLaw deleted the fix/one-node-per-process branch July 29, 2026 14:24
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.

1 participant