Repository navigation
feat(matrix): thread-isolated sessions and per-chat-type threadReplies - #57995
gumadeiras merged 6 commits into
Conversation
Greptile SummaryThis PR adds two improvements to the Matrix plugin: (1) thread-isolated sessions so each Matrix thread gets its own session key ( The per-chat-type The main concern is in Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/matrix/src/matrix/monitor/route.ts
Line: 97-115
Comment:
**Thread isolation ignores `threadReplies` / `dm.threadReplies` setting**
The PR description says `dm.threadReplies: "off"` is intended to "keep DMs flat (no threading)," but the thread-isolation logic here fires unconditionally whenever `threadRootId` differs from `messageId` — it never checks the effective `threadReplies` setting. As a result, even when a user configures `dm.threadReplies: "off"`, any DM message that arrives inside a Matrix thread will receive a thread-scoped session key (`<base>:thread:<rootId>`), silently splitting the conversation history from the non-threaded messages in the same DM.
Concretely:
- `$root` (sent as the thread root) → `messageId == threadRootId` → no isolation → session `agent:…:main`
- `$reply1` (in the same thread) → `messageId != threadRootId` → **isolated** → session `agent:…:main:thread:$root`
So the bot responds without threading (correct, per `dm.threadReplies: "off"`) but with a fresh session that lacks the context of the root message (unintended).
`resolveMatrixInboundRoute` would need to accept the effective `threadReplies` value (or an explicit `isolateThreadSessions` flag) and skip the thread-key block when threading is disabled. There are also no test cases covering `dm.threadReplies: "off"` combined with thread messages, so this gap would go undetected.
```ts
// Proposed guard (sketch):
const effectiveThreadReplies =
params.isDirectMessage && params.dmThreadReplies !== undefined
? params.dmThreadReplies
: params.threadReplies;
if (!configuredBinding && !configuredSessionKey && threadId && effectiveThreadReplies !== "off") {
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(matrix): thread-isolated sessions a..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4657e4dc7b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 550e9ae755
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7de917034c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d69939ae98
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
d69939a to
f3e75c7
Compare
- Append 🧵<threadRootId> to session key when a Matrix thread root is present, giving each thread its own isolated session (mirrors Mattermost replyToMode=all behavior) - Add dm.threadReplies config option to override threadReplies for DMs independently of group rooms - Update handler tests to expect thread-scoped session keys - Add route.test.ts coverage for thread session key isolation Streaming support was already merged upstream in PR openclaw#56387.
f3e75c7 to
9ed96dd
Compare
|
Merged via squash.
Thanks @teconomix! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ed96dd063
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thank you @gumadeiras |
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
openclaw#57995) Merged via squash. Prepared head SHA: 9ed96dd Co-authored-by: teconomix <[email protected]> Co-authored-by: gumadeiras <[email protected]> Reviewed-by: @gumadeiras
#177272) fix(matrix): start new threads with their own history, not the room transcript A new ordinary Matrix thread requested a fork of the whole room transcript, so the first thread turn sent the room's earlier conversation to the model. That broke the isolated thread history established by #57995. New threads now start from their own history. Thread root context, model inheritance, binding selection and the room's own timeline are unchanged. There is no SDK change. Evidence: built Gateway with a real Matrix server. On main, the first turn in a new thread included the room history in the model input (2 of 2). With this change, new threads were isolated (2 of 2). The room timeline, existing-thread history, root context, model inheritance and binding controls behaved the same on both refs. Details: #177272 (comment). Thanks @Linux2010. Co-authored-by: Ayaan Zaidi <[email protected]>
openclaw#177272) fix(matrix): start new threads with their own history, not the room transcript A new ordinary Matrix thread requested a fork of the whole room transcript, so the first thread turn sent the room's earlier conversation to the model. That broke the isolated thread history established by openclaw#57995. New threads now start from their own history. Thread root context, model inheritance, binding selection and the room's own timeline are unchanged. There is no SDK change. Evidence: built Gateway with a real Matrix server. On main, the first turn in a new thread included the room history in the model input (2 of 2). With this change, new threads were isolated (2 of 2). The room timeline, existing-thread history, root context, model inheritance and binding controls behaved the same on both refs. Details: openclaw#177272 (comment). Thanks @Linux2010. Co-authored-by: Ayaan Zaidi <[email protected]>
Summary
Two improvements to the Matrix plugin that should have been part of the streaming PR.
1. Thread-isolated sessions
Currently, when
threadReplies: "always"is set, all threads in a Matrix room share the same session key. This means the agent has no way to keep context separate between different threads in the same room.This PR adds thread-scoped session keys by calling
resolveThreadSessionKeysinresolveMatrixInboundRoute. When athreadRootIdis present (and differs frommessageId), the session key becomes<base>:thread:<threadRootId>— giving each thread its own isolated conversation history, exactly like Mattermost'sreplyToMode: "all"behavior.Binding overrides (runtime and configured ACP bindings) take priority and are unaffected.
2. Per-chat-type
threadRepliesAdds
dm.threadRepliesconfig option, allowing differentthreadRepliesvalues for DMs vs group rooms:{ "channels": { "matrix": { "threadReplies": "always", "dm": { "policy": "pairing", "threadReplies": "off" } } } }This lets you keep group threads isolated (each thread = separate session) while keeping DMs flat (no threading).
Changes
route.ts: ImportresolveThreadSessionKeys; apply thread suffix to session key when thread root presenttypes.ts: AddthreadRepliesfield toMatrixDmConfigconfig-schema.ts: AddthreadRepliesto DM schema (inline expansion ofbuildNestedDmConfigSchema)handler.ts: AdddmThreadRepliesparam; computeeffectiveThreadRepliesper-messageindex.ts: Readdm?.threadRepliesand pass to handlerroute.test.ts: Add 3 tests for thread session key isolationhandler.test.ts,handler.body-for-agent.test.ts: Update expected session keys for threaded messagesNot in scope
Streaming support was already merged in #56387 and requires no further changes.