Skip to content

feat(mattermost): follow thread after @mention (Slack parity) - #54193

Open
wernerhp wants to merge 5 commits into
NousResearch:mainfrom
wernerhp:feat/54188-mattermost-in-thread-autorespond
Open

feat(mattermost): follow thread after @mention (Slack parity)#54193
wernerhp wants to merge 5 commits into
NousResearch:mainfrom
wernerhp:feat/54188-mattermost-in-thread-autorespond

Conversation

@wernerhp

@wernerhp wernerhp commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

After the bot is @mentioned in a Mattermost channel thread, follow-up
messages in that thread are answered without requiring another @mention,
matching Slack adapter behaviour.

  • Tracks active threads in _mentioned_threads (bounded to _MENTIONED_THREADS_MAX = 5000)
  • Opt-out via MATTERMOST_STRICT_MENTION env var or mattermost.strict_mention: true in config.yaml
  • _has_active_session_for_thread(): secondary auto-follow signal — responds in threads with an existing session even after a restart (mirrors SlackAdapter._has_active_session_for_thread)
  • _apply_yaml_config bridge for MATTERMOST_STRICT_MENTION (consistent with require_mention pattern)

Related Issues

Closes #54188

Type of Change

  • New feature (opt-in behaviour, opt-out via strict_mention)
  • Tests

Changes Made

  • plugins/platforms/mattermost/adapter.py: _mentioned_threads, _mm_strict_mention(), _has_active_session_for_thread(), gate ladder, _apply_yaml_config bridge
  • tests/gateway/test_mattermost.py: in-thread auto-response, strict-mention, session-continuity coverage
  • website/docs/reference/environment-variables.md: MATTERMOST_STRICT_MENTION row
  • website/docs/user-guide/messaging/mattermost.md: configuration guidance

Copilot AI review requested due to automatic review settings June 28, 2026 10:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Slack-parity “engaged thread” behavior to the Mattermost gateway adapter: after the bot is first @mentioned in a thread, it will respond to subsequent messages in that thread without requiring another mention (with an opt-out strict mode).

Changes:

  • Track “mentioned threads” in the Mattermost adapter and bypass the mention gate for follow-ups in those threads (unless strict mention mode is enabled).
  • Add Mattermost gateway tests covering in-thread auto-response and strict-mention behavior.
  • Update Mattermost docs + environment variable reference to document MATTERMOST_STRICT_MENTION and the in-thread behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
plugins/platforms/mattermost/adapter.py Implements bounded per-thread engagement tracking and strict-mention toggle.
tests/gateway/test_mattermost.py Adds test cases for in-thread auto-response + strict mention behavior.
website/docs/user-guide/messaging/mattermost.md Documents new in-thread conversation behavior and strict mention opt-out.
website/docs/reference/environment-variables.md Documents MATTERMOST_STRICT_MENTION (and also includes additional unrelated env-var doc edits).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/platforms/mattermost/adapter.py
Comment thread plugins/platforms/mattermost/adapter.py Outdated
Comment thread website/docs/reference/environment-variables.md Outdated
Comment thread website/docs/reference/environment-variables.md Outdated
@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 28, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary\n\nVerdict: LGTM\n\nMattermost in-thread auto-response: after an @mention, follow-ups in the same thread bypass the mention gate. Bounded by _MENTIONED_THREADS_MAX (5000). Configurable via MATTERMOST_STRICT_MENTION env var or config.extra.strict_mention. Clean implementation mirroring Slack adapter behavior.\n\n---\nReviewed by Hermes Agent

@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from ddbe6e3 to 7ee6a63 Compare June 28, 2026 11:21
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from a2ebff8 to 9872d21 Compare June 28, 2026 11:40

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well-designed Mattermost feature (115 additions). After an @mention, follow-ups in the same thread skip the mention gate. Bounded by _MENTIONED_THREADS_MAX (5000). MATTERMOST_STRICT_MENTION env var for opt-out. Good test coverage and documentation.

Reviewed by Hermes Agent

@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 9872d21 to 2ef9363 Compare June 28, 2026 14:02
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 2ef9363 to b9419b3 Compare June 28, 2026 21:10
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch 2 times, most recently from b53a2ef to 79548f9 Compare June 28, 2026 21:37
@wernerhp wernerhp changed the title feat(mattermost): in-thread auto-response without @mention each turn feat(mattermost): follow thread after @mention (Slack parity) Jun 28, 2026
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch 10 times, most recently from e43b51a to 3f634be Compare June 30, 2026 18:01
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch 8 times, most recently from 3ecbdd4 to 125171b Compare July 2, 2026 02:01
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 125171b to 1ae4ba9 Compare July 2, 2026 10:01

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused Mattermost parity work. The reported default behavior remains present on current main: plugins/platforms/mattermost/adapter.py:849-854 returns before an unmentioned thread reply reaches the event handler.

Problems

  • The restart fallback builds its source with user_id=None at plugins/platforms/mattermost/adapter.py:1070, while the real inbound path uses sender_id at plugins/platforms/mattermost/adapter.py:934-940. With thread_sessions_per_user=True, gateway/session.py:949-957 appends that user ID, so the fallback cannot find the stored session.
  • The same fallback omits the profile namespace (plugins/platforms/mattermost/adapter.py:1086-1090). In multiplex mode, the runner stamps source.profile before dispatch (gateway/run.py:8629-8638) and SessionStore uses it in generated keys (gateway/session.py:1358-1365), so secondary-profile recovery also misses.

Suggested changes

  • Derive the recovery key from the full inbound session identity, including user and profile, or defer the persistent fallback while retaining the in-process mentioned-thread behavior.
  • Add regressions for per-user thread sessions and multiplexed-profile sessions; the current key test only covers the shared/default path.

Automated hermes-sweeper review.

Comment thread plugins/platforms/mattermost/adapter.py Outdated
Comment thread plugins/platforms/mattermost/adapter.py
@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
wernerhp pushed a commit to wernerhp/hermes-agent that referenced this pull request Jul 15, 2026
…ssion lookup

teknium1 review on PR NousResearch#54193: _has_active_session_for_thread recomputed the
session key with user_id=None and no profile namespace, so post-restart
thread-continuation lookups always missed sessions created with
thread_sessions_per_user=True or under a secondary adapter profile.

- Thread the inbound post's sender_id through to the lookup so the key
  matches session creation when thread_sessions_per_user=True.
- Resolve the profile namespace via SessionStore._resolve_profile_for_key
  so secondary-profile sessions (agent:<profile>) are found instead of
  silently searching agent:main.
- Add regression tests pinning both behaviors (revert-to-fail verified).
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 278fd9d to 24dfd03 Compare July 25, 2026 15:12
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 7c520c4 to 39be51c Compare July 30, 2026 06:04
After the bot is @mentioned in a non-DM Mattermost channel, follow-up
messages in that thread are answered without re-mentioning, matching the
existing Slack behaviour. Opt out with `strict_mention: true` in the
mattermost config block (bridged to MATTERMOST_STRICT_MENTION internally).
Fixes the session-key chat_type mismatch that would silently no-op the
session-presence check in public channels.
…ssion lookup

teknium1 review on PR NousResearch#54193: _has_active_session_for_thread recomputed the
session key with user_id=None and no profile namespace, so post-restart
thread-continuation lookups always missed sessions created with
thread_sessions_per_user=True or under a secondary adapter profile.

- Thread the inbound post's sender_id through to the lookup so the key
  matches session creation when thread_sessions_per_user=True.
- Resolve the profile namespace via SessionStore._resolve_profile_for_key
  so secondary-profile sessions (agent:<profile>) are found instead of
  silently searching agent:main.
- Add regression tests pinning both behaviors (revert-to-fail verified).
@wernerhp
wernerhp force-pushed the feat/54188-mattermost-in-thread-autorespond branch from 885e4a7 to bb34d76 Compare August 4, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mattermost): in-thread auto-response — @mention required on every turn

5 participants