{"record":{"id":"d9047f5362d18aa1","repo":"Hmbown/CodeWhale","slug":"window-worker-panicked","errorCode":null,"errorMessage":"window worker panicked","messagePattern":"window worker panicked","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/window_control.rs","lineNumber":199,"sourceCode":"        completion_tx: Option<tokio::sync::mpsc::Sender<crate::tui::app::DispatchApplyFn>>,\n    ) -> Result<()> {\n        // Reserve delivery before changing the window. A headless test App has\n        // no mailbox and cannot accidentally manipulate its real terminal.\n        let permit = completion_tx\n            .context(\"window completion mailbox is unavailable\")?\n            .try_reserve_owned()\n            .context(\"window completion mailbox is full or closed\")?;\n        BUSY.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)\n            .map_err(|_| anyhow::anyhow!(\"a window change is already in progress\"))?;\n        let busy = BusyGuard;\n        // Foreground selection belongs to the user's action, before dispatch;\n        // the worker must not pick a different window after focus changes.\n        let host = HostWindow::capture()?;\n        std::thread::Builder::new()\n            .name(\"window-pin\".into())\n            .spawn(move || {\n                let result = std::panic::catch_unwind(|| toggle_pin(host))\n                    .unwrap_or_else(|_| Err(anyhow::anyhow!(\"window worker panicked\")));\n                let apply: crate::tui::app::DispatchApplyFn = Box::new(move |app, _, _| {\n                    super::show_result(app, result);\n                    Ok(())\n                });\n                permit.send(apply);\n                drop(busy);\n            })?;\n        Ok(())\n    }\n\n    /// The host window the user sees, if one can be resolved.\n    ///\n    /// Classic console hosts (conhost, legacy cmd windows) hand back a real\n    /// window from `GetConsoleWindow`. ConPTY hosts (Windows Terminal, VS\n    /// Code integrated terminal) have no classic console window, so first\n    /// check the foreground window (the user just right-clicked inside the\n    /// host, so it is almost certainly the host window) and then fall back\n    /// to the parent process chain.","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/window_control.rs#L181-L217","documentation":"The window-pin worker runs toggle_pin inside std::panic::catch_unwind; if the closure panics, the panic is converted into this Err so the result can still be dispatched back to the app instead of killing the worker silently. It reports that the window toggle failed due to an internal panic.","triggerScenarios":"toggle_pin panicking while manipulating host windows (e.g. unwrapping on a window API result, index out of bounds on window lists, or OS API returning an unexpected value).","commonSituations":"OS window-manager state changed underneath the TUI (window closed concurrently), platform quirks in the host window API, or a bug in toggle_pin reached by an unusual window configuration (e.g. only one window, minimized windows).","solutions":["Check the app log for the panic backtrace to find the actual panicking site in toggle_pin.","Reproduce with the current window layout (single window, minimized/fullscreen windows) and fix the unwrapping/indexing in toggle_pin.","Retry the toggle; it is usually safe to re-issue since the worker state is reset.","File a bug with the panic message if it reproduces on a supported platform."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match start_toggle() {\n    Err(e) if e.to_string().contains(\"window worker panicked\") => {\n        log_panic_backtrace(e);\n        show_user_friendly_window_error();\n    }\n    Err(e) => report(e),\n    Ok(()) => {}\n}","preventionTips":["Avoid unwrap/expect inside toggle_pin; propagate Result instead.","Handle degenerate window layouts (0 or 1 windows, minimized windows) explicitly.","Keep the worker's catch_unwind and log the panic payload for diagnosis.","Re-test toggling after OS window-manager changes (monitor hotplug, session lock)."],"tags":["panic","window-control","worker-thread","tui"],"backgroundTag":"internal-invariant-violation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}