Skip to content

Commit e9a4eb6

Browse files
varun369claude
andcommitted
fix: WS peer UDS routing for bi-directional cross-machine mesh
Remote peers connected via WebSocket no longer trigger futile UDS socket connections. Added hasRemotePeer() check — peers with an active WS connection skip push.connect() and route via WS-first. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1e09afb commit e9a4eb6

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to SLM Mesh will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.3] - 2026-05-22
9+
10+
### Fixed
11+
- **WebSocket peer routing bug** — Remote peers connected via WS no longer trigger futile UDS socket connections. The broker now checks `hasRemotePeer()` before attempting UDS, and routes messages via WS for remote peers (WS-first, UDS fallback). Fixes bi-directional cross-machine messaging.
12+
813
## [1.3.2] - 2026-05-22
914

1015
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "slm-mesh",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Peer-to-peer communication for AI coding agents — by Qualixar, powered by SuperLocalMemory",
55
"author": "Varun Pratap Bhardwaj",
66
"license": "Elastic-2.0",

src/broker/handlers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function createHandlers(deps: HandlerDeps) {
247247

248248
stmtInsertPeer.run(peerId, name, pid, projectPath, gitRoot, gitBranch, agentType, udsPath);
249249

250-
if (udsPath) {
250+
if (udsPath && !wsServer?.hasRemotePeer(peerId)) {
251251
push.connect(peerId, udsPath);
252252
}
253253

@@ -368,7 +368,10 @@ export function createHandlers(deps: HandlerDeps) {
368368
payload: { messageId: msgId, fromPeer, text: payload },
369369
timestamp: ts,
370370
};
371-
const delivered = push.send(peer.id, notification) || (wsServer?.sendToPeer(peer.id, notification) ?? false);
371+
// Try WS first if this is a remote peer, fall back to UDS
372+
const delivered = (wsServer?.hasRemotePeer(peer.id) && wsServer?.sendToPeer(peer.id, notification))
373+
|| push.send(peer.id, notification)
374+
|| (wsServer?.sendToPeer(peer.id, notification) ?? false);
372375
/* v8 ignore next 3 -- requires active push connection for broadcast */
373376
if (delivered) {
374377
stmtMarkDelivered.run(msgId);
@@ -426,7 +429,10 @@ export function createHandlers(deps: HandlerDeps) {
426429
payload: { messageId, fromPeer, text: payload },
427430
timestamp: ts,
428431
};
429-
const delivered = push.send(toPeer, notification) || (wsServer?.sendToPeer(toPeer, notification) ?? false);
432+
// Try WS first if this is a remote peer, fall back to UDS
433+
const delivered = (wsServer?.hasRemotePeer(toPeer) && wsServer?.sendToPeer(toPeer, notification))
434+
|| push.send(toPeer, notification)
435+
|| (wsServer?.sendToPeer(toPeer, notification) ?? false);
430436
if (delivered) {
431437
stmtMarkDelivered.run(messageId);
432438
}

src/broker/push/ws-server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface WsServer {
1515
stop(): Promise<void>;
1616
broadcast(data: unknown): void;
1717
sendToPeer(peerId: string, data: unknown): boolean;
18+
hasRemotePeer(peerId: string): boolean;
1819
readonly clientCount: number;
1920
}
2021

@@ -153,11 +154,16 @@ export function createWsServer(
153154
}
154155
}
155156

157+
function hasRemotePeer(peerId: string): boolean {
158+
return _peerMap.has(peerId);
159+
}
160+
156161
return {
157162
start,
158163
stop,
159164
broadcast,
160165
sendToPeer,
166+
hasRemotePeer,
161167
get clientCount(): number {
162168
return clients.size;
163169
},

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface MeshConfig {
4646
readonly walCheckpointIntervalMs: number;
4747
}
4848

49-
export const VERSION = '1.3.2';
49+
export const VERSION = '1.3.3';
5050
export const PRODUCT_NAME = 'SLM Mesh';
5151
export const BRANDING = `${PRODUCT_NAME} v${VERSION} | Part of the Qualixar research initiative`;
5252

0 commit comments

Comments
 (0)