feat(mattermost): add sticky thread routing#9731
Draft
wangai-studio wants to merge 1 commit into
Draft
Conversation
Collaborator
|
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. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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