Skip to content

fix(matrix): add accountId routing for multi-account message sending 🤖#23333

Closed
BadTurki wants to merge 4 commits into
openclaw:mainfrom
BadTurki:main
Closed

fix(matrix): add accountId routing for multi-account message sending 🤖#23333
BadTurki wants to merge 4 commits into
openclaw:mainfrom
BadTurki:main

Conversation

@BadTurki

@BadTurki BadTurki commented Feb 22, 2026

Copy link
Copy Markdown

Summary

  • Problem: Matrix channels with multiple accounts incorrectly used the default/first authenticated account when sending images, instead of the account bound to the agent.
  • Why it matters: Multi-account Matrix setups would fail to send media from non-default accounts due to wrong account routing.
  • What changed: Added accountId propagation through the message tool chain (Matrix actions → tool handlers → threading context → message-action-runner).
  • What did NOT change: No changes to auth, config schema, or other channels.

Change Type

  • Bug fix

Scope

  • Integrations

Linked Issue/PR

  • Related # (add if there's an existing issue)

User-visible / Behavior Changes

  • Matrix multi-account setups now correctly route outbound messages/media through the account bound to each agent.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Debian Linux
  • Runtime: Node 22+
  • Integration/channel: Matrix

Steps

  1. Configure Matrix channel with 2 accounts (default and muse)
  2. Bind main agent → default account, muse agent → muse account
  3. Send image via muse agent in its Matrix DM

Expected

  • Image sends successfully using the muse account

Actual (before fix)

  • System attempted to send with default account, failing because that account isn't in the DM

Actual (after fix)

  • Image sends correctly using the muse account

Evidence

  • Tested manually with multi-account Matrix setup

Human Verification

  • Verified scenarios: Both accounts can send messages and images in their respective DMs
  • Edge cases checked: Private DM channels for each account
  • What you did NOT verify: Group rooms, other media types

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery

  • How to disable/revert: Revert commit
  • Known bad symptoms: None expected

Risks and Mitigations

  • Risk: None - additive change only adds optional accountId parameter
    • Mitigation: N/A

AI Assistance Disclosure

🤖 AI-assisted: This PR was developed with AI assistance.

  • Degree of testing: Fully tested - manual testing with live Matrix multi-account setup
  • AI tools used: Kline+GLM-5 for diagnosis and commit preparation (10M tokens)
  • Understanding confirmation: I understand what this code does - it threads accountId through the Matrix message sending pipeline so that multi-account setups route outbound messages through the correct account instead of always using the default/first authenticated account.

Greptile Summary

Added accountId propagation through Matrix message sending pipeline to fix multi-account routing. When multiple Matrix accounts are configured and bound to different agents, outbound messages (especially media) now correctly route through the agent's bound account instead of defaulting to the first authenticated account.

Key changes:

  • Threads accountId from ChannelMessageActionContext through Matrix actions, tool handlers, and message runner
  • Adds currentAccountId field to ChannelThreadingToolContext type with JSDoc
  • Routes accountId from HTTP headers (x-openclaw-message-to) to tool context in gateway
  • Falls back to toolContext.currentAccountId before defaultAccountId in message action runner

What works:

  • The implementation correctly propagates accountId through all layers for send action
  • Maintains backward compatibility with optional parameters
  • Follows existing multi-account patterns established in commit 2b685b0
  • Type definitions are properly updated with documentation

Incomplete coverage:

  • Other Matrix actions (react, edit, delete, read, pin, unpin, etc.) don't receive ctx.accountId from the action adapter in extensions/matrix/src/actions.ts:86-192, though they accept it via MatrixActionClientOpts. This means these actions may still route to wrong accounts in multi-account setups.

Confidence Score: 4/5

  • Safe to merge - focused bug fix with proper typing and backward compatibility
  • The implementation correctly threads accountId through the Matrix message sending pipeline. All changes are additive (optional parameters), maintaining backward compatibility. The code follows established patterns from previous multi-account fixes. Score is 4 (not 5) because other Matrix actions could have the same routing issue but aren't addressed in this PR.
  • No files require special attention - all changes are straightforward parameter additions

Last reviewed commit: 4977888

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

BadTurki and others added 3 commits February 21, 2026 22:06
- Thread accountId through Matrix message actions and tool handlers
- Add currentAccountId to ChannelThreadingToolContext for outbound routing
- Plumb x-openclaw-message-to header as currentChannelId in gateway HTTP handler
- Add fallback to toolContext.currentAccountId in message-action-runner

Fixes an issue where Matrix channels with multiple accounts would
incorrectly use the default/first authenticated account when sending
images instead of the account bound to the agent.
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix gateway Gateway runtime agents Agent runtime and tooling size: XS labels Feb 22, 2026

@greptile-apps greptile-apps Bot 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.

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

extensions/matrix/src/actions.ts
Other Matrix actions (react, edit, delete, read, pin, unpin) also resolve clients and could benefit from accountId routing for consistency. Consider adding accountId: ctx.accountId ?? undefined to these actions too.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/matrix/src/actions.ts
Line: 86-99

Comment:
Other Matrix actions (react, edit, delete, read, pin, unpin) also resolve clients and could benefit from `accountId` routing for consistency. Consider adding `accountId: ctx.accountId ?? undefined` to these actions too.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@BadTurki

BadTurki commented Feb 23, 2026

Copy link
Copy Markdown
Author

Pulling this PR. Breaking changes made this PR no longer work. I will have to stick to my branch for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: matrix Channel integration: matrix gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant