Hmbown/CodeWhale · error
foreground shell did not return a process id
Error message
foreground shell did not return a process id
What it means
After spawning a foreground shell command, the manager must return a task_id identifying the spawned process so the tool can attach lifecycle guards (ForegroundShellGuard, heavy permits, stdin, polling). If `spawned.task_id` is None the spawn bookkeeping did not register a trackable process, so the tool refuses to continue rather than leaking an unmanaged child.
Solutions
- Upgrade/inspect the shell spawn code to ensure every successful spawn registers a task_id
- Check whether the shell manager was shutting down or at capacity when the spawn happened; retry after it is idle
- Reproduce with logging in execute_with_options_env_for_owner_and_work to see why task_id is None
- As a workaround, run the command via a different execution path (background shell tool) that returns a job id
Example fix
// before: spawn returns without registering
Ok(SpawnedShell { task_id: None, .. })
// after
let task_id = manager.register(pid);
Ok(SpawnedShell { task_id: Some(task_id), .. }) Defensive patterns
Strategy: type-guard
Validate before calling
if spawned.task_id.is_none() {
return Err(anyhow!("spawn did not register a task id"));
} Type guard
fn has_task_id(s: &SpawnedShell) -> bool { s.task_id.is_some() } Try / catch
let task_id = spawned.task_id.ok_or_else(|| anyhow!("foreground shell did not return a process id"))?;
// caller: match on error and fall back to background execution Prevention
- Ensure every spawn path registers the process with the manager
- Add an assertion/test that spawn always returns a task_id on success
- Avoid spawning while the manager is shutting down
- Log platform-specific pty spawn failures explicitly
When it happens
Trigger: Calling the foreground shell tool when the underlying spawn path returns a SpawnedShell without a task_id — typically a spawn implementation that failed to register the process with the ShellManager, or a platform/pty path that skips id assignment.
Common situations: A regression in the shell spawn code after a refactor; running on a platform where the pty/process registration path silently skips id assignment; manager state full or mid-shutdown so registration is skipped while spawn still reports success.
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
- agent profile may not request allow_shell=true
- allowlisted read-only executable
- classifier-approved Git read did not keep its subcommand in…
- classifier-approved Git read was missing its literal…
- classifier-approved read command was empty
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/5a6efcbc8921dab4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/shell.rs:4544
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()),
false,
timeout_bounds_ms,
)?
};
let task_id = spawned
.task_id
.ok_or_else(|| anyhow!("foreground shell did not return a process id"))?;
let mut foreground = ForegroundShellGuard {
manager: context.shell_manager.clone(),
task_id: task_id.clone(),
armed: true,
};
if let Some(permit) = heavy_permit {
let mut manager = context
.shell_manager
.lock()
.map_err(|_| anyhow!("shell manager lock poisoned"))?;
manager.attach_heavy_permit(&task_id, permit)?;
}
if stdin_data.is_some() {
let mut manager = context
.shell_manager
.lock()
.map_err(|_| anyhow!("shell manager lock poisoned"))?;View on GitHub (pinned to 73e0f67d83)