Structured plan-limit errors, handshake fix, and PyPI release workflow#1
Merged
Merged
Conversation
…ached
The client previously reported itself connected as soon as the WebSocket
opened, without waiting for the gateway handshake. A device-limited client
would therefore reconnect in a backoff loop forever, and connect() would
appear to succeed (or time out) with no explanation.
- Wait for the gateway's {"type": "connected"} handshake (or its error)
before reporting success; connect()/connect_sync() now raise a structured
DataNetError for pre-handshake rejections
- Treat device_limit_reached as fatal: stop the reconnect loop instead of
hammering the gateway with retries that can only fail
- Add DataNetError.limit (plan cap that was hit) for device_limit_reached
and the gateway's new topic_limit_reached
- Document all gateway error codes in PROTOCOL.md (when they fire, extra
fields, retryability)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Builds wheel + sdist and publishes to PyPI via OIDC — no token to store or rotate. Requires a one-time pending-publisher registration on pypi.org and a "pypi" environment in repo settings (steps documented in the workflow). 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.
What changed
Bug fix: connect() lied about success, then reconnect-hammered the gateway
The client set its connected state as soon as the WebSocket opened — it never waited for the gateway's
{"type": "connected"}handshake. When the gateway rejected a connection pre-handshake (e.g.device_limit_reached) and closed the socket, the client treated it as a normal drop and reconnected in an exponential-backoff loop forever, whileconnect()/connect_sync()either falsely succeeded or timed out with no explanation.Now:
_await_handshake()waits forconnectedor an error envelope before reporting successdevice_limit_reachedis fatal: the reconnect loop stops, andconnect()/connect_sync()raise the structuredDataNetErrorimmediatelyrate_limited) keep the existing retry behaviorStructured limit errors
DataNetError.limit— the plan cap that was hit, populated fordevice_limit_reachedand the gateway's newtopic_limit_reached(channel cap, e.g. after a tier downgrade)PROTOCOL.mdgains an Error Codes table: every gateway error, its extra fields, and whether it's retryablePyPI release workflow
v*tags build wheel + sdist and publish via Trusted Publishing (OIDC) — no token stored anywhere. One-time setup before the first tag (documented in the workflow file): register a pending publisher on pypi.org fordatanet-sdkand create apypienvironment in repo settings.Why
Plan tiers (Free 100 msg/s / Artist 2,000 / Studio 8,000) are enforced by the gateway; the SDK needs to surface those rejections as actionable errors rather than silent reconnect loops. Matches the equivalent work in datanet-js, so both SDKs behave identically at the protocol level.
Tests
23 passed (7 new: handshake accept/reject/noise-skip, rate_limited fields, topic_limit_reached fields, mid-session fatal error stops the loop, wait_for_connection raises the fatal error immediately).
🤖 Generated with Claude Code