Skip to content

Discord chunker splits before closing fences and formats following prose as code #375

Description

@Calmingstorm

Confirmed response-formatting defect

Reviewed master at 886c36d8ebe861aa987059a1744d45b78797baae (v4.7.0). Suggested priority: P3.

The response chunker updates code-fence state before deciding whether the incoming line fits. If a closing fence triggers a split, it considers the block already closed, sends the old chunk without a closing fence, and places the original closing fence at the start of the new chunk. Subsequent ordinary prose is then formatted as code.

Source: ResponseDelivery.send_chunked.

Isolated reproduction

Call the real chunker with a fake message/transport and this text:

text = "```python\n" + "x" * 1977 + "\n```\nnormal prose after code block"

Observed:

chunk lengths: [1988, 34]
fence counts: [1, 1]
last chunk: '```\nnormal prose after code block\n'

Both outgoing messages have unmatched fences. Independently reproduced twice without sending Discord messages. Agent's focused regression selection: 104 passed.

Acceptance criteria

  • Compute the outgoing chunk's fence state before consuming the next logical line.
  • Close/reopen continuations consistently, retaining the language only while inside the original code block.
  • Test closing-fence-at-boundary, opening-fence-at-boundary, long code lines and following prose.
  • Preserve all content and Discord message-size limits.

This is a formatting defect, not claimed content loss or send failure. The issue was also mentioned as deferred in an older review; no matching existing repository issue was found. No source changes were made.

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions