From d0072125fe212f9349659bcdcd72091941575763 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 02:26:49 +0000 Subject: [PATCH] fix(chats): remove null from LRUCache type to satisfy TypeScript constraint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL FIX: Resolves TypeScript compilation error preventing npm install ERROR: src/Socket/chats.ts(117,52): error TS2344: Type 'IAppStateSyncKeyData | null' does not satisfy the constraint '{}'. Type 'null' is not assignable to type '{}'. ROOT CAUSE: LRUCache v10+ has a generic constraint where value type V must satisfy constraint {}. The type 'IAppStateSyncKeyData | null' includes null, which doesn't satisfy {}. ANALYSIS: The code NEVER caches null values (line 152 only calls set() if key is truthy), so the | null in the type declaration was unnecessary and incorrect. SOLUTION: 1. Remove | null from LRUCache type parameter (line 121) 2. Simplify getCachedAppStateSyncKey return (line 143) 3. Add documentation about type safety VALIDATION: ✓ TypeScript error TS2344 resolved ✓ Logic unchanged: still only caches non-null values ✓ LRUCache.get() still returns undefined for missing keys ✓ Null cache poisoning prevention maintained (commit 4e05e62) This fix enables successful npm install and build. https://claude.ai/code/session_01NTVq3RHgGpgKL289JGvw55 --- src/Socket/chats.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 82cd2626..103728e2 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -113,8 +113,12 @@ export const makeChatsSocket = (config: SocketConfig) => { * * MEMORY SAFETY: Limited by DEFAULT_CACHE_MAX_KEYS.SIGNAL_STORE with 1-hour TTL. * Auto-purges expired entries to maintain memory bounds. + * + * TYPE SAFETY: Only successful lookups (non-null values) are cached. + * Null/undefined values are NOT cached to prevent blocking newly arrived keys. + * LRUCache.get() returns undefined for missing keys. */ - const appStateSyncKeyCache = new LRUCache({ + const appStateSyncKeyCache = new LRUCache({ max: DEFAULT_CACHE_MAX_KEYS.SIGNAL_STORE, // Use constant from Defaults (10,000) ttl: DEFAULT_CACHE_TTLS.MSG_RETRY * 1000, // 1 hour TTL (convert seconds to ms) ttlAutopurge: true, // Automatically remove expired entries @@ -135,9 +139,8 @@ export const makeChatsSocket = (config: SocketConfig) => { // Use get() directly to avoid race between has() and get() (Fix: Copilot C) const cached = appStateSyncKeyCache.get(keyId) if (cached !== undefined) { - // Null in cache means we explicitly cached a null (which we don't do anymore) - // Undefined means not in cache - return cached ?? undefined + // Cache hit - return the cached key + return cached } // Cache miss - fetch from database