Skip to main content

Module metadata_cache

Module metadata_cache 

Source
Expand description

SQLite metadata cache for session files

Caches session metadata with mtime-based invalidation for 90% startup speedup. Also caches activity analysis (tool calls, alerts) per session on demand.

Schema:

  • session_metadata: parsed metadata + mtime + cache_version
  • activity_cache: serialized ActivitySummary + mtime per session file
  • activity_alerts: searchable alert records (severity/category) across all sessions
  • Indexes: project, mtime, session_id, severity for fast queries

Invalidation:

  • File watcher detects modification โ†’ delete session + activity cache entries
  • Startup: compare mtime โ†’ rescan if stale
  • Startup: compare cache_version โ†’ auto-clear ALL tables if mismatch

Cache Version History:

  • v1: Initial version (pre-TokenUsage fix)
  • v2: Fixed TokenUsage::total() to include cache_read_tokens + cache_write_tokens
  • v3: Added token breakdown fields (input_tokens, output_tokens, cache_creation_tokens, cache_read_tokens) to SessionMetadata + real pricing calculation
  • v4: Added branch field to SessionMetadata
  • v5: Added activity_cache + activity_alerts tables for Phase 2 activity module
  • v6: Added aggregate_stats table with triggers + FTS5 session_fts table
  • v7: Added tool_token_usage field to SessionMetadata (Phase K analytics)

Structsยง

ActivityCacheStats
Activity cache statistics
AggregateStats
Aggregate statistics from O(1) table
CacheStats
Session metadata cache statistics
MetadataCache
SQLite-based metadata cache (thread-safe)
SearchResult
A single FTS5 search result
StoredAlert
A single alert record from the activity_alerts table