fix(subscription): allMids() never resolved (release 0.1.6) - #87
Merged
Conversation
Release 0.1.6.
`client.allMids()` — with no arguments, or with `dex: ""` — never resolved.
It rejected with `WebSocketRequestError: Request timed out` after the
configured timeout, or hung forever when `timeout` was null. Only a
non-empty `dex` worked, so the main-dex mid-price feed, which is what
almost every caller wants, was unusable.
The chain:
- `allMids.ts` builds its payload as `{ type: "allMids", dex: params.dex
|| undefined }`, so `dex` is an own key holding `undefined`.
- `normalize()` walks `Object.keys()` and faithfully recreates that key,
so the subscription's normalized form carries `dex: undefined`.
- `JSON.stringify` drops it on the way out, so the server receives
`{"type":"allMids"}` and echoes back exactly that.
- `isSubset` requires every key of the pending request to be present in
the response (`key in sup`). It looks for a `dex` the server was never
told about, finds nothing, and the subscription is never matched to its
own confirmation.
Fixed in `normalize()` rather than in `allMids`: a key whose value is
`undefined` cannot survive serialization, so keeping it leaves the
in-memory identity describing a request that was never sent. Dropping it
makes the id, the echo and the wire frame agree, and immunizes any future
payload built with the same `x || undefined` shape. `allMids` is the only
method using it today.
No test caught this because the only `allMids` test is `mode: "api"` and
needs the live network, so it is skipped in the offline suite CI runs. The
regression test added here covers the root cause and runs offline; it was
verified to fail against the unfixed normalize().
Found while benchmarking against upstream @nktkas/hyperliquid, whose
allMids works correctly — the divergence is ours.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
client.allMids()— with no arguments, or withdex: ""— never resolved. It rejected withWebSocketRequestError: Request timed out, or hung forever whentimeoutwasnull. Only a non-emptydexworked, so the main-dex mid-price feed — what almost every caller wants — was unusable in 0.1.5.The chain
allMids.tsbuilds its payload as{ type: "allMids", dex: params.dex || undefined }, sodexexists as an own key holdingundefined.normalize()walksObject.keys()and faithfully recreates that key, so the subscription's normalized form carriesdex: undefined.JSON.stringifydrops it on the way out. The server receives{"type":"allMids"}and echoes back exactly that.isSubsetrequires every key of the pending request to be present in the response (key in sup). It looks for adexthe server was never told about, finds nothing, and the subscription is never matched to its own confirmation.Reproduced against a mock that echoes the subscribe frame verbatim:
After the fix all three resolve and deliver frames to the listener.
Why the fix is in
normalize()A key whose value is
undefinedcannot survive serialization, so keeping it leaves the in-memory identity describing a request that was never sent. Dropping it makes the id, the echo, and the wire frame agree — and immunizes any future payload built with the samex || undefinedshape.allMidsis the only method using it today, so the blast radius is small either way, but the root cause is the normalizer, not the method.Why no test caught it
The only
allMidstest ismode: "api"— it needs the live network and is skipped in the offline suite CI runs. So the bug sat in a path CI never exercised. The regression test added here covers the root cause and runs offline; I verified it fails against the unfixednormalize()and passes with it.Provenance
Found while benchmarking this SDK against upstream
@nktkas/hyperliquid, whoseallMidsworks correctly. The divergence is ours, introduced in this fork.bun run checkexits 0; 1681 pass, 236 skip, 0 fail.🤖 Generated with Claude Code