Skip to content

feat: add http retries, user-agent, and correlation id#2

Merged
harley-poly merged 3 commits into
mainfrom
harley/sdk-client-resilience
Jun 2, 2026
Merged

feat: add http retries, user-agent, and correlation id#2
harley-poly merged 3 commits into
mainfrom
harley/sdk-client-resilience

Conversation

@harley-poly
Copy link
Copy Markdown
Member

@harley-poly harley-poly commented Jun 2, 2026

summary

hardens the http client (sync + async) for production use:

  • automatic retries with exponential backoff + jitter for idempotent requests (GET/DELETE) on connection errors, timeouts, and 408/409/429/5xx. configurable via max_retries (default 2).
  • non-idempotent requests (order placement, etc.) are never auto-retried, since the api has no idempotency key and a retry could submit a duplicate order.
  • every request now sends a User-Agent (polymarket-us-python/<version>) and a generated poly-correlation-id for server-side tracing.
  • errors now carry request_id (from the response or the generated correlation id) alongside the existing status_code/body.

no Retry-After/X-RateLimit-* headers are emitted by the api today, so backoff is purely client-side (the parser honors Retry-After defensively if it ever appears).

test plan

  • ruff check / ruff format --check
  • mypy polymarket_us
  • pytest (126 passed; new tests/test_retries.py covers retry-then-succeed, exhausted retries, connect-error retry, post-not-retried, 4xx-not-retried, request-id, and header propagation; sync + async)

Note

Medium Risk
Touches core request paths for trading clients; POST skip-on-retry is intentional but behavior change for timeouts/5xx on reads vs writes.

Overview
Hardens the sync and async HTTP clients for production: automatic retries (configurable max_retries, default 2) on transient failures for idempotent methods only (GET/DELETE and similar), with client-side exponential backoff and jitter; POST (e.g. order placement) is never auto-retried to avoid duplicate submissions without idempotency keys.

Adds shared polymarket_us/_retry.py, sends User-Agent and per-request poly-correlation-id, and surfaces request_id on APIError subclasses (from response headers or the generated correlation id). Connection handling broadens from ConnectError to TransportError.

README documents retries and tracing; new tests/test_retries.py covers retry/backoff/header behavior; HTTP error tests use max_retries=0; auth test fixes 64-byte key fixture encoding.

Reviewed by Cursor Bugbot for commit 56ca841. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread polymarket_us/_retry.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2f8c1ff. Configure here.

Comment thread polymarket_us/client.py
@harley-poly harley-poly merged commit aa38c16 into main Jun 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants