Skip to content

fix(ws): report actually subscribed channels in legacy subscribe response#163

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/ws-legacy-subscribe-partial-response
Open

fix(ws): report actually subscribed channels in legacy subscribe response#163
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/ws-legacy-subscribe-partial-response

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • Issue: The legacy WebSocket subscribe handler (single-slab backward compat path) always returned the full 3-channel array (price, trades, funding) in the subscribed response, even when MAX_GLOBAL_SUBSCRIPTIONS or MAX_SUBSCRIPTIONS_PER_CLIENT caused the loop to break early. Clients believed they were fully subscribed but silently missed trade or funding updates — a silent data loss scenario.
  • Fix: Track actually-subscribed channels in a separate array (mirroring the modern handler's correct pattern) and return only those in the response. Sends an error message when limits cause partial subscription.

Context

The modern subscribe handler (channel-array based) already does this correctly — it builds a subscribed accumulator and returns only that. This fix brings the legacy handler to parity.

Changes

  • src/routes/ws.ts: Legacy subscribe loop now tracks subscribed[], only adds to slab map if >= 1 channel succeeded, returns actual subscriptions, and sends error on partial failure.

Test plan

  • tsc --noEmit passes
  • vitest run passes (186/186 tests)
  • Manual: connect via legacy subscribe with near-limit global subscriptions, verify response reflects actual state

🤖 Generated with Claude Code

…onse

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) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@0x-SquidSol has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 56 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 56 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21e01fed-4441-4697-b8f1-eb7a5f9d4034

📥 Commits

Reviewing files that changed from the base of the PR and between fb94c29 and e75be63.

📒 Files selected for processing (1)
  • src/routes/ws.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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