Hmbown/CodeWhale · critical
shell manager lock poisoned
Error message
shell manager lock poisoned
What it means
Before spawning a foreground shell command the tool locks the shared ShellManager mutex; if another thread panicked while holding that lock, the mutex is poisoned and `.lock()` returns Err. The tool converts this into an anyhow error rather than running shell work against a manager in an inconsistent state. This is a symptom of an earlier panic in shell-management code, not a problem with the command being run.
Solutions
- Find and fix the originating panic — scan earlier logs for the panic that poisoned the mutex
- Restart the session/process; a poisoned std::sync::Mutex stays poisoned until recreated
- If recovery is required, switch the field to parking_lot::Mutex or handle PoisonError with into_inner() after auditing invariants
- Reduce concurrent shell-manager access (cancel in-flight background shells before foreground runs) to shrink the race window
Example fix
// before
context.shell_manager.lock().map_err(|_| anyhow!("shell manager lock poisoned"))?
// after (audited recovery)
context.shell_manager.lock().unwrap_or_else(|p| p.into_inner()) Defensive patterns
Strategy: retry
Validate before calling
// detect poisoned state before use
fn manager_healthy(m: &Mutex<ShellManager>) -> bool { m.try_lock().is_ok() || poisoned_ok(m) } Try / catch
match context.shell_manager.lock() {
Ok(mut m) => { /* proceed */ }
Err(_) => return Err(anyhow!("shell manager unavailable (poisoned); restart session")),
} Prevention
- Never panic while holding the shell manager lock
- Keep lock scopes minimal and free of unwraps
- Use parking_lot::Mutex if lock poisoning recovery is desired
- Monitor logs for the first panic — it precedes all poisoning errors
When it happens
Trigger: Calling the foreground shell execute path when any prior panic occurred while a thread held the shell_manager Mutex (e.g. a panic inside execute_with_options_env_for_owner_and_work, poll_status, kill, or output snapshotting).
Common situations: A background/async shell task panicked earlier in the session; a kill-during-timeout race hit an unexpected state and panicked; a bug in ShellManager bookkeeping (eviction while reading results) panicked under contention in long-running TUI sessions.
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
- catalog cache unavailable
- Clock lock failed
- Frame lock failed
- Shell tracking hit an internal error — restart Codewhale to…
- xAI OAuth lifecycle lock was poisoned
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/19d6efa3a3b3ff17.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/shell.rs:4519
command: &str,
heavy_permit: Option<HeavyCommandPermit>,
working_dir: Option<String>,
timeout_ms: Option<u64>,
stdin_data: Option<&str>,
tty: bool,
policy_override: Option<ExecutionSandboxPolicy>,
extra_env: HashMap<String, String>,
direct_argv: bool,
timeout_bounds_ms: (u64, u64),
) -> Result<ShellResult> {
let timeout_ms =
timeout_ms.map(|timeout| timeout.clamp(timeout_bounds_ms.0, timeout_bounds_ms.1));
let spawn_timeout_ms = timeout_ms.unwrap_or(timeout_bounds_ms.1);
let spawned = {
let mut manager = context
.shell_manager
.lock()
.map_err(|_| anyhow!("shell manager lock poisoned"))?;
manager.clear_foreground_background_request();
let owner = shell_job_owner_from_context(context);
let lifecycle = shell_work_lifecycle_from_context(context);
manager.execute_with_options_env_for_owner_and_work(
command,
working_dir.as_deref(),
spawn_timeout_ms,
true,
stdin_data,
tty,
policy_override,
extra_env,
owner,
context.state_namespace.clone(),
context.origin_tool_call_id.clone(),
context.origin_turn_id.clone(),
lifecycle,
direct_argv.then_some(context.workspace.as_path()),View on GitHub (pinned to 73e0f67d83)