Skip to content

fix(mattermost): pass payload.replyToId as root_id for threaded replies#27744

Merged
mukhtharcm merged 4 commits intoopenclaw:mainfrom
hnykda:fix/mattermost-reply-to-current-threading
Mar 8, 2026
Merged

fix(mattermost): pass payload.replyToId as root_id for threaded replies#27744
mukhtharcm merged 4 commits intoopenclaw:mainfrom
hnykda:fix/mattermost-reply-to-current-threading

Conversation

@hnykda
Copy link
Copy Markdown
Contributor

@hnykda hnykda commented Feb 26, 2026

Summary

  • Problem: [[reply_to_current]] and [[reply_to:<id>]] tags are correctly parsed and stripped from outgoing text, but the monitor's deliver callback ignores payload.replyToId and hardcodes replyToId: threadRootId. For top-level messages (no existing thread), threadRootId is undefined, so replies are never threaded.
  • Why it matters: Mattermost users see bot responses as new top-level posts instead of threaded replies, breaking conversation flow.
  • What changed: Monitor deliver callback now uses payload.replyToId || threadRootId (prefer tag-resolved ID, fall back to existing thread root). Added tests at three levels: API client root_id passthrough, reply threading pipeline, and monitor deliver logic.
  • What did NOT change: Tag parsing, reply pipeline, outbound adapter, sendMessageMattermost — all already worked correctly.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Integrations

Linked Issue/PR

User-visible / Behavior Changes

[[reply_to_current]] and [[reply_to:<id>]] now produce threaded replies on Mattermost (sets root_id on POST /api/v4/posts).

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No (same API call, just includes root_id field when appropriate)
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • Integration/channel: Mattermost

Steps

  1. Send a DM to the bot on Mattermost
  2. Bot responds with [[reply_to_current]] some reply text
  3. Check whether the reply appears as a thread reply or a top-level post

Expected

  • Reply appears as a threaded reply to the original message

Actual (before fix)

  • Reply appears as a new top-level post (root_id not set)

Evidence

  • Failing test/log before + passing after

Tests fail with buggy return threadRootId (3 failures), pass with fix return payload.replyToId || threadRootId.

Human Verification (required)

  • Verified scenarios: Tests confirm tag-resolved replyToId is passed through for top-level DMs, explicit [[reply_to:<id>]], fallback to threadRootId, and precedence when both are present.
  • Edge cases checked: undefined threadRootId + defined payload.replyToId, defined threadRootId + undefined payload.replyToId, both defined (payload wins).
  • What you did not verify: Live Mattermost instance end-to-end.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • Revert this single commit.
  • Known bad symptoms: replies suddenly appearing in wrong threads (would require payload.replyToId to contain an invalid post ID, which would be a pre-existing bug in tag parsing).

Risks and Mitigations

None — the change is a two-line fix using the same payload.replyToId that other channels already consume.

@openclaw-barnacle openclaw-barnacle bot added channel: mattermost Channel integration: mattermost size: S labels Feb 26, 2026
@hnykda hnykda force-pushed the fix/mattermost-reply-to-current-threading branch from 33533d5 to e07e563 Compare February 26, 2026 16:36
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

Fixed Mattermost threaded replies by correctly passing payload.replyToId (from [[reply_to_current]] and [[reply_to:<id>]] tags) to the Mattermost API's root_id field. The monitor's deliver callback now uses payload.replyToId || threadRootId instead of hardcoding threadRootId, ensuring replies thread correctly for top-level messages.

  • What changed: Two-line fix in monitor.ts (lines 753, 764) to prefer tag-resolved reply ID over thread context
  • Why it matters: Without this fix, bot responses to top-level Mattermost DMs appear as new posts instead of threaded replies, breaking conversation flow
  • Test coverage: Comprehensive tests added at three levels - API client (createMattermostPost with/without root_id), reply pipeline (applyReplyThreading tag resolution), and monitor deliver logic (precedence rules)
  • Backward compatibility: Yes - falls back to existing threadRootId when no explicit reply tag is present

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a minimal two-line change with clear logic (payload.replyToId || threadRootId), comprehensive test coverage at multiple levels, correct type safety, and backward compatibility. The change only affects Mattermost reply threading behavior and has no security implications.
  • No files require special attention

Last reviewed commit: e07e563

@hnykda
Copy link
Copy Markdown
Contributor Author

hnykda commented Feb 27, 2026

Testing Results

Tested on self-hosted Mattermost Team Edition with OpenClaw 2026.2.25 + this patch applied via git apply.

Setup: chatmode: "onmessage", groupPolicy: "open", bot joined to channel

Confirmed working ✅

  • Reactive replies to channel messages are correctly threaded (root_id set to inbound message ID)
  • message tool with explicit replyTo=<messageId> correctly sets root_id → threaded reply
  • Tag is stripped from outgoing text as expected

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 5, 2026
@hnykda
Copy link
Copy Markdown
Contributor Author

hnykda commented Mar 5, 2026

What should I do? The PR is good, it should be merged, it's tested.

@openclaw-barnacle openclaw-barnacle bot removed the stale Marked as stale due to inactivity label Mar 6, 2026
@mukhtharcm mukhtharcm self-assigned this Mar 8, 2026
@mukhtharcm mukhtharcm force-pushed the fix/mattermost-reply-to-current-threading branch from e07e563 to e1d76d4 Compare March 8, 2026 07:53
@openclaw-barnacle openclaw-barnacle bot added the cli CLI command changes label Mar 8, 2026
mukhtharcm added a commit to hnykda/openclaw that referenced this pull request Mar 8, 2026
@mukhtharcm mukhtharcm force-pushed the fix/mattermost-reply-to-current-threading branch from cfedb33 to e029079 Compare March 8, 2026 08:42
@openclaw-barnacle openclaw-barnacle bot removed the cli CLI command changes label Mar 8, 2026
@mukhtharcm mukhtharcm merged commit 9425209 into openclaw:main Mar 8, 2026
26 checks passed
@mukhtharcm
Copy link
Copy Markdown
Member

Merged via squash.

Thanks @hnykda!

expect(
resolveMattermostReplyRootId({
replyToId: "inbound-post-123",
}),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2a2

Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
GordonSH-oss pushed a commit to GordonSH-oss/openclaw that referenced this pull request Mar 9, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
@hnykda hnykda deleted the fix/mattermost-reply-to-current-threading branch March 9, 2026 09:39
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
sauerdaniel pushed a commit to sauerdaniel/openclaw that referenced this pull request Mar 11, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm

(cherry picked from commit 9425209)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 22, 2026
…es (openclaw#27744)

Merged via squash.

Prepared head SHA: e029079
Co-authored-by: hnykda <[email protected]>
Co-authored-by: mukhtharcm <[email protected]>
Reviewed-by: @mukhtharcm

(cherry picked from commit 9425209)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[[reply_to_current]] tag does not create thread replies on Mattermost

3 participants