Skip to content

fix(mattermost): inherit message tool thread context - #90898

Closed
andyylin wants to merge 3 commits into
openclaw:mainfrom
andyylin:fix/mattermost-message-tool-thread-context
Closed

andyylin wants to merge 3 commits into
openclaw:mainfrom
andyylin:fix/mattermost-message-tool-thread-context

Conversation

@andyylin

@andyylin andyylin commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • port stale PR fix(mattermost): inherit thread context in message tool send action #52120 onto current main as a fresh replacement
  • add Mattermost threading.buildToolContext so active thread metadata reaches the message tool
  • fix shared outbound reply resolution so same-channel threaded sends use the thread root instead of the latest reply message
  • add regression coverage for both the helper path and the normal runMessageAction(... action: "send") dispatch path

Supersedes #52120.

Real behavior proof

Behavior or issue addressed: Mattermost message-tool sends from an active thread previously inherited currentMessageId before the Mattermost adapter could map the active thread root, so a normal message(action="send") call could reply to the latest message instead of staying anchored to the Mattermost thread root.

Real environment tested: Local OpenClaw checkout on branch fix/mattermost-message-tool-thread-context at commit 5058a7c6bc5d7b3dfc4b0850b1ededc6caddc1c6, running with the repo Node/tsx toolchain and node_modules from the OpenClaw workspace. The proof command executes the patched OpenClaw outbound threading module directly with Mattermost-shaped tool context; IDs are redacted placeholders.

Exact steps or command run after this patch:

node --import tsx /tmp/mattermost-thread-root-proof.mjs
node --check src/infra/outbound/message-action-threading.ts
node --check src/infra/outbound/message-action-threading.test-helpers.ts
node --check extensions/mattermost/src/channel.ts
node scripts/test-projects.mjs src/infra/outbound/message-action-runner.threading.test.ts src/infra/outbound/message-action-runner.plugin-dispatch.test.ts extensions/mattermost/src/channel.test.ts
CI=true pnpm check:architecture
./node_modules/.bin/oxlint src/infra/outbound/message-action-threading.ts src/infra/outbound/message-action-threading.test-helpers.ts src/infra/outbound/message-action-runner.threading.test.ts src/infra/outbound/message-action-runner.plugin-dispatch.test.ts extensions/mattermost/src/channel.ts extensions/mattermost/src/channel.test.ts

Evidence after fix:

$ node --import tsx /tmp/mattermost-thread-root-proof.mjs
{
  "resolvedReplyTo": "thread-root-id-redacted",
  "forwardedReplyTo": "thread-root-id-redacted",
  "latestMessageWasNotUsed": true,
  "threadRootWasUsed": true
}

Observed result after fix: The patched outbound reply resolver receives Mattermost-shaped same-channel thread context with currentThreadTs=thread-root-id-redacted and currentMessageId=latest-reply-id-redacted, then writes params.replyTo=thread-root-id-redacted. The latest reply message is not used as the reply target. Targeted Vitest shards also passed: 37 infra tests plus 46 Mattermost extension tests.

What was not tested: I did not send a live production Mattermost network message with real credentials from this local checkout. The runtime proof uses the patched OpenClaw module with redacted Mattermost-shaped context, and the regression tests cover the normal runner/plugin-dispatch path.

Tests

  • node --import tsx /tmp/mattermost-thread-root-proof.mjs
  • node --check src/infra/outbound/message-action-threading.ts
  • node --check src/infra/outbound/message-action-threading.test-helpers.ts
  • node --check extensions/mattermost/src/channel.ts
  • node scripts/test-projects.mjs src/infra/outbound/message-action-runner.threading.test.ts src/infra/outbound/message-action-runner.plugin-dispatch.test.ts extensions/mattermost/src/channel.test.ts
  • CI=true pnpm check:architecture
  • ./node_modules/.bin/oxlint src/infra/outbound/message-action-threading.ts src/infra/outbound/message-action-threading.test-helpers.ts src/infra/outbound/message-action-runner.threading.test.ts src/infra/outbound/message-action-runner.plugin-dispatch.test.ts extensions/mattermost/src/channel.ts extensions/mattermost/src/channel.test.ts

Note: CI=true pnpm check:changed was started and passed the guards/typecheck lanes before the long split-core lint exceeded the local watchdog; changed-file oxlint passed cleanly.

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@clawsweeper

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 6, 2026, 10:12 PM ET / 02:12 UTC.

Summary
The PR adds Mattermost message-tool thread context handling, updates shared outbound reply resolution to prefer a required same-channel thread root, adds regression tests, and carries small unrelated live-test fixture updates.

PR surface: Source +63, Tests +304. Total +367 across 9 files.

Reproducibility: yes. from source inspection: current main builds generic Mattermost tool context without a plugin buildToolContext, and the shared resolver falls back to currentMessageId, which matches the reported child-post anchoring failure. I did not run a live Mattermost send in this read-only review.

Review metrics: 1 noteworthy metric.

  • Non-Mattermost test-only edits: 3 files changed. The PR includes Google, MiniMax, and agent camera test fixture edits outside the Mattermost runtime fix, so maintainers should decide whether to accept those CI backports in the same merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted live Mattermost output, logs, screenshot, or recording showing a real message-tool send from an active thread lands under the intended root post.
  • Confirm whether the unrelated Google, MiniMax, and camera test fixture edits should stay in this PR or be split.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body supplies local terminal/module output and tests, but explicitly says no live production Mattermost message was sent, so real transport proof remains insufficient for this user-visible channel routing change; posted proof should redact private server, user, and message details, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.

Mantis proof suggestion
A short redacted Mattermost UI or log proof would materially reduce the remaining delivery-risk uncertainty for this visible channel-threading change. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

visual task: verify that a Mattermost message(action="send") from an active thread lands under the thread root, with server, user, and message IDs redacted.

Risk before merge

  • [P1] The PR changes same-channel thread/session routing for Mattermost message-tool sends, so a bad merge could keep replies anchored to the child message, route to the channel root, or update replyToMode=first state incorrectly.
  • [P1] The branch also carries unrelated live-test fixture skips for Google/MiniMax ffmpeg availability and an agent camera test mock update; these look like CI compatibility fixes, but they are outside the Mattermost behavior being reviewed.

Maintainer options:

  1. Require live Mattermost proof (recommended)
    Keep human review until the contributor supplies redacted live Mattermost output, logs, or a recording showing a real message-tool send from an active thread lands under the root post.
  2. Accept module-level proof only
    Maintainers can intentionally accept the local module proof and regression tests if a live Mattermost credential path is unavailable, owning the residual transport risk.
  3. Split unrelated fixture backports
    Maintainers may ask for the Google/MiniMax/camera test-only changes to be split out if they want this PR to stay Mattermost-only.

Next step before merge

  • [P1] The remaining blocker is human acceptance of live Mattermost proof and the small unrelated test-only tail, not a narrow code repair ClawSweeper can generate.

Security
Cleared: The diff does not change dependencies, secrets, permissions, package resolution, workflows, or runtime security boundaries; the extra test fixture changes do not introduce a concrete supply-chain concern.

Review details

Best possible solution:

Merge the Mattermost threading fix after live Mattermost proof or an explicit maintainer proof waiver, and keep the unrelated test fixture changes only if maintainers accept them as necessary CI backports.

Do we have a high-confidence way to reproduce the issue?

Yes from source inspection: current main builds generic Mattermost tool context without a plugin buildToolContext, and the shared resolver falls back to currentMessageId, which matches the reported child-post anchoring failure. I did not run a live Mattermost send in this read-only review.

Is this the best way to solve the issue?

Yes with current evidence: the fix uses the existing channel-owned threading adapter seam and shared helper flag rather than adding Mattermost-specific branching in core.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 51b64b81980b.

Label changes

Label justifications:

  • P1: The bug affects real Mattermost message-tool replies from active threads and can misroute agent output in a live channel workflow.
  • merge-risk: 🚨 message-delivery: The patch changes which Mattermost post receives message-tool sends, so delivery can land in the wrong visible thread if the context mapping is wrong.
  • merge-risk: 🚨 session-state: The patch changes inherited thread context and hasRepliedRef consumption for threaded sessions, which can affect subsequent reply state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body supplies local terminal/module output and tests, but explicitly says no live production Mattermost message was sent, so real transport proof remains insufficient for this user-visible channel routing change; posted proof should redact private server, user, and message details, then update the PR body to trigger re-review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +63, Tests +304. Total +367 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 74 11 +63
Tests 6 304 0 +304
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 378 11 +367

What I checked:

  • Repository policy read: Root and relevant scoped policies were read; the review applied the plugin-boundary, outbound-helper, real-proof, and whole-path review rules. (AGENTS.md:1, 51b64b81980b)
  • Current-main behavior: Current main's shared reply resolver inherits toolContext.currentMessageId for same-target sends when replyToMode allows it, so it cannot prefer a Mattermost thread root today. (src/infra/outbound/message-action-threading.ts:101, 51b64b81980b)
  • Current Mattermost adapter: Mattermost current main exposes scoped reply mode and reply transport, but no threading.buildToolContext, so the generic tool-context fallback supplies current message metadata instead of Mattermost thread-root metadata. (extensions/mattermost/src/channel.ts:739, 51b64b81980b)
  • Runner call path: handleSendAction resolves and writes reply-to metadata before preparing the outbound mirror route, and plugin dispatch receives the same tool context, so this helper controls both send params and session mirroring. (src/infra/outbound/message-action-runner.ts:1102, 51b64b81980b)
  • Sibling channel comparison: Slack already uses sameChannelThreadRequired for thread-root-required same-channel turns, while Telegram and Google Chat do not set it, supporting the PR's opt-in shared-helper shape. (extensions/slack/src/threading-tool-context.ts:27, 51b64b81980b)
  • PR diff evidence: The PR adds Mattermost buildToolContext, passes toolContext into Mattermost action handling, and changes the shared resolver to prefer currentThreadTs only when sameChannelThreadRequired is set. (extensions/mattermost/src/channel.ts:779, 1303df4e5889)

Likely related people:

  • steipete: Recent blame and sampled history show Peter Steinberger's broad refactor on the current outbound helper and Mattermost plugin shape, plus multiple recent Mattermost/channel boundary refactors. (role: recent area contributor; confidence: medium; commits: ba447d5afc17, 8bfa06e992be, b98cccc06e27; files: src/infra/outbound/message-action-threading.ts, extensions/mattermost/src/channel.ts)
  • Teconomix: The related superseded PR and current history tie Teconomix to Mattermost replyToMode and earlier thread-context behavior that this PR repairs. (role: feature-history contributor; confidence: high; commits: 0c926a2c5e82, 171d2df9e0fe; files: extensions/mattermost/src/channel.ts)
  • Gustavo Madeira Santana: Recent history shows Gustavo carried Mattermost outbound session routing and plugin message-discovery seams that interact with this PR's thread/session path. (role: adjacent owner; confidence: medium; commits: e29d3709696b, d6c13d9dc01e, 28ab5061bf3d; files: src/infra/outbound/message-action-threading.ts, extensions/mattermost/src/channel.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@andyylin

andyylin commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 6, 2026
@andyylin

andyylin commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 6, 2026
@andyylin

andyylin commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review after adding the runner-level thread-root fix and exact real-behavior proof fields.

@clawsweeper

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 6, 2026
@andyylin

andyylin commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing per Andy's request: he has stopped using OpenClaw, so we're retiring the remaining Andy-authored OpenClaw PR work instead of continuing proof/CI/maintainer follow-up.

@andyylin andyylin closed this Jun 8, 2026
@andyylin
andyylin deleted the fix/mattermost-message-tool-thread-context branch June 8, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: mattermost Channel integration: mattermost extensions: google extensions: minimax merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant