refactor: improve libsignal error logging and deduplication

Implements 4 key improvements to reduce log noise and duplicates:

1.  Remove console.log interceptor
   - Libsignal only uses console.error for errors
   - Eliminates duplicate interception (was logging 2x per error)
   - Reduces code by 50+ lines

2.  Increase deduplication window (100ms → 150ms)
   - Better coverage for rapid sequential errors
   - Configurable via DEDUP_WINDOW_MS constant

3.  Type + JID tracking for smart deduplication
   - Uses Map<string, number> instead of single variable
   - Deduplication key: "errorType:maskedJID"
   - Prevents false positives (different error types now tracked separately)
   - Memory-safe: auto-cleanup keeps last 50 entries max

4.  Concise session recreation summary
   - Before: Verbose multi-line debug logs
   - After: Single line "🔄 Session Reset | JID: 4680****_1.0 | Cleared: 6 devices"
   - Shows masked JID, deleted count, and next action
   - cleanupCorruptedSession() now returns deletion count

Expected log improvement:
- Before: 3-9 duplicate logs per error burst
- After: 1 log per unique error type per contact

https://claude.ai/code/session_01TvSrN9JmHZDdKMZDFWEcUS
This commit is contained in:
Claude
2026-02-12 20:36:45 +00:00
parent 6c6f49d93f
commit 1ef4095fee
2 changed files with 33 additions and 70 deletions
+11 -9
View File
@@ -425,10 +425,15 @@ export const decryptMessageNode = (
// Automatic cleanup of corrupted session (if enabled)
if (autoCleanCorrupted) {
try {
await cleanupCorruptedSession(decryptionJid, repository, logger)
const deletedCount = await cleanupCorruptedSession(decryptionJid, repository, logger)
// Mask JID for privacy (show first 4 and last 4 digits)
const maskedJid = decryptionJid.length > 8
? `${decryptionJid.substring(0, 4)}****${decryptionJid.substring(decryptionJid.length - 4)}`
: decryptionJid
logger.info(
{ decryptionJid, author },
'✅ Corrupted session cleaned up. New session will be created on next message.'
`🔄 Session Reset | JID: ${maskedJid} | Cleared: ${deletedCount} devices | Will recreate on next message`
)
} catch (cleanupErr) {
logger.error(
@@ -500,11 +505,11 @@ async function cleanupCorruptedSession(
jid: string,
repository: SignalRepositoryWithLIDStore,
logger: ILogger
): Promise<void> {
): Promise<number> {
const { user, device } = jidDecode(jid) || {}
if (!user) {
logger.warn({ jid }, 'Cannot cleanup session - invalid JID')
return
return 0
}
// Build list of JIDs to delete (primary + secondary devices)
@@ -541,8 +546,5 @@ async function cleanupCorruptedSession(
await repository.deleteSession(jidsToDelete)
logger.debug(
{ jid, user, device, deletedSessions: jidsToDelete },
'Deleted corrupted sessions for user'
)
return jidsToDelete.length
}