Skip to content

Menubar trend chart / daily history is empty #441

Closed

Description

@jacobk

[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-json returns only today in history.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 user message.content is a string instead of an array.
  • hydrateCache() wraps the backfill in try { … } catch { return emptyCache2() }, so the crash is silently swallowed — no error, no log even with --verbose. daily-cache.json is 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

  1. Have at least one Pi session .jsonl older than 30 days containing a message entry where message.role = "user" and message.content is 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}}
  2. Run the command the menubar uses:
    codeburn status --format menubar-json --period 30days
    
    → history.daily contains only today. (--period all and codeburn export --format json over 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.json built with 115 days (2025-09-11 → yesterday); payload history.daily = 116 entries; --period all no 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

  1. Pi parser (and any other parser using the same idiom): normalize content before 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);
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions