{"record":{"id":"5a6efcbc8921dab4","repo":"Hmbown/CodeWhale","slug":"foreground-shell-did-not-return-a-process-id","errorCode":null,"errorMessage":"foreground shell did not return a process id","messagePattern":"foreground shell did not return a process id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/shell.rs","lineNumber":4544,"sourceCode":"            spawn_timeout_ms,\n            true,\n            stdin_data,\n            tty,\n            policy_override,\n            extra_env,\n            owner,\n            context.state_namespace.clone(),\n            context.origin_tool_call_id.clone(),\n            context.origin_turn_id.clone(),\n            lifecycle,\n            direct_argv.then_some(context.workspace.as_path()),\n            false,\n            timeout_bounds_ms,\n        )?\n    };\n    let task_id = spawned\n        .task_id\n        .ok_or_else(|| anyhow!(\"foreground shell did not return a process id\"))?;\n    let mut foreground = ForegroundShellGuard {\n        manager: context.shell_manager.clone(),\n        task_id: task_id.clone(),\n        armed: true,\n    };\n    if let Some(permit) = heavy_permit {\n        let mut manager = context\n            .shell_manager\n            .lock()\n            .map_err(|_| anyhow!(\"shell manager lock poisoned\"))?;\n        manager.attach_heavy_permit(&task_id, permit)?;\n    }\n\n    if stdin_data.is_some() {\n        let mut manager = context\n            .shell_manager\n            .lock()\n            .map_err(|_| anyhow!(\"shell manager lock poisoned\"))?;","sourceCodeStart":4526,"sourceCodeEnd":4562,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/shell.rs#L4526-L4562","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: spawn returns without registering\nOk(SpawnedShell { task_id: None, .. })\n// after\nlet task_id = manager.register(pid);\nOk(SpawnedShell { task_id: Some(task_id), .. })","handlingStrategy":"type-guard","validationCode":"if spawned.task_id.is_none() {\n    return Err(anyhow!(\"spawn did not register a task id\"));\n}","typeGuard":"fn has_task_id(s: &SpawnedShell) -> bool { s.task_id.is_some() }","tryCatchPattern":"let task_id = spawned.task_id.ok_or_else(|| anyhow!(\"foreground shell did not return a process id\"))?;\n// caller: match on error and fall back to background execution","preventionTips":["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"],"tags":["shell","process-management","internal"],"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"}