From 878e79733f1b68c0af99a72e7cb63314242b7397 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Wed, 1 Apr 2026 10:39:25 -0700 Subject: [PATCH] fix(claudbg-gtu4): sync sessions to DB before querying message counts in TUI TUI startup was querying message_count from the DB without first calling ensure_synced, so counts were always 0 if the user hadn't run sessions list or index previously. Now syncs each session before the SELECT query. Co-Authored-By: Claude Sonnet 4.6 --- ...ge-count-always-0-because-tui-never-syncs.md | 17 +++++++++++++++++ src/tui/run.rs | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .beans/claudbg-gtu4--tui-message-count-always-0-because-tui-never-syncs.md 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(),