fix(broker): don't broadcast peer_joined/peer_left/peer_returned to same-pubkey sessions
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

When a user opens multiple Claude Code instances on one laptop they
all share the same memberPubkey (one identity, one config.json). The
broker was broadcasting each Claude Code start/stop to every OTHER
session of the same user — showing as 'peer agutierrez left / joined'
spam in every active claude terminal.

Now: skip broadcast to presences whose memberPubkey equals the joining
or leaving presence's memberPubkey. Other actual peers on the mesh
still see the event.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-15 14:28:57 +01:00
parent 6f4a44e281
commit 3dfab0f792

View File

@@ -2001,6 +2001,10 @@ function handleConnection(ws: WebSocket): void {
for (const [pid, peer] of connections) { for (const [pid, peer] of connections) {
if (pid === presenceId) continue; if (pid === presenceId) continue;
if (peer.meshId !== joinedConn.meshId) continue; if (peer.meshId !== joinedConn.meshId) continue;
// Don't spam the user's own other sessions about themselves —
// multiple Claude Code instances from one laptop all share the
// same memberPubkey, so they're the same human identity.
if (peer.memberPubkey === joinedConn.memberPubkey) continue;
sendToPeer(pid, joinMsg); sendToPeer(pid, joinMsg);
} }
// Restore persistent MCP servers owned by this member // Restore persistent MCP servers owned by this member
@@ -4162,6 +4166,9 @@ function handleConnection(ws: WebSocket): void {
}; };
for (const [pid, peer] of connections) { for (const [pid, peer] of connections) {
if (peer.meshId !== conn.meshId) continue; if (peer.meshId !== conn.meshId) continue;
// Don't tell the user's own other sessions they "left" when one
// of their Claude Code instances closes. Same pubkey = same user.
if (peer.memberPubkey === conn.memberPubkey) continue;
sendToPeer(pid, leaveMsg); sendToPeer(pid, leaveMsg);
} }
} }