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 <noreply@anthropic.com>
main
Elijah Voigt 2 months ago
parent ddaa772da4
commit 878e79733f

@ -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`.

@ -217,7 +217,7 @@ pub fn run_tui() -> Result<()> {
// Sort most-recent-first before converting to display items. // Sort most-recent-first before converting to display items.
session_refs.sort_by(|a, b| b.modified_at.cmp(&a.modified_at)); session_refs.sort_by(|a, b| b.modified_at.cmp(&a.modified_at));
state.sessions = session_refs state.sessions = session_refs
.into_iter() .iter()
.map(|sr| { .map(|sr| {
let short_id = sr.session_id.chars().take(8).collect(); let short_id = sr.session_id.chars().take(8).collect();
let full_id = sr.session_id.clone(); let full_id = sr.session_id.clone();
@ -252,6 +252,10 @@ pub fn run_tui() -> Result<()> {
Ok(d) => d, Ok(d) => d,
Err(_) => return HashMap::new(), 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() { let conn = match db.connect() {
Ok(c) => c, Ok(c) => c,
Err(_) => return HashMap::new(), Err(_) => return HashMap::new(),

Loading…
Cancel
Save