From 5aa16edfbb8fe96539dc92b1bd766ed2456c67a2 Mon Sep 17 00:00:00 2001 From: teconomix Date: Fri, 20 Mar 2026 12:16:26 +0000 Subject: [PATCH] fix(mattermost): detect reply target divergence correctly (ID=2965349638) resolveMattermostReplyRootId always returns threadRootId when it is set, so comparing finalReplyToId against effectiveReplyToId was always false when the streaming preview was created in a thread. Explicit reply directives like [[reply_to:...]] could therefore never trigger the divergent-target path. Fix: compare payload.replyToId directly against effectiveReplyToId instead of going through the resolver. The resolver is still used to compute finalReplyToId for the actual delivery call. --- extensions/mattermost/src/mattermost/monitor.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extensions/mattermost/src/mattermost/monitor.ts b/extensions/mattermost/src/mattermost/monitor.ts index 44bb6bce94e..a14d6d1ebba 100644 --- a/extensions/mattermost/src/mattermost/monitor.ts +++ b/extensions/mattermost/src/mattermost/monitor.ts @@ -1549,12 +1549,21 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {} // Compute reply target divergence before flushing, so we don't // accidentally create a preview post in the wrong thread on flush. + // Compute the reply target for this payload. When payload.replyToId is set + // and resolves to a different thread than the one the streaming preview was + // created in (effectiveReplyToId), we must not patch the preview in-place. + // We compare the raw payload.replyToId against effectiveReplyToId directly + // instead of going through resolveMattermostReplyRootId(), because that + // helper always returns threadRootId when set, making the comparison always + // false when effectiveReplyToId is non-empty (ID=2965349638). const finalReplyToId = resolveMattermostReplyRootId({ threadRootId: effectiveReplyToId, replyToId: payload.replyToId, }); const replyTargetDiverged = - finalReplyToId !== effectiveReplyToId && payload.replyToId != null; + payload.replyToId != null && + payload.replyToId.trim() !== "" && + payload.replyToId.trim() !== effectiveReplyToId; if (isFinal && blockStreamingClient) { if (replyTargetDiverged) {