feat(mattermost): add sticky thread routing - #9731
Conversation
|
Related to #12063 (Mattermost adapter ignores metadata.thread_id). This PR covers the thread_id fix plus adds sticky-thread ownership via SQLite state store. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused sticky-thread routing work. The core need remains: current main still drops unmentioned Mattermost channel replies at plugins/platforms/mattermost/adapter.py:849.
Problems
- The PR edits the removed legacy adapter at
gateway/platforms/mattermost.py; Mattermost moved toplugins/platforms/mattermost/adapter.pyinaf973e407, so this needs a plugin-targeted port. - The
metadata.thread_id/root_idwork is superseded by current_thread_root_for_send()and_resolve_root_id()atplugins/platforms/mattermost/adapter.py:163-176,326-340(06161c6ed). Preserve that stronger resolver when salvaging. MATTERMOST_THREAD_STICKYis a new behavioral env setting. The existing plugin bridge atplugins/platforms/mattermost/adapter.py:1177-1205should instead receive amattermost.thread_stickyconfig.yaml setting, consistent withAGENTS.md:102-105.- The environment-variable documentation hunk also removes unrelated current entries.
Suggested changes
- Port only sticky ownership and focused coverage to the plugin adapter; remove obsolete root-routing hunks and unrelated documentation edits.
Automated hermes-sweeper review.
|
|
||
| from gateway.config import Platform, PlatformConfig | ||
| from gateway.platforms.helpers import MessageDeduplicator | ||
| from gateway.platforms.mattermost_thread_state import MattermostThreadStateStore |
There was a problem hiding this comment.
Current main no longer imports this adapter path: Mattermost was migrated to plugins/platforms/mattermost/adapter.py in af973e407. Port the sticky-state integration to the plugin adapter; this legacy module is absent from HEAD.
| | `MATTERMOST_ALLOWED_USERS` | Comma-separated Mattermost user IDs allowed to message the bot | | ||
| | `MATTERMOST_HOME_CHANNEL` | Channel ID for proactive message delivery (cron, notifications) | | ||
| | `MATTERMOST_REQUIRE_MENTION` | Require `@mention` in channels (default: `true`). Set to `false` to respond to all messages. | | ||
| | `MATTERMOST_THREAD_STICKY` | Keep a thread bound to the most recently `@mentioned` agent so later replies in that thread do not need another `@mention` (default: `true`). Set to `false` to require `@mention` on every thread turn. | |
There was a problem hiding this comment.
Please make this a mattermost.thread_sticky config.yaml setting and extend the plugin YAML bridge, rather than documenting a new behavioral environment variable. AGENTS.md:102-105 reserves user-facing environment configuration for secrets.
What does this PR do?
Adds thread-aware Mattermost routing with a configurable sticky-thread mode.
This change targets the case where an agent is explicitly
@mentionedinside a Mattermost thread. After that first explicit mention, the thread can stay bound to the active agent so later replies in the same thread do not need another@mention.It also fixes the thread reply payload to prefer
metadata.thread_idas the authoritative Mattermost thread root whenMATTERMOST_REPLY_MODE=thread, while keepingMATTERMOST_REPLY_MODE=offas flat-channel behavior.This PR overlaps with existing Mattermost thread work in #4230 and #6617, but adds two things that are not covered there:
MATTERMOST_THREAD_STICKYmodeIt does not try to solve the separate scenario where a user opens a brand-new child thread under an agent-authored mainline post and expects that new thread to auto-inherit the agent without a fresh
@mention.Related Issue
Related to #4221
Related to #6617
Type of Change
Changes Made
gateway/platforms/mattermost_thread_state.pywith a shared SQLite-backed thread ownership storegateway/platforms/mattermost.pyto:MATTERMOST_THREAD_STICKYmetadata.thread_idoverreply_towhen sending threaded repliesroot_idselectionMATTERMOST_THREAD_STICKYand clarifyMATTERMOST_REPLY_MODEin:website/docs/reference/environment-variables.mdwebsite/docs/user-guide/messaging/mattermost.mdHow to Test
@mentionan agent inside it.@mentionand confirm the same agent continues the conversation.@mentiona different agent and confirm the new agent replies in the thread and becomes the active agent for later unmentioned replies.MATTERMOST_THREAD_STICKY=falseand confirm unmentioned follow-ups in a thread are ignored.MATTERMOST_REPLY_MODE=threadand confirm replies in an existing thread use the correct Mattermostroot_id.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passuv run --extra dev pytest tests/gateway/test_mattermost.py -q)Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Targeted test run:
uv run --extra dev pytest tests/gateway/test_mattermost.py -q 56 passed in 1.76s