Skip to content

fix(stats): source heatmap from session_cache instead of stats-cache.json - #7

Merged
JeanBaptisteRenard merged 1 commit into
mainfrom
fix/heatmap-from-db
May 22, 2026
Merged

JeanBaptisteRenard merged 1 commit into
mainfrom
fix/heatmap-from-db

Conversation

@JeanBaptisteRenard

Copy link
Copy Markdown
Collaborator

Problem

The stats heatmap had a large hole between March and April 2026 and was mostly empty before February. Root cause:

  • claude /stats only counts parent JSONL files, silently ignoring all subagent sessions
  • Claude rotates/deletes old parent JSONLs — only ~137 survive on disk (all April–May 2026)
  • The user's workflow is heavily subagent-based, so most activity was invisible

Solution

Source the heatmap directly from session_cache (Switchboard's own SQLite DB), which already indexes every parent and subagent session and persists them independently of Claude's file rotation.

DB counts by month:

Month Sessions Messages
Feb 2026 494 24,328
Mar 2026 389 33,951
Apr 2026 134 21,678
May 2026 532 149,268

All months are now fully visible in the heatmap.

Changes

  • db.js: add getDailyActivity()GROUP BY substr(modified,1,10) over session_cache
  • main.js: add get-stats-from-db IPC handler; rewrite refresh-stats to drop the slow /stats PTY spawn; remove dead runClaude helper (~90 lines)
  • preload.js: expose getStatsFromDb to renderer
  • public/stats-view.js: consume DB stats; update data-source notice text
  • test/db-daily-activity.test.js: 6 tests covering aggregation logic and stats-object shape

Test plan

  • Open Stats tab — heatmap shows activity in Feb/Mar/Apr 2026
  • Hover a March cell — tooltip shows sessions count > 0
  • Rate limits panel still works (fetched via fetchAndTransformUsage, unchanged)
  • npm test passes (38/38)

…json

Claude's /stats command only counts parent JSONL files and rotates them
off disk, making the heatmap blind to subagent sessions and older months.
Switch to an in-DB aggregate (getDailyActivity) that covers everything
Switchboard has indexed — parents and subagents alike.

- db.js: add getDailyActivity() — GROUP BY date over session_cache
- main.js: add get-stats-from-db IPC handler; rewrite refresh-stats to
  drop the /stats PTY spawn (now redundant); remove dead runClaude helper
- preload.js: expose getStatsFromDb to renderer
- public/stats-view.js: consume DB stats; update data-source notice text
- test/db-daily-activity.test.js: 6 tests covering aggregation logic and
  stats-object shape (better-sqlite3 ABI incompatibility with plain node
  means the SQL path is covered via a pure-JS mirror of the query)
@JeanBaptisteRenard
JeanBaptisteRenard merged commit 76aaaf3 into main May 22, 2026
7 checks passed
@JeanBaptisteRenard
JeanBaptisteRenard deleted the fix/heatmap-from-db branch May 22, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant