From aaba1ae653f3049d85fb709cc7ab17e7fccdc840 Mon Sep 17 00:00:00 2001 From: create Date: Mon, 23 Mar 2026 01:01:20 +0800 Subject: [PATCH] fix(mattermost): honor replyToMode off for threaded messages --- .../mattermost/src/mattermost/monitor.test.ts | 27 +++++++++++++++++++ .../mattermost/src/mattermost/monitor.ts | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/extensions/mattermost/src/mattermost/monitor.test.ts b/extensions/mattermost/src/mattermost/monitor.test.ts index 7155f5b3c83..c36011d9589 100644 --- a/extensions/mattermost/src/mattermost/monitor.test.ts +++ b/extensions/mattermost/src/mattermost/monitor.test.ts @@ -169,6 +169,17 @@ describe("resolveMattermostEffectiveReplyToId", () => { ).toBe("thread-root-456"); }); + it("suppresses existing thread roots when replyToMode is off", () => { + expect( + resolveMattermostEffectiveReplyToId({ + kind: "channel", + postId: "post-123", + replyToMode: "off", + threadRootId: "thread-root-456", + }), + ).toBeUndefined(); + }); + it("starts a thread for top-level channel messages when replyToMode is all", () => { expect( resolveMattermostEffectiveReplyToId({ @@ -232,6 +243,22 @@ describe("resolveMattermostThreadSessionContext", () => { }); }); + it("keeps threaded messages top-level when replyToMode is off", () => { + expect( + resolveMattermostThreadSessionContext({ + baseSessionKey: "agent:main:mattermost:default:chan-1", + kind: "group", + postId: "post-123", + replyToMode: "off", + threadRootId: "root-456", + }), + ).toEqual({ + effectiveReplyToId: undefined, + sessionKey: "agent:main:mattermost:default:chan-1", + parentSessionKey: undefined, + }); + }); + it("keeps direct-message sessions linear", () => { expect( resolveMattermostThreadSessionContext({ diff --git a/extensions/mattermost/src/mattermost/monitor.ts b/extensions/mattermost/src/mattermost/monitor.ts index 958a40de705..05b8de67cc1 100644 --- a/extensions/mattermost/src/mattermost/monitor.ts +++ b/extensions/mattermost/src/mattermost/monitor.ts @@ -175,7 +175,7 @@ export function resolveMattermostEffectiveReplyToId(params: { threadRootId?: string | null; }): string | undefined { const threadRootId = params.threadRootId?.trim(); - if (threadRootId) { + if (threadRootId && params.replyToMode !== "off") { return threadRootId; } if (params.kind === "direct") {