mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
Problem: SSE streams decide first-token time with the admin openai_ttft_mode setting (semantic: first non-lifecycle event; visible: first visible output), but WebSocket passthrough turns always wait for the first ".delta" event and ignore the setting. On reasoning models the reasoning item is announced when reasoning starts while the first delta only arrives after it ends, so in semantic mode a WS turn reports the reasoning time as first-token latency and an HTTP request does not. The same user's WS turns look seconds slower than their HTTP requests, and the gap grows with reasoning tokens while the HTTP numbers stay flat. Fix: let RelayOptions take the first-token rule and have the passthrough adapter pass the configured TTFT mode through the same check the SSE path uses (openAIStreamDataStartsTTFT). codex.* frames are WebSocket-only out-of-band events and never count; terminal events still never count, as before. Without a rule the relay keeps the delta-based behaviour. Test: TestOpenAIWSPassthroughFirstTokenFollowsTTFTMode replays two reasoning turns on one passthrough connection in both modes and expects each turn's first token at the event the SSE rule picks. TestRelay_IsFirstTokenEventDecidesEveryTurnFirstToken checks the relay applies the injected rule per turn and still skips terminal events.