Repository navigation
Description
[Bug] [pi] Menubar trend chart / daily history is empty — Pi parser crashes on string message.content, error silently swallowed so daily-cache.json is never built
Summary
- The macOS menubar trend chart (and previous-day stats) is empty:
codeburn status --format menubar-jsonreturns only today inhistory.daily, regardless of--period. - Root cause: the 365-day backfill that builds
daily-cache.json(hydrateCache→ensureCacheHydrated→parseAllSessions) throws while parsing a Pi (~/.pi/agent/sessions) session whose usermessage.contentis a string instead of an array. hydrateCache()wraps the backfill intry { … } catch { return emptyCache2() }, so the crash is silently swallowed — no error, no log even with--verbose.daily-cache.jsonis never written, so the trend has only one data point.- The period aggregates (7d/30d/month) are correct because they don't reach the offending file; only the longer backfill does. This is very likely the underlying cause of [Bug] Previous day usage always reported as 0 #425 and is related to Menubar Lifetime period should use full history and consistent adaptive cadence across CLI, macOS, and GNOME #389.
Environment
| codeburn CLI | 0.9.11 |
| CodeBurn Menubar | 0.9.11 |
| Node | v25.8.0 |
| macOS | 26.5 (Darwin 25.5.0) |
| Provider involved | Pi (~/.pi/agent/sessions) |
Steps to reproduce
- Have at least one Pi session
.jsonlolder than 30 days containing amessageentry wheremessage.role = "user"andmessage.contentis a string (not an array of content blocks). Minimal example line:{"type":"message","id":"x","parentId":null,"timestamp":"2026-03-01T13:00:00.000Z","message":{"role":"user","content":"test message from file watcher","timestamp":1772366400000}} - Run the command the menubar uses:
→
codeburn status --format menubar-json --period 30dayshistory.dailycontains only today. (--period allandcodeburn export --format jsonover a >30-day range crash outright.)
Actual behavior
codeburn export --format json --from <366d ago> --to yesterday crashes:
.../dist/main.js:4925
const texts = (msg.content ?? []).filter((c) => c.type === "text").map((c) => c.text ?? "").filter(Boolean);
^
TypeError: (msg.content ?? []).filter is not a function
at Object.parse (.../dist/main.js:4925:45)
at parseProviderSources (.../dist/main.js:10215:26)
at async parseAllSessions (.../dist/main.js:10420:22)
Via the menubar path the same throw is caught by hydrateCache's catch { return emptyCache2() }, so it fails silently and ~/.cache/codeburn/daily-cache.json is never created.
Root cause
In the Pi provider parser (src/providers/pi.ts), the user-message branch assumes content is always an array:
if (msg.role === "user") {
const texts = (msg.content ?? []).filter((c) => c.type === "text")...
}?? [] only guards null/undefined; a string content reaches .filter and throws. (Pi/other agents legitimately write content as a plain string for some user turns, e.g. programmatically injected messages.)
This is then masked by the silent catch in hydrateCache():
async function hydrateCache() {
try {
return await ensureCacheHydrated(...);
} catch {
return emptyCache2(); // <- backfill failure becomes "no history", no log
}
}Confirmation
Removing the single offending Pi session file and re-running let the backfill complete normally:
- Before:
history.daily= 1 entry (today). - After:
daily-cache.jsonbuilt with 115 days (2025-09-11 → yesterday); payloadhistory.daily= 116 entries;--period allno longer crashes.
So the bug is purely the unguarded content parse plus the silenced backfill error — not a cache/data-volume problem (a full session-cache rebuild does not fix it).
Suggested fix
- Pi parser (and any other parser using the same idiom): normalize
contentbefore filtering, e.g.const blocks = Array.isArray(msg.content) ? msg.content : typeof msg.content === "string" ? [{ type: "text", text: msg.content }] : []; const texts = blocks.filter((c) => c.type === "text").map((c) => c.text ?? "").filter(Boolean);
- Don't swallow backfill errors silently in
hydrateCache()— at minimum log under--verbose/CODEBURN_VERBOSE, and ideally skip only the offending session/file rather than discarding the entire daily cache. A single malformed record in any provider currently disables the whole trend/history feature.
Notes
- Likely the same root cause as [Bug] Previous day usage always reported as 0 #425 ("[Bug] Previous day usage always reported as 0"); related to Menubar Lifetime period should use full history and consistent adaptive cadence across CLI, macOS, and GNOME #389.
- Workaround for affected users: find the bad file with a quick scan of
~/.pi/agent/sessions/**/*.jsonlfor arole:"user"entry whosecontentis a string, remove/fix that line, then refresh.
Activity
fix(parser): tolerate string message content; isolate per-file parse …
fix(parser): cache parse failures so broken files aren't re-read ever…
fix(parser): isolate Claude per-file parse failures
fix(cache): close three data-integrity holes in the month-shard layout