Skip to content

acp: reasoning deltas interleave with text chunks, fragmenting responses in Zed #66347

Backlog

Description

@flupkede

Summary

Over ACP, a single assistant response arrives as many tiny agent_message chunks interleaved with agent_thought_chunk updates (one per reasoning delta). Clients that render each chunk as its own block (Zed) show the response fragmented into one-line fragments separated by "Thinking" chips. Claude Code over the same ACP client does not interleave thought chunks mid-text, so the problem is specific to opencode's emission pattern.

Environment

  • opencode version: 2.4.1 (latest channel)
  • OS: Windows 10/11 (Windows_NT 10.0.26200, win32 x64)
  • Terminal: n/a — ACP client is Zed (Zed-industries ACP integration)
  • Shell: Git Bash
  • Install/channel: latest
  • Active plugins: @slkiser/[email protected], local fast-compaction plugin
  • Model: GLM (z.ai) via custom providers — streams reasoning_content and content alternately

Reproduction

  1. Configure Zed to use opencode as its ACP agent.
  2. Start a session on a model that streams reasoning (GLM 5.3 family).
  3. Ask any question that produces a multi-sentence answer.

Expected Behavior

The assistant's text streams as one growing block; reasoning is rendered separately, without breaking the text into fragments.

Actual Behavior

The text arrives as alternating agent_message / agent_thought_chunk session updates, e.g. (Zed transcript):

first sentence of the answer ends here
💭 Thinking
the next sentence arrives
💭 Thinking
as a separate block, and so on

Zed merges only consecutive same-kind chunks (crates/acp_thread/src/acp_thread.rs, can_merge_message_chunks), so every interleaved thought chunk starts a new text block. The full text is present and in order — this is a rendering/emission mismatch, not data loss. Claude Code over the same client does not emit thought chunks mid-text, so its output renders as one block.

Additional Context

  • Started recently (after an opencode 2.x update); before that the same setup rendered normally.
  • opencode's own TUI renders these responses as a single block, so the interleaving is specific to the ACP adapter.
  • Two possible fixes on opencode's side: buffer reasoning deltas instead of emitting one agent_thought_chunk per delta, or avoid interleaving thought updates between text deltas of the same response.
  • Consistently reproducible with reasoning-streaming models; not reproducible via Claude Code as the ACP agent.

Activity

  1. added
    area/ide-acp
    type/bug
    version/v2
    on Nov 25, 2026
  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I tried this with a local mock OpenAI-compatible server configured as a custom provider. It streams reasoning_content and content alternately, as you describe GLM doing. I drove opencode acp with a minimal ACP client.

    What I saw:

    • 2.4.1: when the model alternates reasoning and text, OpenCode sends agent_thought_chunk and agent_message_chunk updates in that same alternating order. When the model sends all its reasoning first, there is one thought chunk followed by one text chunk.
    • 2.3.2: the same alternating stream also came out interleaved in one of three runs. The core groups deltas into ~100 ms batches, so how much interleaving shows depends on the stream's timing.
    • Latest dev (64324cf): same, still interleaved.

    So OpenCode passes reasoning and text through in the order the provider streams them. Thought chunks and text chunks carry different messageIds (<message>:reasoning:0 and <message>). That looks like the current design rather than something broken, and I couldn't confirm it as a regression. Buffering reasoning, or not interleaving it within a response, would be a change to that behaviour, so it might be better tracked as a feature request for the ACP adapter.

    If you saw it work in a specific earlier 2.x version with the same GLM setup, it would help to know:

    • that version number;
    • whether GLM 5.3 began alternating reasoning and content around the same time (for example, a raw stream captured with a proxy);
    • any OpenCode or Zed logs showing the order of updates in both versions.
  3. flupkede commented on Nov 25, 2026

    @flupkede
    Author

    I can't say that it started with that specific version I only started noting this since last week, however opencode, acp and zed received updates so difficult to know what exactly caused it, it 's also not consistent, however once it starts it continues doing so. I thought it would be in the acp layer , because zed just streams what it gets in sequence, so if the text stops and switches message id zed creates the appropriate UI component and continues streaming until the next type of message comes in. Opus said that behavior is fine in Zed, so that it had to be changed in opencode , why it didn't think it was the acp I don't know, because that was my first thought.

  4. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the extra details. I think you're right that the place to change this is OpenCode's ACP layer.

    In my tests the ACP adapter sends each text delta as an agent_message_chunk and each reasoning delta as an agent_thought_chunk, in the order they arrive. The core first groups deltas into ~100 ms batches. When a model like GLM alternates reasoning and text mid-answer, Zed therefore gets alternating chunk types, starts a new block at each switch, and the answer ends up in fragments.

    I used a mock provider that alternates reasoning and text, and saw the same thing on 2.3.2, 2.4.1 and the latest dev. On 2.3.2 it was intermittent, because how much interleaving shows depends on the stream's timing. That fits what you describe: inconsistent, but once the model starts alternating, it keeps going. I didn't find a version that behaved differently, so this looks like how the adapter works today rather than something that broke.

    I'm treating this as a feature request: over ACP, keep one response's text as one block, for example by buffering reasoning deltas or not sending thought chunks in the middle of a response's text. The maintainers will consider it. This can't be done as a plugin, because I didn't find a plugin hook that can reorder or merge the updates sent to ACP clients.

  5. added
    type/feature
    and removed
    type/bug
    on Nov 25, 2026
  6. flupkede commented on Nov 25, 2026

    @flupkede
    Author

    however the acp layer for zed is a separate layer right ? or is this also part of opencode I don't think so, so maybe it needs to be tweaked there instead ? Opus said that normally it should send these chunks in one piece and should not switch in between

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

    area/ide-acpplatform/windowstype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions