mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
The gate withholds the HTTP response until the first event that also counts as committed output on the buffered path, so both paths agree on failover status. While it is closed nothing reaches the client — not even a keepalive, since the first byte commits the 200 — and a turn here runs in a real browser that can think for a long time, so a client with an idle timeout could hang up on a perfectly healthy turn. Race the gate against CHATGPT_SESSION_STREAM_OPEN_TIMEOUT_MS (30s, overridable per call through the new options argument). A committing event or an error still wins exactly as before; only when the deadline elapses with neither does the stream open anyway and keep consuming the same iterator, replaying the buffered reasoning after the role chunk so nothing is lost or reordered. The in-flight next() the deadline outran is carried into the stream body instead of being abandoned, otherwise its event would vanish behind a second next(). The timer is unref'd and cleared on every exit path. Every failure that needs a real HTTP status — no browser, missing or expired credentials, rate limiting, an incompatible route — surfaces within seconds, far inside the window.