The handler was calling resolveAgentRoute without accountId, causing
all Matrix messages to route to the default agent regardless of which
account received them.
Changes:
- Add accountId to MatrixMonitorHandlerParams type
- Extract accountId in createMatrixRoomMessageHandler
- Pass accountId to resolveAgentRoute call
- Pass accountId from monitorMatrixProvider to handler
The parallel account startup was crashing because the dynamic import
of ./matrix/index.js returned undefined when called concurrently.
Added importMatrixIndex() to import-mutex.ts and use it in channel.ts
to ensure the module is only imported once during parallel startup.
Problem: When multiple Matrix accounts start in parallel, they all trigger
dynamic imports simultaneously. The Rust native crypto module
(@matrix-org/matrix-sdk-crypto-nodejs) crashes when loaded in parallel.
Solution: Add import-mutex.ts that caches import promises. Concurrent callers
now await the same promise instead of triggering parallel imports.
Files changed:
- NEW: src/matrix/import-mutex.ts - serializedImport() utility
- src/matrix/client/create-client.ts - use importCryptoNodejs()
- src/matrix/client/config.ts - use importCredentials()
- Modified shared.ts to maintain a Map of clients per accountId
- Each account gets its own Matrix client instance
- Backwards compatible with single-account usage
- resolveMatrixAuth now accepts accountId parameter
- stopSharedClient can stop specific or all accounts
Files changed:
- src/matrix/client/shared.ts (main changes)
- src/matrix/client/config.ts (accountId support)
- src/matrix/accounts.ts (list enabled accounts)
- src/matrix/monitor/index.ts (pass accountId)
- src/types.ts (accounts config type)