feat: add http retries, user-agent, and correlation id#2
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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.
mustafa-poly
approved these changes
Jun 2, 2026
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.

summary
hardens the http client (sync + async) for production use:
GET/DELETE) on connection errors, timeouts, and408/409/429/5xx. configurable viamax_retries(default 2).User-Agent(polymarket-us-python/<version>) and a generatedpoly-correlation-idfor server-side tracing.request_id(from the response or the generated correlation id) alongside the existingstatus_code/body.no
Retry-After/X-RateLimit-*headers are emitted by the api today, so backoff is purely client-side (the parser honorsRetry-Afterdefensively if it ever appears).test plan
ruff check/ruff format --checkmypy polymarket_uspytest(126 passed; newtests/test_retries.pycovers 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/DELETEand 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, sendsUser-Agentand per-requestpoly-correlation-id, and surfacesrequest_idonAPIErrorsubclasses (from response headers or the generated correlation id). Connection handling broadens fromConnectErrortoTransportError.README documents retries and tracing; new
tests/test_retries.pycovers retry/backoff/header behavior; HTTP error tests usemax_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.