From e75be63d0fe3d53d37537bff1a001f8e6d34a7fe Mon Sep 17 00:00:00 2001 From: 0X-SquidSol Date: Thu, 9 Apr 2026 12:48:12 -0400 Subject: [PATCH] fix(ws): report actually subscribed channels in legacy subscribe response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The legacy subscribe handler (single-slab backward compatibility path) always sent the full 3-channel array in the response, even when globalSubscriptionCount or per-client limits caused the loop to break early. Clients believed they were subscribed to all channels but silently missed trade or funding updates — a silent data loss scenario. The modern subscribe handler already correctly tracks and returns only the channels that were actually added. This fix applies the same pattern to the legacy handler: - Track subscribed channels in a separate array - Only add client to slab map if at least one channel succeeded - Return only actually-subscribed channels in the response - Send an error message when limits cause partial subscription Co-Authored-By: Claude Opus 4.6 (1M context) --- src/routes/ws.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/routes/ws.ts b/src/routes/ws.ts index d2ba32a..3e3a2de 100644 --- a/src/routes/ws.ts +++ b/src/routes/ws.ts @@ -926,17 +926,24 @@ export function setupWebSocket(server: Server): WebSocketServer { message: "Please use channels array. Subscribing to all channels for this slab." })); + const subscribed: string[] = []; for (const channel of channels) { if (client.subscriptions.has(channel)) continue; if (globalSubscriptionCount >= MAX_GLOBAL_SUBSCRIPTIONS) break; if (client.subscriptions.size >= MAX_SUBSCRIPTIONS_PER_CLIENT) break; - + client.subscriptions.add(channel); globalSubscriptionCount++; + subscribed.push(channel); + } + + if (subscribed.length > 0) { + addClientToSlab(client, sanitized); + } + ws.send(JSON.stringify({ type: "subscribed", slabAddress: sanitized, channels: subscribed })); + if (subscribed.length < channels.length) { + ws.send(JSON.stringify({ type: "error", message: "Subscription limit reached — some channels were not subscribed" })); } - - addClientToSlab(client, sanitized); - ws.send(JSON.stringify({ type: "subscribed", slabAddress: sanitized, channels })); } // Handle unsubscribe with channels array else if (msg.type === "unsubscribe" && msg.channels && Array.isArray(msg.channels)) {