From 4692588a6c608018826eb3ee3766e76e01c04b51 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 17 Jan 2026 21:58:07 +0000 Subject: [PATCH] fix: add critical encrypted content cache diagnostics Add comprehensive logging to trace JSON parse errors: 1. **EncryptedContentStorage logging**: - Log all getItem calls showing what's retrieved from IndexedDB - Log all setItem calls showing what's being stored - Shows first 100 chars of plaintext to identify corruption 2. **Gift wrap unlock state tracking**: - Count events with applesauce symbols attached - Count events found in persistedIds cache - Distinguish between symbol-based vs cache-based unlocking - Format: 'N unlocked (X symbols, Y cached), Z pending' This will reveal if: - Wrong data is being stored in IndexedDB (test strings instead of JSON) - Timing issues where symbols aren't attached yet - Cache not being properly populated from IndexedDB --- src/services/db.ts | 14 +++++++++++++- src/services/gift-wrap.ts | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/services/db.ts b/src/services/db.ts index 5e7c7ea..6333836 100644 --- a/src/services/db.ts +++ b/src/services/db.ts @@ -453,10 +453,22 @@ export const relayLivenessStorage = { export const encryptedContentStorage = { async getItem(id: string): Promise { const entry = await db.encryptedContent.get(id); - return entry?.plaintext ?? null; + const plaintext = entry?.plaintext ?? null; + + if (plaintext) { + console.log( + `[EncryptedContentStorage] getItem(${id.slice(0, 8)}): ${plaintext.slice(0, 100)}...`, + ); + } + + return plaintext; }, async setItem(id: string, plaintext: string): Promise { + console.log( + `[EncryptedContentStorage] setItem(${id.slice(0, 8)}): ${plaintext.slice(0, 100)}...`, + ); + await db.encryptedContent.put({ id, plaintext, diff --git a/src/services/gift-wrap.ts b/src/services/gift-wrap.ts index 61b8a02..65777e5 100644 --- a/src/services/gift-wrap.ts +++ b/src/services/gift-wrap.ts @@ -799,12 +799,18 @@ class GiftWrapService { // Update decrypt states for new gift wraps let newUnlocked = 0; let newPending = 0; + let hasSymbolCount = 0; + let hasPersistedCount = 0; + for (const gw of giftWraps) { if (!this.decryptStates.has(gw.id)) { const hasSymbol = isGiftWrapUnlocked(gw); const hasPersisted = this.persistedIds.has(gw.id); const isUnlocked = hasSymbol || hasPersisted; + if (hasSymbol) hasSymbolCount++; + if (hasPersisted) hasPersistedCount++; + if (isUnlocked) { newUnlocked++; } else { @@ -840,7 +846,7 @@ class GiftWrapService { dmInfo( "GiftWrap", - `Decrypt states: ${newUnlocked} unlocked, ${newPending} pending (total: ${this.decryptStates.size})`, + `Decrypt states: ${newUnlocked} unlocked (${hasSymbolCount} symbols, ${hasPersistedCount} cached), ${newPending} pending (total: ${this.decryptStates.size})`, ); this.decryptStates$.next(new Map(this.decryptStates));