← Back to PRs

#18908: fix(payloads): place tool warnings before assistant reply

by BinHPdev open 2026-02-17 05:34 View on GitHub →
channel: mattermost agents size: S
## Summary - Reorder payload items so tool failure warnings (`⚠️ ... failed`) appear **before** the assistant's final reply text in the output array - Previously, the warning was appended after the reply, making it the last (most visible) message in channels like Telegram that deliver messages sequentially — this overshadowed the actual answer - Now the assistant's reply is always the last item sent, ensuring it's the most visible - Dedup logic extended to check `answerTexts` in addition to already-emitted items, preserving the behavior where identical warning text in the assistant output prevents duplicate messages Closes #18687 ## Test plan - [x] Updated e2e test expectation: "shows mutating tool errors before assistant output for visibility" verifies `[warning, reply]` order - [x] `pnpm build` passes (TypeScript + lint) - [x] All existing payload tests remain compatible (dedup, suppression, recoverable errors, etc.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Reorders the `buildEmbeddedRunPayloads` output so tool failure warnings (`⚠️ ... failed`) appear **before** the assistant's reply text, making the final answer the last (most visible) message in sequential-delivery channels like Telegram. - Moved the `answerTexts` processing loop to after the tool-error-warning block, so warnings are appended to `replyItems` first - Pre-computed `hasUserFacingAssistantReply` via `.some()` since the decision needs to happen before answer items are pushed - Extended dedup logic with a new `duplicateInAnswers` check against raw `answerTexts`, compensating for answer texts not yet being in `replyItems` at dedup time - Updated the e2e test to verify `[warning, reply]` ordering and added a changelog entry <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk — it's a well-scoped reordering of output items with preserved dedup semantics and updated tests. - The change is focused and well-tested. The reordering logic is straightforward: tool warnings are pushed before answer texts instead of after. The pre-computed hasUserFacingAssistantReply preserves the same boolean semantics. The extended duplicateInAnswers check correctly compensates for answer texts not yet being in replyItems. One minor subtlety — the new dedup compares against raw answerTexts rather than parseReplyDirectives-cleaned text — is inconsequential for the warning text format. All existing tests pass and the updated test verifies the new ordering. - No files require special attention <sub>Last reviewed commit: f9a9b28</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs