diff --git a/.beans/claudbg-gtu4--tui-message-count-always-0-because-tui-never-syncs.md b/.beans/claudbg-gtu4--tui-message-count-always-0-because-tui-never-syncs.md new file mode 100644 index 0000000..67be3d0 --- /dev/null +++ b/.beans/claudbg-gtu4--tui-message-count-always-0-because-tui-never-syncs.md @@ -0,0 +1,17 @@ +--- +# claudbg-gtu4 +title: 'TUI: message count always 0 because TUI never syncs sessions to DB' +status: completed +type: bug +priority: normal +created_at: 2026-04-01T17:37:06Z +updated_at: 2026-04-01T17:38:26Z +--- + +The TUI startup queries message_count from the sessions DB table, but never calls ensure_synced first. If the user opens the TUI without having run sessions list or index previously, the DB is empty and all message counts show 0. + +Fix: call ensure_synced for each session_ref inside the block_in_place block before the SELECT query in run_tui(). + +## Summary of Changes + +In `src/tui/run.rs`: changed `session_refs.into_iter()` to `session_refs.iter()` so the vec is not consumed before DB sync. Added a loop inside the `block_in_place` block to call `ensure_synced` for each session before querying `message_count` from the DB. This ensures the DB is populated even if the user opens the TUI without having previously run `sessions list` or `index`. diff --git a/src/tui/run.rs b/src/tui/run.rs index b73ac02..47bdece 100644 --- a/src/tui/run.rs +++ b/src/tui/run.rs @@ -217,7 +217,7 @@ pub fn run_tui() -> Result<()> { // Sort most-recent-first before converting to display items. session_refs.sort_by(|a, b| b.modified_at.cmp(&a.modified_at)); state.sessions = session_refs - .into_iter() + .iter() .map(|sr| { let short_id = sr.session_id.chars().take(8).collect(); let full_id = sr.session_id.clone(); @@ -252,6 +252,10 @@ pub fn run_tui() -> Result<()> { Ok(d) => d, Err(_) => return HashMap::new(), }; + // Sync each session so message counts are up to date. + for sr in &session_refs { + let _ = crate::db::sync::ensure_synced(&db, sr).await; + } let conn = match db.connect() { Ok(c) => c, Err(_) => return HashMap::new(),