Skip to content

feat: add backoff on auth for 429/5xx responses#95

Open
jajeffries wants to merge 3 commits into
developfrom
obs-3341-diode-sdk-add-backoff-on-auth-for-4295xx-responses
Open

feat: add backoff on auth for 429/5xx responses#95
jajeffries wants to merge 3 commits into
developfrom
obs-3341-diode-sdk-add-backoff-on-auth-for-4295xx-responses

Conversation

@jajeffries

Copy link
Copy Markdown
Contributor

Summary

Add retry/backoff on the OAuth2 token HTTP call when the auth endpoint returns transient failures.

What changed

  • Retry /auth/token on 429, 500, 502, and 503 only; other 4xx fail immediately
  • Exponential backoff (1s initial, 30s cap) with random jitter (0–25% of delay)
  • Honour Retry-After on 429 and 503 when present (seconds or HTTP-date), capped at 30s
  • Respect existing DIODE_MAX_AUTH_RETRIES for total auth HTTP attempts (default 3)
  • Document DIODE_MAX_AUTH_RETRIES in README
  • Unit tests for retriable status codes, delay calculation, and mocked retry behaviour

How tested

  • pytest tests/test_client.py
  • ruff check / ruff format on changed files

Made with Cursor

Retry OAuth token fetch on transient HTTP failures with exponential
backoff, jitter, and Retry-After support while honouring DIODE_MAX_AUTH_RETRIES.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/netboxlabs/diode/sdk
   chunking.py33197%112
   client.py5684293%196–197, 216–218, 221–224, 482, 545, 550, 554, 627–632, 675–677, 707, 711, 715, 734, 753, 755, 825, 852, 860, 915–916, 922, 952, 977, 982–983, 1016, 1021–1024
   exceptions.py44393%69, 82–83
TOTAL6604693% 

Tests Skipped Failures Errors Time
203 0 💤 0 ❌ 0 🔥 2.103s ⏱️

@jajeffries

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44d170a709

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread netboxlabs/diode/sdk/client.py Outdated
Apply jitter before the final min() so sleeps never exceed the
configured max delay cap.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jajeffries

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 45c7360e18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Restore develop formatting in client.py and test_client.py while keeping
the OAuth retry/backoff behaviour, helper functions, README note, and tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants