Summary
A bare .unwrap() in the AI service will crash the entire Tauri backend when a race condition occurs between session creation and cancellation.
Location
src-tauri/crates/mas-ai/src/service.rs:361
let sessions = self.sessions.read().await;
sessions.get(conversation_id).unwrap().session.clone() // PANIC
Root Cause
The code checks need_new_session at line 190 with a read lock, then releases it. The else branch at line 359 reacquires a read lock and calls .unwrap() on sessions.get(). Between these two operations, a cancel or session removal (from a different concurrent request) can delete the session, causing the .unwrap() to panic and crash the entire backend process.
Impact
- Any concurrent cancel + send operation can crash the app
- The user sees the app vanish without any error message
- All unsaved work is lost
Fix
Replace .unwrap() with proper error handling:
let session = sessions
.get(conversation_id)
.ok_or_else(|| AiError::SessionNotFound)?
.session
.clone();
Summary
A bare
.unwrap()in the AI service will crash the entire Tauri backend when a race condition occurs between session creation and cancellation.Location
src-tauri/crates/mas-ai/src/service.rs:361Root Cause
The code checks
need_new_sessionat line 190 with a read lock, then releases it. Theelsebranch at line 359 reacquires a read lock and calls.unwrap()onsessions.get(). Between these two operations, a cancel or session removal (from a different concurrent request) can delete the session, causing the.unwrap()to panic and crash the entire backend process.Impact
Fix
Replace
.unwrap()with proper error handling: