← Back to PRs

#20051: fix(mattermost): fix chatmode: "onmessage" to work correctly in mattermost [AI-generated]

by RHesketh open 2026-02-18 13:11 View on GitHub →
channel: mattermost size: S
## Problem Setting `channels.mattermost.requireMention: false`, `channels.mattermost.accounts.<id>.requireMention: false`, or `chatmode: "onmessage"` has **no effect** on whether the bot requires an @mention in channels. All channel messages without an explicit @mention are silently dropped. This happens because the monitor's mention gate at `extensions/mattermost/src/mattermost/monitor.ts` calls: ```typescript core.channel.groups.resolveRequireMention({ cfg, channel: "mattermost", accountId: account.accountId, groupId: channelId, }); ``` This resolves to the SDK's `resolveChannelGroupRequireMention`, which only reads from `channels.mattermost.groups.<groupId>.requireMention` or `channels.mattermost.groups.*.requireMention`. It does **not** consult the account-level `requireMention` or the plugin's own `resolveMattermostGroupRequireMention` (registered on the channel dock but not called from this code path). When no `groups` config exists — which is the default — the SDK function returns `true` (require mention), regardless of what `chatmode` or `requireMention` is set to at the account level. ## Root Cause Two `resolveRequireMention` functions exist: | Function | Reads from | Called by | |----------|-----------|-----------| | `resolveMattermostGroupRequireMention` (plugin dock) | `account.requireMention`, respects `chatmode` | Reply template context (`resolveGroupRequireMention`) | | `resolveChannelGroupRequireMention` (SDK) | `channels.mattermost.groups.*` config only | Monitor mention gate (`core.channel.groups.resolveRequireMention`) | The monitor uses the SDK function but never passes the account-level override, so the plugin's `chatmode` / `requireMention` config is invisible to the gate that actually drops messages. ## Fix The SDK's `resolveChannelGroupRequireMention` already accepts a `requireMentionOverride` parameter (with configurable precedence via `overrideOrder`). The fix passes `account.requireMention` through this existing parameter: ```diff core.channel.groups.resolveRequireMention({ cfg, channel: "mattermost", accountId: account.accountId, groupId: channelId, + requireMentionOverride: account.requireMention, }); ``` With the default `overrideOrder: "after-config"`, the precedence becomes: 1. Per-group config (`channels.mattermost.groups.<id>.requireMention`) — highest priority 2. Wildcard group config (`channels.mattermost.groups.*.requireMention`) 3. Account-level override from `chatmode` / `requireMention` — new fallback 4. SDK default (`true`) — lowest priority This means existing `groups.*` config is still respected, but `chatmode: "onmessage"` and `requireMention: false` now work as expected when no group-level config is set. ## Workaround (current) Users can work around this today by adding: ```json { "channels": { "mattermost": { "groups": { "*": { "requireMention": false } } } } } ``` This fix makes that workaround unnecessary. # Notes for Reviewers The code changes were generated by Claude Opus 4.6 and tested by a human (me) on a test install of OpenClaw and Mattermost: <img width="347" height="121" alt="Screenshot 2026-02-18 at 12 20 39" src="https://github.com/user-attachments/assets/6a97c2f3-65e2-48d3-9bec-bc1403d246a0" /> Standard tests were run: | Step | Command | Result | Notes | | -------------------------- | -------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------ | | Build | `pnpm build` | ✅ Pass | Clean build, no errors | | Formatting | `pnpm check` (prettier) | ✅ Pass | "All matched files use the correct format" (4825 files) | | Lint | `pnpm check` (oxlint) | ✅ Pass | 0 warnings, 0 errors (3391 files, 136 rules) | | Mattermost extension tests | `vitest run extensions/mattermost/` | ✅ 36/36 pass (6 files) | Includes new tests for this fix | | Full test suite | `pnpm test` | ⚠️ OOM | Dev machine could not run full test suite | | WebSocket verification | Python WebSocket client | ✅ Events delivered | Confirmed Mattermost server delivers `posted` events for channel messages to the bot — issue was purely in OpenClaw's handling | ## Asking Claude to assess its own work: > Without the fix (no requireMentionOverride): > > 1. requireMentionOverride = undefined > 1. overrideOrder = "after-config" (default) > 1. groupConfig = undefined (no channels.mattermost.groups.cooking config) > 1. defaultConfig = undefined (no channels.mattermost.groups.* config) > 1. configMention = undefined > 1. First if: overrideOrder !== "before-config" → skip > 1. Second if: configMention is undefined → skip > 1. Third if: requireMentionOverride is undefined, typeof undefined === "boolean" is false → skip > 1. Returns true ← requires mention, message dropped > > With the fix (requireMentionOverride: false from chatmode: "onmessage"): > > 1. requireMentionOverride = false > 1. overrideOrder = "after-config" (default) > 1. groupConfig = undefined, defaultConfig = undefined > 1. configMention = undefined > 1. First if: overrideOrder !== "before-config" → skip > 1. Second if: configMention is undefined → skip > 1. Third if: overrideOrder !== "before-config" ✓ AND typeof false === "boolean" ✓ → returns false ← mention not required, message passes through ✅ > > With the fix AND per-group config override (groups.cooking.requireMention: true): > > 1. requireMentionOverride = false > 1. groupConfig.requireMention = true > 1. configMention = true > 1. Second if: typeof true === "boolean" ✓ → returns true ← per-group config takes precedence ✅ > 1. The logic is sound — it's not a hallucination. The requireMentionOverride parameter exists specifically for this use case, it's typed, and the precedence chain works correctly. The Mattermost plugin just wasn't using it. > > Telegram already does the exact same thing. It passes requireMentionOverride: `opts.requireMention` with `overrideOrder: "after-config"`. The Mattermost plugin just missed this pattern. This isn't a novel change — it's aligning Mattermost with how Telegram already works. > <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes the Mattermost monitor's mention gate to respect account-level `requireMention` and `chatmode` settings (e.g., `chatmode: "onmessage"`), which were previously ignored — causing all non-mentioned channel messages to be silently dropped regardless of configuration. - **One-line fix** in `monitor.ts`: passes `account.requireMention` as `requireMentionOverride` to the SDK's `resolveChannelGroupRequireMention`, aligning Mattermost with how Telegram (`src/telegram/bot.ts:296`) and iMessage (`src/imessage/monitor/inbound-processing.ts:251`) already handle this. - The existing `resolveChannelGroupRequireMention` function's `overrideOrder: "after-config"` default ensures per-group and wildcard group configs still take precedence over the account-level override. - New test file (`monitor-mention.test.ts`) with 6 tests covering: default behavior, `chatmode: "onmessage"`, explicit `requireMention: false`, per-group override, wildcard override, and `chatmode: "oncall"`. - No issues found — the change is minimal, well-tested, and correctly uses the existing SDK infrastructure. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — it's a minimal, well-understood one-line fix that aligns Mattermost with the existing Telegram/iMessage pattern, backed by thorough tests. - The code change is a single line that passes an already-computed value through an existing, well-typed parameter. The fix mirrors an identical pattern used by two other channels (Telegram, iMessage). The precedence logic in the SDK function is well-tested and unchanged. New tests cover all relevant scenarios. The PR author manually tested on a live Mattermost installation. - No files require special attention. <sub>Last reviewed commit: 51c8161</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs