Fix: Load encryption store for token/OIDC authentication to enable E2E encryption #14
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.
Problem
The bot was unable to respond to commands in encrypted Matrix rooms when using token or OIDC authentication. Users would see the bot connect successfully and log room events, but commands like
!cd helpor!cd projectsreceived no response.The error logs revealed:
Root Cause
The matrix-nio library requires the encryption store to be loaded before the client can handle encrypted messages. When using password authentication, this happens automatically via
client.login(). However, when using token or OIDC authentication, the authentication flow bypasses the login method and directly sets the access token, which means the store is never loaded.Without the loaded store:
Solution
Added an explicit
await self.client.load_store()call in the token/OIDC authentication path before setting the access token. This ensures the encryption store (including the Olm account and megolm sessions) is properly loaded from disk, enabling the bot to handle encrypted messages.Changes:
chatrixcd/bot.py: Load encryption store before setting access token for token/OIDC authtests/test_bot.py: Add test case to verify store loading during token authenticationARCHITECTURE.md: Update authentication flow documentationTesting
Added unit test
test_login_token_loads_storethat verifies:Impact
This fix resolves the issue for users deploying the bot with:
Password authentication continues to work as before (store loading is automatic).
Fixes #[issue-number]
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.