- 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>
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.
- Add src/lib/proxy-pool.ts: round-robin proxy pool that reads
proxy.txt (host:port:user:pass), tracks consecutive failures,
and rotates on threshold
- Integrate into src/index.ts: on fetch network error, mark proxy
as failed, rotate to next, and retry the request once
- proxy.txt loaded from PROXY_FILE/PROXY_LIST env var or ./proxy.txt
- Graceful no-op when proxy.txt doesn't exist (Vercel/Workers)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>