Skip to content

fix(mattermost): prevent DM replies from threading via resolveMattermostReplyRootId#60115

Closed
jwchmodx wants to merge 1 commit intoopenclaw:mainfrom
jwchmodx:fix/mattermost-dm-reply-threading
Closed

fix(mattermost): prevent DM replies from threading via resolveMattermostReplyRootId#60115
jwchmodx wants to merge 1 commit intoopenclaw:mainfrom
jwchmodx:fix/mattermost-dm-reply-threading

Conversation

@jwchmodx
Copy link
Copy Markdown
Contributor

@jwchmodx jwchmodx commented Apr 3, 2026

Problem

Mattermost DM auto-replies were sent with a non-empty root_id, creating threads in the DM channel despite the documentation stating that direct messages ignore replyToMode and stay non-threaded.

The bug was in resolveMattermostReplyRootId: it would fall back to payload.replyToId regardless of chat kind. Even though resolveMattermostEffectiveReplyToId already correctly returns undefined for DMs (guarding session-key resolution), the delivery path could still reintroduce a thread root when a downstream payload carried a replyToId — for example, during block-streaming delivery where each block carries the inbound post ID as replyToId.

This caused all DM bot replies to appear as threads, making the main channel body appear empty to users.

Fixes #59981

Fix

Add kind: ChatType to resolveMattermostReplyRootId and hard-return undefined when kind === "direct", mirroring the guard that already existed in resolveMattermostEffectiveReplyToId.

Update all three delivery call sites to pass kind:

  1. Main inbound message replies
  2. Button-click interaction replies
  3. Model picker command replies

Tests

Added two regression tests to resolveMattermostReplyRootId:

  • DM with replyToIdundefined (was: returns replyToId, causing threading)
  • DM with both threadRootId and replyToIdundefined

All 22 Mattermost monitor tests pass.

pnpm vitest run extensions/mattermost/src/mattermost/monitor.test.ts
✓ 22 tests passed

…ostReplyRootId

Direct messages in Mattermost were creating threads even with
replyToMode=off because resolveMattermostReplyRootId would fall back
to payload.replyToId regardless of chat kind. When a downstream payload
carried a replyToId (e.g. from block-streaming delivery), this
bypassed the earlier DM threading guard and set root_id on the outbound
post, making DM replies appear as threads instead of in the channel body.

Fix: pass kind through all three delivery call sites and hard-return
undefined inside resolveMattermostReplyRootId for kind="direct",
mirroring the resolveMattermostEffectiveReplyToId guard that already
existed for session-key resolution.

Fixes openclaw#59981
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 3, 2026

Greptile Summary

This PR fixes a threading bug in the Mattermost extension where DM bot replies were incorrectly sent with a non-empty root_id, causing threads in DM channels. The fix adds a kind: ChatType parameter to resolveMattermostReplyRootId and short-circuits to undefined for "direct" chats, mirroring the guard already present in resolveMattermostEffectiveReplyToId. All three delivery call sites are correctly updated, and two targeted regression tests are added.

Confidence Score: 5/5

Safe to merge — minimal, focused fix with regression tests covering both DM threading scenarios.

All three delivery call sites correctly pass kind, the new guard mirrors the existing DM policy in resolveMattermostEffectiveReplyToId, regression tests are accurate, and no unrelated code is touched.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(mattermost): prevent DM replies from..." | Re-trigger Greptile

@vincentkoc
Copy link
Copy Markdown
Member

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #72305
Source PR: #60115
Contributor credit is preserved in the replacement PR body and changelog plan.

@vincentkoc
Copy link
Copy Markdown
Member

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #72659
Source PR: #60115
Contributor credit is preserved in the replacement PR body and changelog plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:Mattermost: DM replies thread despite replyToMode "off" (docs say DMs stay non-threaded)

2 participants