Skip to content

bug: The last line of every code block is truncated while streaming #263

Description

@monon999

Version: 2.0.23

Describe the Bug

During streaming, each code block loses everything after the first token of its final line:

Expected Rendered
(DDDDDDDD) (
line-60: ######## line-
first-05: ######## first

Findings from testing:

  • The stored .jsonl message is complete, with finishReason: "stop" and the full token count. Nothing is lost in the response itself.
  • Switching to another thread and back renders the code block correctly, so it is the streaming render that is left in a stale state.
  • The copy button copies the truncated text, which is what makes this more than a cosmetic problem.
  • It is not related to generation length: a 424-token response over 5.2 s was truncated the same way as a 29-token one.
  • It is not limited to the final block: with two code blocks in one response, both lost the tail of their last line, while the prose between them was intact.
  • It is not the tail of the response either: when I asked for a line of text after the code block, that line rendered in full while the code block was still truncated.
  • A 210-token response with no code block was not affected at all.
  • The same model and prompt through another client render the full text, so the model output is fine.

My guess is that the highlight state for the last line is computed while it is still incomplete and never recomputed once the stream ends, but I haven't traced it into the code plugin.

Steps to Reproduce

  1. Send this prompt to any local model:

    Output the following in a code block. No explanation needed.

    {AAAAAAAA}
    {BBBB},{BBBB}
    {CCC},{CCCCC}
    (DDDDDDDD)
    
  2. The rendered code block ends at ( instead of (DDDDDDDD).

  3. Press the copy button and paste elsewhere — the text is truncated the same way.

  4. Switch to another thread and back — it now renders correctly.

Screenshots / Logs

Image

Operating System

  • MacOS
  • Windows
  • Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions