You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Three files changed across the Limitless exchange:
client.ts: Replaces three this.orderClient! / this.signer! non-null assertions with explicit if (!x) throw guards in cancelOrder, cancelAllOrders, and getBalance. Error messages are clear and actionable.
normalizer.ts: Replaces two params.start! / params.end! non-null assertions inside their own if (params.start) / if (params.end) blocks with local const bindings. TypeScript narrows correctly when the value is captured before the closure.
websocket.ts: Multiple changes:
Removes buffer.shift()! by assigning to a local and checking.
Refactors the watchOrderBook resolver-push pattern to eliminate Map.get()! calls.
Removes non-null assertions in setupEventHandlers for resolver shift and buffer push.
Blast Radius
Three files in core/src/exchanges/limitless/. The client and normalizer changes are cosmetic safety improvements. The websocket resolver-leak fix and close-cleanup are behavioral changes that affect long-running connections.
Findings
Resolver leak fix is correct. The resolverEntry object is created outside the Promise constructor so it can be referenced by both the wsUpdatePromise and the timeout cleanup. indexOf identity comparison works because it is the same object reference.
close() now rejects pending resolvers -- this is good. Without this, callers awaiting watchOrderBook would hang forever after close().
Mutation concern in websocket.ts:resolvers.splice(idx, 1) mutates the array in-place. This is acceptable here because the array is owned by the Map and only accessed from this module, but it is worth noting as a deviation from immutable patterns.
The buffer.shift() guard (line ~120): After the if (entry) return entry; check, if shift() returned undefined (empty array that passed length > 0 check -- impossible), execution falls through to the rest of the method. This is fine.
Not verified because the websocket resolver-leak fix involves a race condition that requires runtime testing to confirm correctness under concurrent watchOrderBook calls. The logic reads correctly, but races are hard to verify statically.
Semver Impact
patch -- bug fix (resolver leak, close cleanup), no API surface change.
Risk
Medium. The resolver-leak fix changes race semantics in watchOrderBook. Incorrect cleanup could cause a resolver to be resolved after removal, or a timeout to fire on a cleaned-up resolver. The code looks correct, but integration testing is recommended.
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
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.
Fixes #257
Fixes #290
Fixes #303
Fixes #372