Skip to content

fix(subscription): allMids() never resolved (release 0.1.6) - #87

Merged
joeblau merged 1 commit into
mainfrom
fix/allmids-subscribe-never-resolves
Jul 28, 2026
Merged

fix(subscription): allMids() never resolved (release 0.1.6)#87
joeblau merged 1 commit into
mainfrom
fix/allmids-subscribe-never-resolves

Conversation

@joeblau

@joeblau joeblau commented Jul 28, 2026

Copy link
Copy Markdown

client.allMids() — with no arguments, or with dex: ""never resolved. It rejected with WebSocketRequestError: Request timed out, or hung forever when timeout was null. Only a non-empty dex worked, so the main-dex mid-price feed — what almost every caller wants — was unusable in 0.1.5.

The chain

  1. allMids.ts builds its payload as { type: "allMids", dex: params.dex || undefined }, so dex exists as an own key holding undefined.
  2. normalize() walks Object.keys() and faithfully recreates that key, so the subscription's normalized form carries dex: undefined.
  3. JSON.stringify drops it on the way out. The server receives {"type":"allMids"} and echoes back exactly that.
  4. 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.

Reproduced against a mock that echoes the subscribe frame verbatim:

allMids()             -> REJECTED: Request timed out after 3000 ms
allMids({dex:''})     -> REJECTED: Request timed out after 3000 ms
allMids({dex:'test'}) -> resolved OK

After the fix all three resolve and deliver frames to the listener.

Why the fix is in normalize()

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, 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 allMids test is mode: "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 unfixed normalize() and passes with it.

Provenance

Found while benchmarking this SDK against upstream @nktkas/hyperliquid, whose allMids works correctly. The divergence is ours, introduced in this fork.

bun run check exits 0; 1681 pass, 236 skip, 0 fail.

🤖 Generated with Claude Code

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>
@joeblau
joeblau merged commit bf2d59f into main Jul 28, 2026
4 checks passed
@joeblau
joeblau deleted the fix/allmids-subscribe-never-resolves branch July 28, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant