{"record":{"id":"938b53f2e7a229c5","repo":"Hmbown/CodeWhale","slug":"terminal-host-window-no-longer-exists","errorCode":null,"errorMessage":"terminal host window no longer exists","messagePattern":"terminal host window no longer exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/window_control.rs","lineNumber":107,"sourceCode":"            BUSY.store(false, Ordering::Release);\n        }\n    }\n\n    #[derive(Clone, Copy)]\n    struct HostWindow {\n        handle: isize,\n        owner_pid: u32,\n    }\n\n    impl HostWindow {\n        fn capture() -> Result<Self> {\n            let hwnd = console_hwnd().context(\"no terminal host window found\")?;\n            let mut owner_pid = 0;\n            unsafe {\n                GetWindowThreadProcessId(hwnd, Some(&mut owner_pid));\n            }\n            if owner_pid == 0 {\n                bail!(\"terminal host window no longer exists\");\n            }\n            Ok(Self {\n                handle: hwnd.0 as isize,\n                owner_pid,\n            })\n        }\n\n        fn hwnd(self) -> Result<HWND> {\n            let hwnd = HWND(self.handle as *mut _);\n            let mut owner_pid = 0;\n            unsafe {\n                GetWindowThreadProcessId(hwnd, Some(&mut owner_pid));\n            }\n            if owner_pid != self.owner_pid {\n                bail!(\"terminal host window owner changed\");\n            }\n            Ok(hwnd)\n        }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/window_control.rs#L89-L125","documentation":"WindowControl::capture looks up the console host window (console_hwnd) and then reads its owning process id via GetWindowThreadProcessId. If the owner pid comes back 0, the window handle is stale or the window has been destroyed, so capture bails with this error rather than caching a dead handle.","triggerScenarios":"Calling capture on Windows when the console window's owning process has exited, so GetWindowThreadProcessId returns 0 for the hwnd obtained from console_hwnd().","commonSituations":"The terminal was closed or detached between obtaining the console window and capture; running under an environment with no real console host; conhost/Windows Terminal restart replaced the host process mid-session.","solutions":["Re-capture the host window (call capture again) so a fresh console_hwnd is resolved.","Verify the terminal hosting the TUI is still open and attached to a console.","On non-Windows or headless environments, skip pinning/window-control entirely (this code is Windows-only)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Windows-only: confirm a live console host before capture\nlet hwnd = console_hwnd();\nlet mut pid = 0u32;\nif hwnd.is_ok() {\n    unsafe { GetWindowThreadProcessId(hwnd.unwrap(), Some(&mut pid)); }\n}\nlet capturable = pid != 0;","typeGuard":null,"tryCatchPattern":"match WindowControl::capture() {\n    Err(e) if e.to_string().contains(\"no longer exists\") => skip_pinning_and_log(),\n    other => other?,\n}","preventionTips":["Only enable pinning when a real console host window exists.","Re-capture instead of reusing cached handles.","Disable window control on headless/CI environments.","Check the host process is alive before window operations."],"tags":["windows","win32","terminal-window","pinning"],"backgroundTag":"resource-not-found","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"}