fix(desktop): resolve Tauri state panic on startup
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
SessionStreamGuard and StreamCancelFlags were type aliases to the same Arc<DashMap<String, Arc<AtomicBool>>> type. Tauri distinguishes managed state by Rust type, so registering both caused a runtime panic: "state for type ... is already being managed". Changed to newtype structs with Deref impl to the inner Arc<DashMap>, keeping all call sites compatible without changes.
This commit is contained in:
@@ -34,12 +34,28 @@ pub type SchedulerState = Arc<Mutex<Option<zclaw_kernel::scheduler::SchedulerSer
|
||||
/// for the same session_id.
|
||||
/// Uses `AtomicBool` so the `DashMap` — `true` means active stream, `false` means idle.
|
||||
/// The `spawn`ed task resets the flag on completion/error.
|
||||
pub type SessionStreamGuard = Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>;
|
||||
///
|
||||
/// Newtype wrapper is required because Tauri state management uses the Rust type
|
||||
/// system to distinguish states — two `type` aliases to the same underlying type
|
||||
/// would cause a runtime panic ("state already being managed").
|
||||
#[derive(Clone, Default)]
|
||||
pub struct SessionStreamGuard(pub Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>);
|
||||
|
||||
/// Per-session stream cancellation flags.
|
||||
/// When a user cancels a stream, the flag for that session_id is set to `true`.
|
||||
/// The spawned `agent_chat_stream` task checks this flag each iteration.
|
||||
pub type StreamCancelFlags = Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>;
|
||||
#[derive(Clone, Default)]
|
||||
pub struct StreamCancelFlags(pub Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>);
|
||||
|
||||
impl std::ops::Deref for SessionStreamGuard {
|
||||
type Target = Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>;
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
||||
impl std::ops::Deref for StreamCancelFlags {
|
||||
type Target = Arc<dashmap::DashMap<String, Arc<std::sync::atomic::AtomicBool>>>;
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared validation helpers
|
||||
|
||||
Reference in New Issue
Block a user