{"record":{"id":"d8588c94f3f390b3","repo":"Hmbown/CodeWhale","slug":"terminal-restore-request-was-rejected","errorCode":null,"errorMessage":"terminal restore request was rejected","messagePattern":"terminal restore request was rejected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/window_control.rs","lineNumber":405,"sourceCode":"        // An unconfirmed request keeps its original target and restore data.\n        // The next request restores that window, even if focus has changed.\n        let restoring = state.host.is_some();\n        let host = state.host.unwrap_or(captured_host);\n        if let Err(error) = host.hwnd() {\n            // Retire geometry only when the original owner is gone. A failed\n            // observation must preserve it for the next restore attempt.\n            *state = State::new();\n            PINNED.store(false, Ordering::Release);\n            return Err(error);\n        }\n        let before = observe(host)?;\n        if !restoring {\n            state.host = Some(host);\n            state.was_maximized = before.maximized;\n            state.saved_rect = Some(before.rect);\n            if before.maximized {\n                if !unsafe { ShowWindowAsync(host.hwnd()?, SW_RESTORE) }.as_bool() {\n                    bail!(\"terminal restore request was rejected\");\n                }\n                if !wait_for(host, Duration::from_millis(800), |observed| {\n                    !observed.maximized\n                })? {\n                    bail!(\"terminal restore was not observed before the deadline\");\n                }\n                state.saved_rect = Some(observe(host)?.rect);\n            }\n        }\n\n        let saved = state\n            .saved_rect\n            .context(\"terminal restore geometry is unavailable\")?;\n        let target = Observation {\n            topmost: !restoring,\n            maximized: restoring && state.was_maximized,\n            rect: if restoring {\n                saved","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/window_control.rs#L387-L423","documentation":"During toggle_pin's un-maximize (restore) step, ShowWindowAsync(hwnd, SW_RESTORE) returned false, meaning Windows rejected the async restore request for the host window. The code bails instead of continuing to move/resize a window that could not be restored.","triggerScenarios":"toggle_pin restoring a maximized window when the Win32 ShowWindowAsync(SW_RESTORE) call returns FALSE — e.g. the window is in a state that cannot be restored or is owned/protected by another process.","commonSituations":"The terminal is maximized in a way the window manager refuses to undo (fullscreen/secure desktop, elevated vs non-elevated process mismatch); another application holds the window; a race with the user's own window actions.","solutions":["Retry toggle_pin; transient ShowWindowAsync failures often succeed on a second attempt.","Un-maximize the terminal manually before toggling pin, avoiding the restore path.","Check for elevated (admin) vs non-elevated process mismatch — UIPI can block window manipulation of an elevated window.","Verify the host window still exists (hwnd() succeeded here, so re-capture if owner changed)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match toggle_pin() {\n    Err(e) if e.to_string().contains(\"restore request was rejected\") => retry_with_backoff(2),\n    other => other?,\n}","preventionTips":["Retry ShowWindowAsync once before failing; rejections are often transient.","Check process integrity levels (elevated vs non-elevated) before manipulating the window.","Avoid toggling while the user is actively resizing/maximizing the terminal.","Offer a manual 'un-maximize first' hint when restore is rejected."],"tags":["windows","win32","showwindow","terminal-window"],"backgroundTag":"unsupported-operation","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"}