Skip to content

OpenRouter (openai-chat adapter): streaming delivers tokens in batches, not live #114

Closed

Description

@robin-bially

Summary

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

  1. Install opencodex with default config (ChatGPT passthrough + OpenRouter with openai-chat adapter)
  2. Use a ChatGPT model (e.g. gpt-5.6-luna): streaming works token-by-token ✅
  3. Switch to an OpenRouter model (e.g. openrouter/deepseek/deepseek-v4-flash): response appears all at once at the end ❌
  4. 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:

delta: "J"
delta: "etzt"
delta: " sie"
delta: "hst"
...

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.

Activity

  1. Wibias commented on Jul 12, 2026

    @Wibias
    Contributor

    @RobinBially Should hopefully get fixed by #115 either u build urself with the change or wait for a new version!

    • Wibias
  2. added a commit that references this issue on Jul 13, 2026
    7510904
  3. robin-bially commented on Jul 13, 2026

    @robin-bially
    ContributorAuthor

    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:

    1. 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.
    2. 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.

    The app-server measurement was:

    10297.2ms item/started type=reasoning
    10297.6ms item/completed type=reasoning
    10305.1ms item/started type=agentMessage
    10305.4ms delta #1
    10312.7ms delta #100
    10316.5ms delta #200
    10321.5ms delta #400
    10326.2ms delta #600
    10331.8ms delta #900
    10334.1ms item/completed type=agentMessage
    10334.3ms turn/completed deltas=999 deltaSpanMs=28.7
    

    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.

  4. Wibias commented on Jul 13, 2026

    @Wibias
    Contributor

    Hm. @RobinBially Can u please apply and build that fix locally and report back?

  5. robin-bially commented on Jul 14, 2026

    @robin-bially
    ContributorAuthor

    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:

    9008.9ms  delta #1
    9122.4ms  delta #100
    9244.6ms  delta #200
    9605.6ms  delta #500
    10133.5ms delta #900
    10276.5ms turn/completed deltas=999 deltaSpanMs=1253.2
    

    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.

  6. Wibias commented on Jul 14, 2026

    @Wibias
    Contributor

    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.

  7. added 2 commits that reference this issue on Sep 17, 2026
    b8eae10
    9f7cf1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions