← Back to PRs

#12180: fix: merge multi-block assistant texts into single reply

by 1960697431 open 2026-02-08 23:46 View on GitHub →
agents stale
When a model (e.g. Claude with interleaved thinking blocks) produces multiple text content blocks in a single assistant message, each block was being delivered as a separate outbound message (e.g. multiple iMessage bubbles). This merges them into a single coherent reply when block streaming is off. ## Problem Claude API can return multiple `text` content blocks in a single assistant turn. The `buildEmbeddedRunPayloads` function creates a separate reply payload for each text block, resulting in multiple outbound messages (e.g. 2-3 iMessage bubbles for what should be a single response). ## Fix Before iterating over `answerTexts`, merge adjacent text blocks into a single string joined by `\n\n`. This ensures the model's multi-block response is delivered as one coherent message. ## Testing - All 4904 existing tests pass - `payloads.test.ts` (12 tests) all pass <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This change updates `buildEmbeddedRunPayloads` to collapse multiple assistant `text` content blocks into a single outbound reply (joined with `\n\n`) to avoid sending multiple message “bubbles” when block streaming is disabled. The logic sits in the embedded runner’s payload builder, which is responsible for turning assistant output (plus optional tool meta, reasoning text, and error messages) into a list of user-facing reply payloads. The new merge happens right before iterating and parsing reply directives for each outgoing message. <h3>Confidence Score: 3/5</h3> - This PR is moderately safe to merge, but it can change behavior for replies that rely on per-block directives/media parsing. - The merge accomplishes the stated goal, but it changes the unit of parsing for `parseReplyDirectives` by combining multiple blocks into one, which can break cases where directives or media tags are intended to apply to a specific block. If directives are present in any merged block, the resulting payload fields may be incorrect or lost. - src/agents/pi-embedded-runner/run/payloads.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs