{"record":{"id":"1994f2e1c659db28","repo":"Hmbown/CodeWhale","slug":"editor-handoff-cancelled-by-pending-terminal-input","errorCode":null,"errorMessage":"editor handoff cancelled by pending terminal input","messagePattern":"editor handoff cancelled by pending terminal input","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tui/ui/event_loop.rs","lineNumber":6712,"sourceCode":"                    let seed = app.input.clone();\n                    let editor_result = match terminal_input.pause_for_child_terminal().await {\n                        Err(err) => Err(err),\n                        Ok(()) => {\n                            let result = prepare_terminal_input_handoff(\n                                &terminal_input,\n                                &mut pending_terminal_events,\n                            )\n                            .and_then(|ready| {\n                                if ready {\n                                    crate::tui::external_editor::spawn_editor_for_input(\n                                        terminal,\n                                        app.use_alt_screen(),\n                                        app.use_mouse_capture,\n                                        app.use_bracketed_paste,\n                                        &seed,\n                                    )\n                                } else {\n                                    Err(io::Error::new(\n                                        io::ErrorKind::Interrupted,\n                                        \"editor handoff cancelled by pending terminal input\",\n                                    ))\n                                }\n                            });\n                            terminal_input.resume_after_child_terminal();\n                            force_terminal_repaint = true;\n                            result\n                        }\n                    };\n                    match editor_result {\n                        Ok(crate::tui::external_editor::EditorOutcome::Edited(new)) => {\n                            app.apply_external_edit(new);\n                            let editor = std::env::var(\"VISUAL\")\n                                .ok()\n                                .filter(|s| !s.trim().is_empty())\n                                .or_else(|| {\n                                    std::env::var(\"EDITOR\")","sourceCodeStart":6694,"sourceCodeEnd":6730,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/ui/event_loop.rs#L6694-L6730","documentation":"During editor handoff, the TUI event loop spawns a child terminal for the editor. Before resuming, it checks there is no pending terminal input; if input is pending, it refuses the handoff with ErrorKind::Interrupted so keystrokes typed around the handoff are not lost or misrouted to the child.","triggerScenarios":"run_event_loop (called by run_tui) invokes the editor handoff while keys are still queued in the terminal input pump and resume_after_child_terminal is set up without a clean quiescent state.","commonSituations":"User launches the editor (e.g. multi-line prompt editor) while still typing or with buffered paste/key events arriving at the same moment.","solutions":["Retry the editor handoff after the pending input drains.","Dismiss or consume the pending keystrokes before opening the editor.","Treat Interrupted as 'cancelled', keep the prompt state, and let the user reopen the editor."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure input quiescence before handoff\nif pending_terminal_input().is_empty() { open_editor()?; }","typeGuard":null,"tryCatchPattern":"match open_editor_handoff() {\n    Err(e) if e.kind() == io::ErrorKind::Interrupted => schedule_retry_after_drain(),\n    other => other,\n}","preventionTips":["Drain or pause key input before launching the editor.","Debounce rapid keystrokes near handoff boundaries.","Treat Interrupted as user-visible 'editor cancelled', not a crash."],"tags":["tui","terminal","editor"],"backgroundTag":"invalid-state-transition","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"}