From f0768d4c328d81614c24767fa34299f9570bf483 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Tue, 9 Jun 2026 14:58:18 -0700 Subject: [PATCH] fix(parser): isolate Claude per-file parse failures The per-file failure isolation #441 added to the provider path was missing on the Claude path: a throw in groupIntoTurns/canonicalization propagated up and emptied the whole daily-history backfill. Wrap the per-file parse in try/catch + a failed marker, mirroring the provider path; one bad file no longer wipes the trend. --- src/parser.ts | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 085f7d77..dec65742 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1526,22 +1526,33 @@ async function scanProjectDirs( for (const { filePath, info } of changedFiles) { delete section.files[filePath] - const tracker = { lastCompleteLineOffset: 0 } - const entries = await parseClaudeEntries(filePath, tracker) - if (!entries) continue + try { + const tracker = { lastCompleteLineOffset: 0 } + const entries = await parseClaudeEntries(filePath, tracker) + if (!entries) continue - const turns = groupIntoTurns(dedupeStreamingMessageIds(entries), seenMsgIds) - const cwd = extractCanonicalCwd(entries) - const canonical = (cwd && !isCoworkSession(cwd, filePath)) ? await resolveCanonicalProjectPath(cwd) : undefined - section.files[filePath] = { - fingerprint: info.fp, - lastCompleteLineOffset: tracker.lastCompleteLineOffset, - canonicalCwd: canonical?.path, - canonicalProjectName: canonical?.isWorktree ? projectNameFromPath(canonical.path, info.dirName) : undefined, - mcpInventory: extractMcpInventory(entries), - turns: turns.map(parsedTurnToCachedTurn), + const turns = groupIntoTurns(dedupeStreamingMessageIds(entries), seenMsgIds) + const cwd = extractCanonicalCwd(entries) + const canonical = (cwd && !isCoworkSession(cwd, filePath)) ? await resolveCanonicalProjectPath(cwd) : undefined + section.files[filePath] = { + fingerprint: info.fp, + lastCompleteLineOffset: tracker.lastCompleteLineOffset, + canonicalCwd: canonical?.path, + canonicalProjectName: canonical?.isWorktree ? projectNameFromPath(canonical.path, info.dirName) : undefined, + mcpInventory: extractMcpInventory(entries), + turns: turns.map(parsedTurnToCachedTurn), + } + ;(diskCache as { _dirty?: boolean })._dirty = true + } catch (err) { + // A single malformed Claude session file must not abort the whole run — that + // would empty the daily-cache backfill and wipe the trend/history (issue #441, + // same isolation the provider path already has). Record a failure marker keyed + // by the current fingerprint so it isn't re-read and re-thrown every run; it + // re-parses only if the file changes. + section.files[filePath] = { fingerprint: info.fp, mcpInventory: [], turns: [], failed: true } + ;(diskCache as { _dirty?: boolean })._dirty = true + warnProviderParseFailure('claude', filePath, err) } - ;(diskCache as { _dirty?: boolean })._dirty = true } if (dirs.length > 0) {