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
This commit is contained in:
Claude
2026-01-17 21:58:07 +00:00
parent dbbd72909f
commit 4692588a6c
2 changed files with 20 additions and 2 deletions

View File

@@ -453,10 +453,22 @@ export const relayLivenessStorage = {
export const encryptedContentStorage = {
async getItem(id: string): Promise<string | null> {
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<void> {
console.log(
`[EncryptedContentStorage] setItem(${id.slice(0, 8)}): ${plaintext.slice(0, 100)}...`,
);
await db.encryptedContent.put({
id,
plaintext,

View File

@@ -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));