-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
feat(mattermost): chunk text before final streaming edit to respect post size limits #39491
Description
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.