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
{{ message }}
Repository navigation
WS: stale orderbook frames mutate local book before subscription-existence check #255
Frames arriving with an old sid after resubscribe_one tears down the book and assigns a new sid (or after a server-initiated unsubscribe reaped the sub) still get applied to the local OrderbookManager. A stale snapshot can re-create a book under the old sid index and a stale delta can mutate the freshly-resynced book under the same ticker, producing inconsistent state that the consumer's get(ticker) reads.
Location
kalshi/ws/client.py:322-336 — apply happens before sid check
# client.py _process_frame:ifmsg_type=="orderbook_snapshot"andself._orderbook_mgr:
snapshot=OrderbookSnapshotMessage.model_validate(data)
self._orderbook_mgr._apply_snapshot_inplace(snapshot, sid=snapshot.sid)
pre_validated=snapshotelifmsg_type=="orderbook_delta"andself._orderbook_mgr:
delta=OrderbookDeltaMessage.model_validate(data)
self._orderbook_mgr._apply_delta_inplace(delta)
# Apply happens BEFORE dispatch.py:240-243 which drops unknown sid.
Recommended fix
Gate the orderbook-apply on self._sub_mgr.get_subscription_by_sid(sid) is not None before validating + mutating. Stale-sid frames should hit the dispatcher's existing debug-log path and short-circuit without touching the book.
Activity