Skip to content

fix: use profile-scoped get_secret for MATRIX_RECOVERY_KEY (#69090) - #70633

Closed
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/69090-matrix-recovery-key-profile-scope
Closed

fix: use profile-scoped get_secret for MATRIX_RECOVERY_KEY (#69090)#70633
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/69090-matrix-recovery-key-profile-scope

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Summary

  • Replaces os.getenv("MATRIX_RECOVERY_KEY") with profile-scoped get_secret("MATRIX_RECOVERY_KEY", "") in the Matrix adapter
  • Fixes E2EE recovery key verification failure in multi-profile gateway mode

Root Cause

In multi-profile gateway mode (gateway.multiplex_profiles), the Matrix adapter reads MATRIX_RECOVERY_KEY using os.getenv(). Since os.environ is process-global, every profile reads the default profile's recovery key from the process environment. Non-default profiles' recovery keys (stored in their <profile>/.env) are never read, causing "Key MAC does not match" E2EE verification failures.

Fix

Replace os.getenv("MATRIX_RECOVERY_KEY", "") with get_secret("MATRIX_RECOVERY_KEY", "") from agent.secret_scope. The get_secret function:

  • Reads from the active profile's secret scope when multiplexing is active
  • Falls back to os.environ for single-profile deployments (backward compatible)
  • Properly isolates secrets between concurrent profile turns

Changed at two call sites:

  1. Line 1442: recovery key verification during startup
  2. Line 1740: recovery_key_configured status in diagnostics

Test Plan

  • Existing Matrix adapter tests still pass
  • Manual test: configure two profiles with different MATRIX_RECOVERY_KEY values, verify each profile uses its own key

Closes #69090

…rch#69090)

In multi-profile gateway mode, os.getenv() reads from the process
environment which holds the default profile's value. This caused
non-default profiles to use the wrong recovery key, resulting in
"Key MAC does not match" E2EE verification failures.

Replace os.getenv('MATRIX_RECOVERY_KEY') with get_secret() from
agent.secret_scope which honors the active profile's .env file.

Closes NousResearch#69090
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/matrix Matrix adapter (E2EE) area/profiles Multi-profile isolation, HERMES_HOME scoping duplicate This issue or pull request already exists labels Jul 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #69110. It implements the same profile-scoped recovery-key mechanism, including the unscoped multiplex fallback and focused regression coverage; this narrower patch omits those safeguards.

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

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/matrix Matrix adapter (E2EE) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix adapter uses only the default recovery key in multi-profile mode

2 participants