From bf4e348440808faee7eb0704a4879ea32cc45119 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Mon, 9 Feb 2026 08:19:21 -0700 Subject: [PATCH] fix: de-duplicate normalized account IDs and add case-insensitive config lookup to send/client --- extensions/matrix/src/matrix/accounts.ts | 12 ++++++--- extensions/matrix/src/matrix/send/client.ts | 28 ++++++++++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/extensions/matrix/src/matrix/accounts.ts b/extensions/matrix/src/matrix/accounts.ts index 2da5614abf..5b094af6e7 100644 --- a/extensions/matrix/src/matrix/accounts.ts +++ b/extensions/matrix/src/matrix/accounts.ts @@ -18,10 +18,14 @@ function listConfiguredAccountIds(cfg: CoreConfig): string[] { if (!accounts || typeof accounts !== "object") { return []; } - // Normalize keys so listing and resolution use the same semantics - return Object.keys(accounts) - .filter(Boolean) - .map((id) => normalizeAccountId(id)); + // Normalize and de-duplicate keys so listing and resolution use the same semantics + return [ + ...new Set( + Object.keys(accounts) + .filter(Boolean) + .map((id) => normalizeAccountId(id)), + ), + ]; } export function listMatrixAccountIds(cfg: CoreConfig): string[] { diff --git a/extensions/matrix/src/matrix/send/client.ts b/extensions/matrix/src/matrix/send/client.ts index c1938d4c39..8bbc364d22 100644 --- a/extensions/matrix/src/matrix/send/client.ts +++ b/extensions/matrix/src/matrix/send/client.ts @@ -18,13 +18,33 @@ export function ensureNodeRuntime() { } } +/** Look up account config with case-insensitive key fallback. */ +function findAccountConfig( + accounts: Record | undefined, + accountId: string, +): Record | undefined { + if (!accounts) return undefined; + const normalized = normalizeAccountId(accountId); + // Direct lookup first + if (accounts[normalized]) return accounts[normalized] as Record; + // Case-insensitive fallback + for (const key of Object.keys(accounts)) { + if (normalizeAccountId(key) === normalized) { + return accounts[key] as Record; + } + } + return undefined; +} + export function resolveMediaMaxBytes(accountId?: string): number | undefined { const cfg = getCore().config.loadConfig() as CoreConfig; - // Check account-specific config first (normalize to ensure consistent keying) - const normalized = normalizeAccountId(accountId); - const accountConfig = cfg.channels?.matrix?.accounts?.[normalized]; + // Check account-specific config first (case-insensitive key matching) + const accountConfig = findAccountConfig( + cfg.channels?.matrix?.accounts as Record | undefined, + accountId ?? "", + ); if (typeof accountConfig?.mediaMaxMb === "number") { - return accountConfig.mediaMaxMb * 1024 * 1024; + return (accountConfig.mediaMaxMb as number) * 1024 * 1024; } // Fall back to top-level config if (typeof cfg.channels?.matrix?.mediaMaxMb === "number") {