Skip to content

WS: KalshiBackpressureError lacks structured channel/sid/client_id fields #256

Description

@TexasCoding

Summary

Consumer code that iterates a subscribe queue sees except KalshiBackpressureError as e with only str(e) — no way to discriminate which channel/sid/client_id overflowed when multiple subscriptions exist. The error must be parsed from the message string, which is brittle and breaks the structured-error contract #226 established for KalshiSequenceGapError and KalshiSubscriptionError.

Location

  • kalshi/errors.py:121-122 — bare class, no fields
  • kalshi/ws/channels.py:537-551 — broadcast site
  • kalshi/ws/backpressure.py:78-86 — raise site

Evidence

class KalshiBackpressureError(KalshiWebSocketError):
    """Message queue overflow with ERROR strategy."""
    # no __init__, no fields

Compare KalshiSequenceGapError which carries channel, sid, client_id, last_seq, next_seq.

Recommended fix

Add __init__ with channel, sid, client_id, maxsize keyword-only fields; populate them at the put() raise site in backpressure.py:78-86 and at the broadcast_error site so the iterator's except block can route by channel.

Severity & category

medium / api-design, ws

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwsWebSocket-related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions