fix: persist stats across session changes, only reset on disconnect

- Reuse existing WslBridge when reconnecting (preserves stats)
- Move reset_session() from start() to stop() so stats only clear on explicit disconnect
- Stats now persist through permission prompts, interrupts, and question prompts

Closes #59
This commit is contained in:
2026-01-23 15:19:40 -08:00
committed by Naomi Carrigan
parent 5455b5c148
commit 4971f2c436
2 changed files with 12 additions and 8 deletions
+6 -6
View File
@@ -29,7 +29,7 @@ impl BridgeManager {
conversation_id: &str, conversation_id: &str,
options: ClaudeStartOptions, options: ClaudeStartOptions,
) -> Result<(), String> { ) -> Result<(), String> {
// Check if a bridge already exists for this conversation // Check if a bridge already exists and is running for this conversation
if self.bridges.get(conversation_id).map(|b| b.is_running()).unwrap_or(false) { if self.bridges.get(conversation_id).map(|b| b.is_running()).unwrap_or(false) {
return Err("Claude is already running for this conversation".to_string()); return Err("Claude is already running for this conversation".to_string());
} }
@@ -38,15 +38,15 @@ impl BridgeManager {
.ok_or_else(|| "App handle not set".to_string())? .ok_or_else(|| "App handle not set".to_string())?
.clone(); .clone();
// Create a new bridge for this conversation // Reuse existing bridge if it exists (preserves stats across reconnects)
let mut bridge = WslBridge::new_with_conversation_id(conversation_id.to_string()); // Only create a new bridge if one doesn't exist for this conversation
let bridge = self.bridges
.entry(conversation_id.to_string())
.or_insert_with(|| WslBridge::new_with_conversation_id(conversation_id.to_string()));
// Start the Claude process // Start the Claude process
bridge.start(app, options)?; bridge.start(app, options)?;
// Store the bridge
self.bridges.insert(conversation_id.to_string(), bridge);
Ok(()) Ok(())
} }
+6 -2
View File
@@ -292,8 +292,8 @@ impl WslBridge {
self.stdin = stdin; self.stdin = stdin;
self.process = Some(child); self.process = Some(child);
// Reset session stats when starting new session // Note: We no longer reset stats here - stats persist across reconnects
self.stats.write().reset_session(); // Stats are only reset when explicitly disconnecting via stop()
// Load saved achievements // Load saved achievements
let app_handle = app.clone(); let app_handle = app.clone();
@@ -411,6 +411,10 @@ impl WslBridge {
self.stdin = None; self.stdin = None;
self.session_id = None; self.session_id = None;
self.mcp_config_file = None; // Temp file is automatically deleted when dropped self.mcp_config_file = None; // Temp file is automatically deleted when dropped
// Reset session stats on explicit disconnect
self.stats.write().reset_session();
emit_connection_status(app, ConnectionStatus::Disconnected, self.conversation_id.clone()); emit_connection_status(app, ConnectionStatus::Disconnected, self.conversation_id.clone());
} }