Skip to content

Add retries for connect failures - #14

Merged
nicot merged 2 commits into
mainfrom
nico/retries
Feb 19, 2026
Merged

Add retries for connect failures#14
nicot merged 2 commits into
mainfrom
nico/retries

Conversation

@nicot

@nicot nicot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

This allows our library to reconnect on failures to fetch prompt templates and other calls to the Freeplay server.

Summary by CodeRabbit

  • Chores

    • Updated project version to 0.5.8.
  • Improvements

    • Added automatic retry behavior for transient HTTP failures, improving request resilience and overall stability without changing public APIs or behavior.

@coderabbitai

coderabbitai Bot commented Feb 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Version bumped 0.5.7 → 0.5.8. Added a module-level Retry configuration and a shared HTTP session in src/freeplay/api_support.py, replacing direct requests.<method> calls with _session.<method> calls to enable automatic retries for transient HTTP failures. Added changelog entry for 0.5.8.

Changes

Cohort / File(s) Summary
Version Bump
pyproject.toml
Updated project version from 0.5.7 to 0.5.8.
HTTP Retry Mechanism
src/freeplay/api_support.py
Added Retry and HTTPAdapter imports, created module-level _retry and _session with adapters mounted for HTTP/HTTPS, and replaced direct requests.post/put/patch/delete/get calls with _session.post/put/patch/delete/get to enable automatic retries.
Changelog
CHANGELOG.md
Added entry for version 0.5.8 documenting automatic retries for transient HTTP connection failures.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant ApiSupport as api_support._session
    participant Remote as Remote API

    Caller->>ApiSupport: make HTTP request (GET/POST/...)
    ApiSupport->>Remote: send request
    alt transient failure
        Remote--x ApiSupport: connection error / timeout
        ApiSupport->>ApiSupport: Retry per _retry policy
        ApiSupport->>Remote: resend request
    end
    Remote-->>ApiSupport: response
    ApiSupport-->>Caller: return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I thumped my paw, a small update to bring,
Retries now bounce when the connections spring,
Version hopped up, no API changed its face,
Requests try again — a gentle, steady pace. 🥕

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add retries for connect failures' directly and clearly describes the main change: implementing retry logic for HTTP connection failures, which aligns with the PR's primary objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nico/retries

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp

macroscopeapp Bot commented Feb 19, 2026

Copy link
Copy Markdown

Add retries for connect failures by routing all freeplay.api_support HTTP calls through a shared requests.Session with HTTPAdapter(max_retries=Retry(connect=3, backoff_factor=0.5))

Introduce a module-level session with retry on connection errors and update all request helpers in api_support.py to use it; bump version to 0.5.8.

📍Where to Start

Start with the session initialization and adapter mounting in api_support.py, then review the switch from requests.* to _session.* in each helper.

Changes since #14 opened

  • Released version 0.5.8 of the freeplay package with automatic retries for transient connection failures on HTTP requests [113763c]

Macroscope summarized 9c6107c.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/freeplay/api_support.py (1)

14-17: Consider adding status_forcelist for server error retries.

The current configuration only retries on connection failures. Server errors (e.g., 502/503/504) that often indicate transient issues won't trigger retries. If the goal is broader resilience, consider:

-_retry = Retry(connect=3, backoff_factor=0.5)
+_retry = Retry(
+    connect=3,
+    read=3,
+    status=3,
+    status_forcelist=[502, 503, 504],
+    backoff_factor=0.5,
+    allowed_methods=["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE", "POST"],
+)

Note: Adding POST to allowed_methods is needed if you want POST requests to retry on status codes (connect retries happen regardless of method).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/freeplay/api_support.py` around lines 14 - 17, The Retry instance named
_retry currently only retries on connection failures; update its constructor to
include a status_forcelist like {502,503,504} and (if you want POSTs retried)
extend allowed_methods to include "POST" so HTTPAdapter(max_retries=_retry) will
also retry on transient server errors; modify the _retry initialization (the
Retry(...) call) to add status_forcelist and allowed_methods and keep the
_session mounting of HTTPAdapter as-is to enable server-error retries for
_session requests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/freeplay/api_support.py`:
- Around line 14-17: The Retry instance named _retry currently only retries on
connection failures; update its constructor to include a status_forcelist like
{502,503,504} and (if you want POSTs retried) extend allowed_methods to include
"POST" so HTTPAdapter(max_retries=_retry) will also retry on transient server
errors; modify the _retry initialization (the Retry(...) call) to add
status_forcelist and allowed_methods and keep the _session mounting of
HTTPAdapter as-is to enable server-error retries for _session requests.

Comment thread pyproject.toml
@nicot
nicot merged commit b3c9b50 into main Feb 19, 2026
5 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Feb 24, 2026
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