Hmbown/CodeWhale · error

Shell tracking hit an internal error — restart Codewhale to…

Error message

Shell tracking hit an internal error — restart Codewhale to recover.

What it means

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.

Solutions

  1. Restart Codewhale — a poisoned mutex cannot be safely recovered in-process; this is what the message advises
  2. Report/diagnose the original panic that poisoned the mutex (check logs for the first panic backtrace)
  3. 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
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot pre-validate a poisoned mutex; detect it cheaply:
fn mutex_ok(m: &std::sync::Mutex<ShellManager>) -> bool {
    !m.is_poisoned()
}

Try / catch

match shell_manager.lock() {
    Ok(mut manager) => manager.request_foreground_background(),
    Err(_) => {
        app.add_message(HistoryCell::System {
            content: "Shell tracking hit an internal error — restart Codewhale to recover.".into(),
        });
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/b17a1609fa1f4336. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/ui.rs:1252

    match request_active_foreground_shell_background(app) {
        Ok(()) => {
            app.status_message = Some("Moving current shell command to /jobs...".to_string());
        }
        Err(err) => {
            app.status_message = Some(err.to_string());
        }
    }
}

fn request_active_foreground_shell_background(app: &App) -> Result<()> {
    let shell_manager = app
        .runtime_services
        .shell_manager
        .clone()
        .context("No shell session is active.")?;
    let mut manager = shell_manager.lock().map_err(|_| {
        anyhow::anyhow!("Shell tracking hit an internal error — restart Codewhale to recover.")
    })?;
    manager.request_foreground_background();
    Ok(())
}

pub(crate) fn prefill_jobs_cancel_all_if_tasks_sidebar(app: &mut App) -> bool {
    if !app.view_stack.is_empty()
        || app.work_surface.panel != crate::tui::work_surface::RailPanel::Tasks
        || app.work_surface.last_area.is_none()
        || !app
            .task_panel
            .iter()
            .any(|task| task.id.starts_with("shell_") && task.status == "running")
    {
        return false;
    }

    app.input = "/jobs cancel-all".to_string();

View on GitHub (pinned to 73e0f67d83)