fetchWithRetry:
- Dynamically calculate maxAttempts = pool.size + 1 (direct fallback)
- Try every proxy in pool via rotation, then direct as last resort
- Only classify as error when even direct produces no response
fetchWithSessionRetry:
- Default maxRetries = sessionPool.size + 1 instead of hardcoded 3
- Try pool.size proxy attempts (each on a different proxy via rotateNow),
then 1 direct attempt (no proxy) before giving up
- Only classify as error if direct also returns no response
ProxyPool.rotate():
- Skip proxies that have exceeded the failure threshold (isFailed)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add rotateNow() to SessionProxyPool — force-rotate session to a
different proxy immediately (excludes current index to ensure real
rotation). Uses round-robin scan from oldIndex+1 so all proxies
get used, not just bouncing between two.
- fetchWithSessionRetry: call rotateNow() on every failure instead of
markFailed() which only rotated after threshold. Return last HTTP
response (e.g. 429) instead of classifying as 502 when we have one.
- fetchWithRetry: rotate pool on every failure for consistency.
Co-Authored-By: Claude <noreply@anthropic.com>
- fetch-utils.ts: logProxy() — logs every attempt, proxy used, success/failure
with sessionId prefix for traceability
- proxy-pool.ts: logPool() — logs acquire/release/rotate/markFailed/markSuccess
with active session count and proxy host info
- Both use consistent [prefix] HH:MM:SS.mmm key=value format
Co-Authored-By: Claude <noreply@anthropic.com>
- fetchWithRetry: use proxy on every attempt (not just fallback after direct)
- fetchWithSessionRetry: call acquire() on attempt 0 so new sessions get
a least-loaded proxy assigned, enabling IP spread across concurrent users
- Update docstrings to reflect new strategy
Co-Authored-By: Claude <noreply@anthropic.com>
Add SessionProxyPool for per-session sticky proxy allocation with
load-balanced least-used selection and auto-rotation on failure.
Introduce fetchWithSessionRetry for transparent retry with proxy
rotation. Wire into AI proxy handlers (OpenAI + Anthropic) with
stream lifecycle cleanup.
Co-Authored-By: Claude <noreply@anthropic.com>
Introduce a centralized `fetch-utils.ts` to handle retry logic with proxy fallback, SSE line buffering to prevent chunk-boundary corruption, and graceful shutdown via active reader tracking.
Key changes:
- Add `fetchWithRetry` for automatic direct-to-proxy failover.
- Implement `SSELineBuffer` to ensure reliable parsing of split SSE chunks.
- Add `createStreamBodyLimiter` to enforce payload limits on streaming requests.
- Refactor `ProxyPool` to decouple failure marking from rotation.
- Standardize CORS handling and environment variable configuration.
- Clean up documentation and remove obsolete skill files.