You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenRouter (openai-chat adapter): streaming delivers tokens in batches, not live #114
Streaming works correctly with ChatGPT passthrough (openai-responses adapter) but delivers tokens in batches (only at the end) with OpenRouter models using the openai-chat adapter.
Environment
opencodex 2.7.8
macOS (Apple Silicon)
Codex Desktop (latest)
OpenRouter API
Steps to reproduce
Install opencodex with default config (ChatGPT passthrough + OpenRouter with openai-chat adapter)
Use a ChatGPT model (e.g. gpt-5.6-luna): streaming works token-by-token ✅
Switch to an OpenRouter model (e.g. openrouter/deepseek/deepseek-v4-flash): response appears all at once at the end ❌
Switch to a ChatGPT model routed through OpenRouter (e.g. openrouter/gpt-5.6-luna): also delayed ❌
What we tried
websockets: false in config: no change, streaming still delayed
Direct openai-responses adapter to OpenRouter Responses API (https://openrouter.ai/api/v1/responses): OpenRouter returned errors, likely because Codex sends proprietary namespace tool types (see openai/codex#32318)
Debug logs show correct SSE deltas
ocx debug provider on shows that opencodex produces correct token-by-token response.output_text.delta SSE frames:
So the bridge/translation layer produces correct SSE deltas — the chunks appear to be buffered at the OpenRouter level or between opencodex and the client.
Suspected cause
OpenRouter SSE streaming in the openai-chat adapter path delivers chunks in larger batches rather than individual tokens, or there is buffering in the async generator → SSE stream pipeline. The fact that ChatGPT passthrough (direct openai-responses adapter) streams perfectly suggests this is specific to the openai-chat adapter path with OpenRouter.
Thanks for the fix in #115. I retested this end-to-end with the current release, and unfortunately the real Codex Desktop path is still batching the final answer.
Environment:
opencodex 2.7.13
Codex Desktop bundled codex-cli 0.144.2
macOS / Apple Silicon
openai-chat adapter (opencode-go/deepseek-v4-flash for this reproduction)
websockets: false
I tested at two different layers:
A simple curl --no-buffer request directly to http://127.0.0.1:10100/v1/responses can now stream continuously. For a long 1..500 response, chunks arrived over several seconds, generally every 20–40 ms.
I then ran the exact app-server binary bundled with Codex Desktop (/Applications/ChatGPT.app/Contents/Resources/codex app-server), started a thread with opencode-go/deepseek-v4-flash, sent the same 1..500 prompt, and timestamped the documented item/agentMessage/delta notifications.
So after reasoning completed, the bundled Codex app-server received 999 text deltas in only 28.7 ms. This exactly matches what Codex Desktop displays: the model thinks for a while, then the entire final answer appears at once.
This also rules out the Desktop renderer as the primary cause—the app-server itself receives the final text as an end burst. The Accept-Encoding: identity change is present locally, but it does not resolve batching for the full production Codex request shape (instructions, tools, reasoning, etc.). The simpler direct proxy request is therefore not representative of the actual Codex Desktop path.
Could this issue please be reopened? I can provide the small Node app-server timing probe if useful.
Retested with opencodex 2.7.17 after #123. The DeepSeek path is now streaming progressively in the real Codex Desktop/app-server flow.
Two actual Codex Desktop turns used the same long response shape (integers 1 through 500):
Model
Total turn duration
Time to first token
First-token-to-completion window
opencode-go/minimax-m3
17,938 ms
17,897 ms
41 ms
opencode-go/deepseek-v4-flash
17,836 ms
15,907 ms
1,929 ms
I also reran the standalone E2E probe against the Codex Desktop bundled app-server with opencode-go/deepseek-v4-flash. It timestamped every item/agentMessage/delta notification:
Before #123, the same probe delivered all 999 deltas in only 28.7 ms at the end. With 2.7.17, those deltas are spread across 1,253.2 ms, so #123 fixes the reported coalescing problem for DeepSeek/OpenRouter in the full Codex Desktop path.
MiniMax M3 still behaves like an end burst (only 41 ms from first token to completion). My current interpretation is that MiniMax or its adapter supplies one large text delta, or only a few large deltas, so the bridge has no finer-grained event sequence to flush. That appears distinct from the same-turn multi-event coalescing fixed by #123.
Thanks for the thorough re-test — great to see the delta spread jump from 28.7 ms to 1,253 ms on the DeepSeek path.
On MiniMax M3: the 41 ms first-token-to-completion window is not a regression introduced by this PR. MiniMax (or its OpenRouter adapter) produces only a small number of large text deltas upstream, so the bridge has no finer-grained event sequence to flush — it is faithfully forwarding what it receives. The behaviour is provider-side, not a coalescing bug in the proxy layer. A separate issue or PR targeting MiniMax specifically would be the right place to address that if needed.
Activity
Wibias commentedon Jul 12, 2026
@RobinBially Should hopefully get fixed by #115 either u build urself with the change or wait for a new version!
fix(upstream): suppress Accept-Encoding to prevent SSE buffering via …
robin-bially commentedon Jul 13, 2026
Thanks for the fix in #115. I retested this end-to-end with the current release, and unfortunately the real Codex Desktop path is still batching the final answer.
Environment:
codex-cli 0.144.2openai-chatadapter (opencode-go/deepseek-v4-flashfor this reproduction)websockets: falseI tested at two different layers:
curl --no-bufferrequest directly tohttp://127.0.0.1:10100/v1/responsescan now stream continuously. For a long1..500response, chunks arrived over several seconds, generally every 20–40 ms./Applications/ChatGPT.app/Contents/Resources/codex app-server), started a thread withopencode-go/deepseek-v4-flash, sent the same1..500prompt, and timestamped the documenteditem/agentMessage/deltanotifications.The app-server measurement was:
So after reasoning completed, the bundled Codex app-server received 999 text deltas in only 28.7 ms. This exactly matches what Codex Desktop displays: the model thinks for a while, then the entire final answer appears at once.
This also rules out the Desktop renderer as the primary cause—the app-server itself receives the final text as an end burst. The
Accept-Encoding: identitychange is present locally, but it does not resolve batching for the full production Codex request shape (instructions, tools, reasoning, etc.). The simpler direct proxy request is therefore not representative of the actual Codex Desktop path.Could this issue please be reopened? I can provide the small Node app-server timing probe if useful.
Wibias commentedon Jul 13, 2026
Hm. @RobinBially Can u please apply and build that fix locally and report back?
robin-bially commentedon Jul 14, 2026
Retested with opencodex
2.7.17after #123. The DeepSeek path is now streaming progressively in the real Codex Desktop/app-server flow.Two actual Codex Desktop turns used the same long response shape (integers 1 through 500):
opencode-go/minimax-m3opencode-go/deepseek-v4-flashI also reran the standalone E2E probe against the Codex Desktop bundled app-server with
opencode-go/deepseek-v4-flash. It timestamped everyitem/agentMessage/deltanotification:Before #123, the same probe delivered all 999 deltas in only 28.7 ms at the end. With 2.7.17, those deltas are spread across 1,253.2 ms, so #123 fixes the reported coalescing problem for DeepSeek/OpenRouter in the full Codex Desktop path.
MiniMax M3 still behaves like an end burst (only 41 ms from first token to completion). My current interpretation is that MiniMax or its adapter supplies one large text delta, or only a few large deltas, so the bridge has no finer-grained event sequence to flush. That appears distinct from the same-turn multi-event coalescing fixed by #123.
Wibias commentedon Jul 14, 2026
Thanks for the thorough re-test — great to see the delta spread jump from 28.7 ms to 1,253 ms on the DeepSeek path.
On MiniMax M3: the 41 ms first-token-to-completion window is not a regression introduced by this PR. MiniMax (or its OpenRouter adapter) produces only a small number of large text deltas upstream, so the bridge has no finer-grained event sequence to flush — it is faithfully forwarding what it receives. The behaviour is provider-side, not a coalescing bug in the proxy layer. A separate issue or PR targeting MiniMax specifically would be the right place to address that if needed.
fix(upstream): suppress Accept-Encoding to prevent SSE buffering via …
fix(streaming): flush bursty responses incrementally