Skip to content

fix(mattermost): extend session-continuity root-id fix to DM channels - #54229

Open
wernerhp wants to merge 4 commits into
NousResearch:mainfrom
wernerhp:fix/37144-dm-session-continuity
Open

fix(mattermost): extend session-continuity root-id fix to DM channels#54229
wernerhp wants to merge 4 commits into
NousResearch:mainfrom
wernerhp:fix/37144-dm-session-continuity

Conversation

@wernerhp

@wernerhp wernerhp commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Extends the session-continuity fix from #37144 to DM channels, which the original PR excluded via channel_type_raw != "D".

Root DM posts had thread_id=None; replies carried root_id=<root post id>. This produced two different session keys, so the agent lost all context on the first threaded DM reply. #37144 fixed this for channels but left DMs broken.

Removing the channel_type_raw != "D" guard gives DMs the same treatment: thread_id = post.get("root_id") or post_id when reply_mode == "thread".

-        if (
-            not thread_id
-            and self._reply_mode == "thread"
-            and channel_type_raw != "D"
-            and post_id
-        ):
-            thread_id = post_id
+        if thread_id is None and self._reply_mode == "thread":
+            thread_id = post_id

Related Issue

Fixes #18279
Relates to #37144

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • plugins/platforms/mattermost/adapter.py: remove channel_type_raw != "D" guard from thread-id seeding logic.
  • tests/gateway/test_mattermost.py: 2 new tests — DM root post seeding and DM thread reply resolves to same session.

How to Test

  1. Configure Hermes with a Mattermost gateway in reply_mode: thread.
  2. Send a direct message to the bot. Note the session key.
  3. Reply in the DM thread. The agent should retain context from step 2.
  4. Without this fix, step 3 produces a fresh session (no prior context).
  5. pytest tests/gateway/test_mattermost.py -v -k "dm" — both new DM tests pass.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) — N/A (gateway-only)
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state 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.

Clean DM session-continuity fix (57 additions). Extends root-id seeding to DM channels so threaded DM replies land in the same session. Includes regression test and reply test. Simple, well-targeted.

Reviewed by Hermes Agent

@wernerhp
wernerhp force-pushed the fix/37144-dm-session-continuity branch from c7b24d2 to 91e327c Compare June 28, 2026 21:08
@wernerhp
wernerhp marked this pull request as ready for review June 28, 2026 21:08
Copilot AI review requested due to automatic review settings June 28, 2026 21:08

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

This PR extends the Mattermost session-continuity fix (originally added for non-DM threads) to DM threads when reply_mode == "thread", ensuring a DM thread’s root post and its replies map to the same gateway session key and therefore keep agent context across threaded follow-ups.

Changes:

  • Update the Mattermost adapter’s inbound thread_id derivation so that, in thread reply mode, a root post falls back to using its own post_id as thread_id (now applied to DMs as well).
  • Replace the prior DM-specific expectation in tests with new assertions that DM root posts seed thread_id, and DM threaded replies continue to use root_id as thread_id.

Reviewed changes

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

File Description
plugins/platforms/mattermost/adapter.py Extends thread-mode root-post thread_id seeding to include DM channels, preventing DM thread session splits.
tests/gateway/test_mattermost.py Adds/updates regression tests covering DM root seeding and DM reply thread_id behavior in thread mode.

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

@wernerhp
wernerhp force-pushed the fix/37144-dm-session-continuity branch 13 times, most recently from afe111f to 077e5d9 Compare July 2, 2026 10:01
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused regression fix. Current main still excludes DM roots from thread-id seeding at plugins/platforms/mattermost/adapter.py:869-876; those roots therefore have no thread_id, while gateway/session.py:912-915 appends the reply's root_id to the DM session key. The proposed change makes both messages use the root post ID.

The existing test at tests/gateway/test_mattermost.py:1060-1086 verifies the old behavior, and the PR adds complementary root/reply coverage. The patch applies cleanly to current main because neither changed path has changed since base 4281151ae859241351ba14d8c7682dc67ff4c126.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 15, 2026
@wernerhp
wernerhp force-pushed the fix/37144-dm-session-continuity branch 2 times, most recently from fcf320b to 2c78cab Compare July 30, 2026 06:04
… (PR NousResearch#37144)

Root DM posts had thread_id=None; replies carried root_id=<root>.
Result: two different session keys → agent lost all context on first reply.

Prior fix excluded DM channels (channel_type_raw != 'D' guard).
This removes that exclusion so DMs get the same treatment:
  thread_id = post.get('root_id') or post_id (in thread mode)

Port of upstream PR NousResearch#37144 extended to cover DM channel type.
…ix (NousResearch#37144)

The prior test asserted thread_id=None for DM root posts — which was the
old broken behaviour that caused session context loss on first threaded reply.

Commit a062424fb intentionally removed the 'channel_type_raw != D' guard
so DMs get the same root-post seeding as channels.  Update the test to:
  - Rename and doc the test to describe the fixed behaviour
  - Assert thread_id == post_id for DM root posts (correct)
  - Add companion test: DM replies carry root_id → same session key
@wernerhp
wernerhp force-pushed the fix/37144-dm-session-continuity branch from a9d1849 to a4fcd8f 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

area/sessions Session lifecycle, resume, persistence, history comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mattermost root threads share one session and block parallel conversations

5 participants