{"record":{"id":"b17a1609fa1f4336","repo":"Hmbown/CodeWhale","slug":"shell-tracking-hit-an-internal-error-restart-cod","errorCode":null,"errorMessage":"Shell tracking hit an internal error — restart Codewhale to recover.","messagePattern":"Shell tracking hit an internal error — restart Codewhale to recover\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/ui.rs","lineNumber":1252,"sourceCode":"\n    match request_active_foreground_shell_background(app) {\n        Ok(()) => {\n            app.status_message = Some(\"Moving current shell command to /jobs...\".to_string());\n        }\n        Err(err) => {\n            app.status_message = Some(err.to_string());\n        }\n    }\n}\n\nfn request_active_foreground_shell_background(app: &App) -> Result<()> {\n    let shell_manager = app\n        .runtime_services\n        .shell_manager\n        .clone()\n        .context(\"No shell session is active.\")?;\n    let mut manager = shell_manager.lock().map_err(|_| {\n        anyhow::anyhow!(\"Shell tracking hit an internal error — restart Codewhale to recover.\")\n    })?;\n    manager.request_foreground_background();\n    Ok(())\n}\n\npub(crate) fn prefill_jobs_cancel_all_if_tasks_sidebar(app: &mut App) -> bool {\n    if !app.view_stack.is_empty()\n        || app.work_surface.panel != crate::tui::work_surface::RailPanel::Tasks\n        || app.work_surface.last_area.is_none()\n        || !app\n            .task_panel\n            .iter()\n            .any(|task| task.id.starts_with(\"shell_\") && task.status == \"running\")\n    {\n        return false;\n    }\n\n    app.input = \"/jobs cancel-all\".to_string();","sourceCodeStart":1234,"sourceCodeEnd":1270,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/ui.rs#L1234-L1270","documentation":"Requesting a foreground/background switch on the shell session requires locking the shell manager's Mutex. If the mutex is poisoned (another thread panicked while holding it), lock() returns Err and this error tells the user the shell-tracking state is unrecoverable in-process and the app must be restarted.","triggerScenarios":"Calling the foreground/background shell control path while the shell_manager Mutex is poisoned — i.e. some earlier code path panicked while holding the lock (a bug in shell tracking), and a subsequent command tries to lock it.","commonSituations":"A prior panic inside a shell-tracking routine (signal handling, process reap) poisoning the mutex; hitting shell commands after an internal panic that was caught somewhere upstream.","solutions":["Restart Codewhale — a poisoned mutex cannot be safely recovered in-process; this is what the message advises","Report/diagnose the original panic that poisoned the mutex (check logs for the first panic backtrace)","As a defensive fix, use lock().unwrap_or_else(|p| p.into_inner()) only if you can prove the poisoned state is still consistent — generally not recommended"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Cannot pre-validate a poisoned mutex; detect it cheaply:\nfn mutex_ok(m: &std::sync::Mutex<ShellManager>) -> bool {\n    !m.is_poisoned()\n}","typeGuard":null,"tryCatchPattern":"match shell_manager.lock() {\n    Ok(mut manager) => manager.request_foreground_background(),\n    Err(_) => {\n        app.add_message(HistoryCell::System {\n            content: \"Shell tracking hit an internal error — restart Codewhale to recover.\".into(),\n        });\n    }\n}","preventionTips":["Panic-free shell-tracking code: return Result instead of unwrapping while holding the lock","Keep lock scopes short to reduce the window for poisoning","Log the first panic's backtrace — it is the real bug behind the poisoned mutex"],"tags":["mutex-poisoned","shell","internal-error","panic"],"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"}