Skip to content

Commit d505fa3

Browse files
fix: add retry adapter to requests.Session in batch_validate.py
Stale keep-alive connections in the pool can cause silent hangs when the server closes an idle connection between trace validations. The retry adapter (3 retries, 0.5s backoff) handles connection resets on POST requests automatically, preventing delays mid-batch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dc8b818 commit d505fa3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/altimate-code/src/skills/validate/batch_validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from pathlib import Path
2828

2929
import requests
30+
from requests.adapters import HTTPAdapter
31+
from urllib3.util.retry import Retry
3032
from dotenv import load_dotenv
3133

3234
# ---------------------------------------------------------------------------
@@ -206,7 +208,13 @@ def fetch_traces_by_session_id(session_id):
206208
# ---------------------------------------------------------------------------
207209

208210
# Session reuses TCP connection and SSL handshake across all traces.
211+
# Retry adapter handles stale keep-alive connections being reset mid-batch.
209212
_SESSION = requests.Session()
213+
_adapter = HTTPAdapter(
214+
max_retries=Retry(total=3, allowed_methods=["POST"], backoff_factor=0.5)
215+
)
216+
_SESSION.mount("https://", _adapter)
217+
_SESSION.mount("http://", _adapter)
210218

211219

212220
def validate_trace(trace_id):

0 commit comments

Comments
 (0)