[Sovereignty P0] Metrics Emitter + SQLite Metrics Store #954

Closed
opened 2026-03-22 18:23:02 +00:00 by perplexity · 1 comment
Collaborator

Parent

Part of #953 (The Sovereignty Loop) — P0 priority

Governing Principle

"Cannot improve what you cannot measure."

Goal

Build the metrics infrastructure that tracks sovereignty percentage across all layers. Without this, the sovereignty loop has no feedback signal.

Implementation

  1. Create src/timmy/sovereignty/metrics.py:
    • metrics.record(event_type, metadata) — log any sovereignty event
    • Event types: perception_cache_hit, perception_vlm_call, decision_rule_hit, decision_llm_call, narration_template, narration_llm, skill_crystallized, api_call, api_cost
  2. SQLite storage at data/sovereignty_metrics.db:
    • events table: timestamp, event_type, session_id, metadata_json
    • sessions table: session_id, game, start_time, end_time
  3. Real-time computation functions:
    • get_sovereignty_pct(layer, time_window) → float
    • get_cost_per_hour(time_window) → float
    • get_skills_crystallized(session_id) → int
  4. WebSocket emitter for dashboard widget (feeds into #953's sovereignty dashboard spec)

Effort Estimate

1 day

Cross-references

  • #953 (Sovereignty Loop governing doc)
  • #855 (SQLite Command Log — can share infrastructure)
  • #879 (Dashboard — will consume these metrics)
  • #862 (Timmy Dashboard — monitoring UI)
## Parent Part of #953 (The Sovereignty Loop) — P0 priority ## Governing Principle > "Cannot improve what you cannot measure." ## Goal Build the metrics infrastructure that tracks sovereignty percentage across all layers. Without this, the sovereignty loop has no feedback signal. ## Implementation 1. Create `src/timmy/sovereignty/metrics.py`: - `metrics.record(event_type, metadata)` — log any sovereignty event - Event types: `perception_cache_hit`, `perception_vlm_call`, `decision_rule_hit`, `decision_llm_call`, `narration_template`, `narration_llm`, `skill_crystallized`, `api_call`, `api_cost` 2. SQLite storage at `data/sovereignty_metrics.db`: - `events` table: timestamp, event_type, session_id, metadata_json - `sessions` table: session_id, game, start_time, end_time 3. Real-time computation functions: - `get_sovereignty_pct(layer, time_window)` → float - `get_cost_per_hour(time_window)` → float - `get_skills_crystallized(session_id)` → int 4. WebSocket emitter for dashboard widget (feeds into #953's sovereignty dashboard spec) ## Effort Estimate 1 day ## Cross-references - #953 (Sovereignty Loop governing doc) - #855 (SQLite Command Log — can share infrastructure) - #879 (Dashboard — will consume these metrics) - #862 (Timmy Dashboard — monitoring UI)
claude was assigned by Rockachopa 2026-03-22 23:31:25 +00:00
claude added the harnessheartbeatp0-critical labels 2026-03-23 13:52:52 +00:00
Collaborator

PR created: #1164

Summary of changes:

  • src/timmy/sovereignty/metrics.py — new module with SovereigntyMetricsStore backed by SQLite, events + sessions tables, all 9 event types, get_sovereignty_pct(), get_cost_per_hour(), get_skills_crystallized(), module-level convenience functions, and emit_sovereignty_event() async helper
  • src/dashboard/routes/sovereignty_ws.py/ws/sovereignty WebSocket endpoint streaming metric snapshots every 5 s
  • src/dashboard/app.py — sovereignty WS router registered
  • tests/unit/test_sovereignty_metrics.py — 34 new unit tests, all passing (tox -e unit: 127 passed)
PR created: #1164 **Summary of changes:** - `src/timmy/sovereignty/metrics.py` — new module with `SovereigntyMetricsStore` backed by SQLite, `events` + `sessions` tables, all 9 event types, `get_sovereignty_pct()`, `get_cost_per_hour()`, `get_skills_crystallized()`, module-level convenience functions, and `emit_sovereignty_event()` async helper - `src/dashboard/routes/sovereignty_ws.py` — `/ws/sovereignty` WebSocket endpoint streaming metric snapshots every 5 s - `src/dashboard/app.py` — sovereignty WS router registered - `tests/unit/test_sovereignty_metrics.py` — 34 new unit tests, all passing (`tox -e unit`: 127 passed)
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#954