-
Notifications
You must be signed in to change notification settings - Fork 48.1k
fix(mattermost): resolve thread follow-ups and tool output leaks (#4221) #4230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devorun
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
devorun:patch-19
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,8 @@ def __init__(self, config: PlatformConfig): | |
| self._SEEN_MAX = 2000 | ||
| self._SEEN_TTL = 300 # 5 minutes | ||
|
|
||
| self._known_threads: set[str] = set() | ||
|
|
||
| # ------------------------------------------------------------------ | ||
| # HTTP helpers | ||
| # ------------------------------------------------------------------ | ||
|
|
@@ -265,15 +267,21 @@ async def send( | |
| formatted = self.format_message(content) | ||
| chunks = self.truncate_message(formatted, MAX_POST_LENGTH) | ||
|
|
||
| thread_root = reply_to | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if not thread_root and metadata: | ||
| thread_root = metadata.get("thread_id") | ||
|
|
||
| last_id = None | ||
| for chunk in chunks: | ||
| payload: Dict[str, Any] = { | ||
| "channel_id": chat_id, | ||
| "message": chunk, | ||
| } | ||
| # Thread support: reply_to is the root post ID. | ||
| if reply_to and self._reply_mode == "thread": | ||
| payload["root_id"] = reply_to | ||
| if thread_root and self._reply_mode == "thread": | ||
| payload["root_id"] = thread_root | ||
| if hasattr(self, "_known_threads"): | ||
| self._known_threads.add(thread_root) | ||
|
|
||
| data = await self._api_post("posts", payload) | ||
| if not data or "id" not in data: | ||
|
|
@@ -625,13 +633,19 @@ async def _handle_ws_event(self, event: Dict[str, Any]) -> None: | |
| for pattern in mention_patterns | ||
| ) | ||
|
|
||
| if require_mention and not is_free_channel and not has_mention: | ||
| thread_id = post.get("root_id") or None | ||
| bot_involved = thread_id and hasattr(self, "_known_threads") and thread_id in self._known_threads | ||
|
|
||
| if require_mention and not is_free_channel and not has_mention and not bot_involved: | ||
| logger.debug( | ||
| "Mattermost: skipping non-DM message without @mention (channel=%s)", | ||
| channel_id, | ||
| ) | ||
| return | ||
|
|
||
| if thread_id and hasattr(self, "_known_threads"): | ||
| self._known_threads.add(thread_id) | ||
|
|
||
| # Strip @mention from the message text so the agent sees clean input. | ||
| if has_mention: | ||
| for pattern in mention_patterns: | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This set is never bounded or expired, so a long-lived gateway retains every thread root and permanently bypasses mention gating for it. Please use bounded ownership/expiry semantics rather than process-lifetime membership.