-
Notifications
You must be signed in to change notification settings - Fork 2
fix(tui): graph metrics always show zero in TUI dashboard #1938
Description
Problem
Graph metrics panel in TUI always shows zeros (entities: 0, edges: 0, communities: 0) despite the database containing real data (138 entities, 388 edges confirmed via sqlite3).
Two separate root causes identified.
Root Cause 1: Initial value lost at startup
sync_graph_counts() is called in src/runner.rs:1237 before the TUI receiver is created. Tokio watch::Receiver marks the initial value as has_changed = false, so poll_metrics() skips it on the first poll and graph counts never appear.
// app.rs — poll_metrics() only reads when has_changed = true
if let Some(ref mut rx) = self.metrics_rx
&& rx.has_changed().unwrap_or(false) // false at startup → skippedFix: Read the initial value eagerly in with_metrics_rx():
pub fn with_metrics_rx(mut self, rx: watch::Receiver<MetricsSnapshot>) -> Self {
self.metrics = rx.borrow().clone(); // read initial value immediately
self.metrics_rx = Some(rx);
self
}Root Cause 2: sync_graph_counts() called before extraction completes
sync_graph_counts() is called at the end of process_user_message_inner() immediately after analyze_and_learn(). However, graph extraction is fire-and-forget (tokio::spawn) — the spawn has not completed by the time sync_graph_counts() reads from the store, so it reads stale counts.
self.analyze_and_learn().await; // spawns extraction task (fire-and-forget)
self.sync_graph_counts().await; // reads BEFORE spawn finishes → stale dataFix: Call sync_graph_counts() as a callback inside the extraction spawn after it completes, or add a post-extraction notification mechanism so counts are refreshed after the spawn finishes.
Files
crates/zeph-tui/src/app.rs—with_metrics_rx(),poll_metrics()crates/zeph-core/src/agent/utils.rs—sync_graph_counts()crates/zeph-core/src/agent/mod.rs:3182— call sitesrc/runner.rs:1237— startup call site
Verification
sqlite3 ~/Library/Application\ Support/zeph/data/zeph.db "SELECT 'entities:', COUNT(*) FROM graph_entities;
SELECT 'edges:', COUNT(*) FROM graph_edges;"
# entities: 138
# edges: 388
# TUI shows: 0 / 0