Skip to content

feat(mattermost): chunk text before final streaming edit to respect post size limits #39491

@teconomix

Description

@teconomix

Problem

In the Mattermost block-streaming path, when the final deliver call patches the streamed placeholder via updateMattermostPost, the full response text is passed without chunking. This bypasses the chunkMarkdownTextWithMode flow used by the non-streaming path.

If a response exceeds Mattermosts post size limit (~16k chars), the updateMattermostPost call fails. The catch block re-delivers the same unchunked text via sendMessageMattermost, which also fails, leaving an orphaned partial-text message with no complete reply.

Expected behaviour

Responses exceeding textLimit should be chunked and delivered as multiple messages, consistent with the non-streaming path.

Proposed fix

Before calling updateMattermostPost on the final patch, check text.length > textLimit. If so, delete the orphaned streaming placeholder (best-effort) and fall through to the normal chunkMarkdownTextWithMode delivery path.

Context

Identified by Codex review on PR #33506. Deferred to keep that PR focused. A TODO comment marks the relevant location in monitor.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions