Skip to content

UN-3230 [FEAT] Implement back-off retry mechanism for API deployment client#12

Open
muhammad-ali-e wants to merge 6 commits intomainfrom
feat/UN-3230-FEAT_implement_backoff_retry_mechanism
Open

UN-3230 [FEAT] Implement back-off retry mechanism for API deployment client#12
muhammad-ali-e wants to merge 6 commits intomainfrom
feat/UN-3230-FEAT_implement_backoff_retry_mechanism

Conversation

@muhammad-ali-e
Copy link
Contributor

@muhammad-ali-e muhammad-ali-e commented Feb 11, 2026

What

  • Added exponential back-off retry mechanism with full jitter to APIDeploymentsClient
  • New constructor params: max_retries, initial_delay, max_delay, backoff_factor
  • Migrated build tooling from PDM to uv (hatchling backend)

Why

  • Transient server errors (5xx) and rate limits (429) can cause unnecessary failures
  • Automatic retries with exponential backoff improve reliability without manual intervention
  • Full jitter prevents thundering herd when multiple clients retry simultaneously
  • uv is significantly faster than PDM for dependency resolution and installs, and aligns with the broader ecosystem trend

How

  • Custom retry logic in _request_with_retry() wrapping all HTTP calls
  • Exponential backoff: min(initial_delay * backoff_factor^attempt, max_delay) with full jitter
  • Respects Retry-After header for 429 responses
  • Async mode (timeout=0) retries POST requests; sync mode skips POST retries to avoid duplicates
  • File objects are rewound (seek(0)) before each retry attempt
  • Comprehensive test suite with 40+ test cases covering all retry scenarios
  • Replaced PDM build backend with hatchling in pyproject.toml
  • Replaced pdm.lock with uv.lock
  • Updated CI workflow (.github/workflows/main.yml) to use uv instead of PDM
  • Updated .pre-commit-config.yaml to use uv-lock hook instead of pdm-lock-check
  • Updated .gitignore with uv-specific entries

Can this PR break any existing features. If yes, please list possible items. If no, please explain why.

  • No. All retry parameters have sensible defaults matching previous behavior. Setting max_retries=0 disables retries entirely. The PDM→uv migration is a build tooling change only; the published package remains identical.

Database Migrations

  • None

Env Config

  • None

Relevant Docs

Related Issues or PRs

Dependencies Versions

  • No new runtime dependencies (uses only stdlib random, time, and existing requests)
  • Build tooling: PDM → uv (hatchling backend)

Notes on Testing

  • 40+ unit tests in tests/test_retry.py covering: defaults, retryable status codes, delay calculation, connection errors, retry exhaustion, non-retryable codes, Retry-After header, file seek on retry, disabled retry, async vs sync mode behavior
  • CI pipeline updated to run with uv

Screenshots

N/A

Checklist

I have read and understood the Contribution Guidelines.

muhammad-ali-e and others added 2 commits February 11, 2026 10:11
…client

Add exponential back-off retry with full jitter to APIDeploymentsClient
for improved reliability against transient 5xx errors and 429 rate limits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Version updates are handled separately during the release process.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
muhammad-ali-e and others added 3 commits February 11, 2026 12:18
- Add python-dotenv to both PDM and uv dev dependencies so
  tests/client_test.py can run standalone without ModuleNotFoundError
- Fix pre-commit default Python version from python3.9 to python3
- Refine structure_file pending detection: only set pending=True on
  2xx responses (POST 422 indicates setup errors, not queued work)
- Fix trailing newlines in utils.py and sample.env
- Update tests to match new 422 pending behavior and fix docstring
  formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pyproject.toml Outdated
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[dependency-groups]
Copy link
Contributor

Choose a reason for hiding this comment

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

@muhammad-ali-e Why "python-dotenv added in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's dev dependancy for test

]

[tool.pdm.dev-dependencies]
test = [
Copy link
Contributor

Choose a reason for hiding this comment

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

@muhammad-ali-e it looks like this project is not migrated into uv yet. so please migrate it into UV first. no need to keep both pdm and uv in one place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do that as another task

Copy link
Contributor

@jaseemjaskp jaseemjaskp left a comment

Choose a reason for hiding this comment

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

Migrate this project entirely into uv . it looks like you already added the lock file and some of the pyproject.toml file changed into UV

sdist = { url = "https://files.pythonhosted.org/packages/e0/2d/a891ca51311197f6ad14a7ef42e2399f36cf2f9bd44752b3dc4eab60fdc5/certifi-2026.1.4.tar.gz", hash = "sha256:ac726dd470482006e014ad384921ed6438c457018f4b3d204aea4281258b2120", size = 154268, upload-time = "2026-01-04T02:42:41.825Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/e6/ad/3cc14f097111b4de0040c83a525973216457bbeeb63739ef1ed275c1c021/certifi-2026.1.4-py3-none-any.whl", hash = "sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c", size = 152900, upload-time = "2026-01-04T02:42:40.15Z" },
]
Copy link
Contributor

Choose a reason for hiding this comment

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

@muhammad-ali-e better to migrate into UV. because you already added uv.lock. Refere llmwhisperer python client if any doubts and make sure all pdm related mentions removed from pyproject.toml and remove pdm.lock

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
with:
python-version: 3.11
version: 2.10.0
python-version: "3.12"
Copy link
Contributor

Choose a reason for hiding this comment

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

@muhammad-ali-e you can pin the python version here https://github.com/astral-sh/setup-uv. no need to setup python separately

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.

4 participants