{"record":{"id":"71bb25fb61e13619","repo":"Hmbown/CodeWhale","slug":"persistent-service-has-no-process-group-id","errorCode":null,"errorMessage":"Persistent service has no process group id","messagePattern":"Persistent service has no process group id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/shell.rs","lineNumber":2793,"sourceCode":"            terminal_size: tty.then(PtyDimensions::default),\n            child: Some(child),\n            #[cfg(windows)]\n            windows_job,\n            stdout_thread,\n            stderr_thread,\n            work_lifecycle,\n            lifecycle_seq: 0,\n            last_lifecycle_status: None,\n            last_lifecycle_bytes: 0,\n        };\n\n        #[cfg(unix)]\n        if persist_pending {\n            let process_group_id = bg_shell\n                .child\n                .as_ref()\n                .and_then(ShellChild::process_id)\n                .ok_or_else(|| anyhow!(\"Persistent service has no process group id\"))?;\n            register_pending_persistent_process_group(process_group_id);\n        }\n\n        if let Some(input) = stdin_data\n            && let Err(err) = bg_shell.write_stdin(input, false)\n        {\n            let _ = bg_shell.kill();\n            return Err(err);\n        }\n\n        if let Err(err) = bg_shell.publish_lifecycle() {\n            let _ = bg_shell.kill();\n            return Err(err);\n        }\n\n        self.processes.insert(task_id.clone(), bg_shell);\n        spawn_guard.disarm();\n        // Evict here, not only from `list_jobs()`: retention must not depend on","sourceCodeStart":2775,"sourceCodeEnd":2811,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/shell.rs#L2775-L2811","documentation":"During background-shell spawn, when the job was requested as a pending persistent service (persist_pending, unix only), the manager must register the child's OS process id as a persistent process group so it survives and can be reaped later. If ShellChild::process_id() returns None — the child handle does not expose a pid at that point — the spawn fails with this error rather than registering a bogus group.","triggerScenarios":"Calling the shell tool with persist/persistent-service semantics on unix when the freshly spawned child cannot report its pid: the child was spawned without pid capture support, or the child handle variant in use (e.g. a PTY or sandboxed variant) returns None from process_id().","commonSituations":"Persistent-service spawn on a unix platform where the sandbox/PTY child wrapper does not carry a process id; internal spawn-path changes that leave child = Some(...) but with an id-less variant; code paths where the child was already reaped between spawn and this lookup.","solutions":["Re-run the persistent-service command; transient spawn races usually succeed on retry.","Check whether the command runs under a sandbox or PTY wrapper that does not expose a pid; run it as a normal background job instead of a persistent service.","If it reproduces every time, inspect ShellChild::process_id for the child variant being spawned — it must return Some for the persistent path on unix.","Report/fix upstream: spawn should either guarantee a pid for persist_pending or reject the request earlier with a clearer message."],"exampleFix":"// before\nlet process_group_id = bg_shell\n    .child\n    .as_ref()\n    .and_then(ShellChild::process_id)\n    .ok_or_else(|| anyhow!(\"Persistent service has no process group id\"))?;\n// after\nlet process_group_id = bg_shell\n    .child\n    .as_ref()\n    .and_then(ShellChild::process_id)\n    .with_context(|| format!(\"persistent service '{}' spawned without a pid (child variant: {:?})\", task_id, bg_shell.child.as_ref().map(ShellChild::kind)))?;","handlingStrategy":"try-catch","validationCode":"// Rust: pre-check child variant exposes a pid before persist_pending path\nif persist_pending && bg_shell.child.as_ref().and_then(ShellChild::process_id).is_none() {\n    return Err(anyhow!(\"cannot persist service: spawned child has no pid on this platform\"));\n}","typeGuard":"fn child_has_pid(child: Option<&ShellChild>) -> bool {\n    child.and_then(ShellChild::process_id).is_some()\n}","tryCatchPattern":"match spawn_persistent(...) {\n    Ok(result) => result,\n    Err(e) if e.to_string().contains(\"no process group id\") => {\n        // fall back to a normal background job; persistence unavailable for this child type\n        spawn_background(...)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Only request persistent-service semantics for child spawn variants that expose a pid on unix","Add a unit test spawning the persistent path for every ShellChild variant","Fail the request at argument-validation time when the platform/wrapper cannot provide a pid"],"tags":["process-spawn","unix","persistent-service","pty"],"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"}