{"record":{"id":"cb857acf9ce39536","repo":"Hmbown/CodeWhale","slug":"stdin-is-not-available-for-task","errorCode":null,"errorMessage":"stdin is not available for task {}","messagePattern":"stdin is not available for task (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/shell.rs","lineNumber":1367,"sourceCode":"    }\n\n    fn write_stdin_bytes(&mut self, input: &[u8], close: bool) -> Result<()> {\n        if let Some(stdin) = self.stdin.as_mut() {\n            if !input.is_empty() {\n                stdin.write_all(input).context(\"Failed to write to stdin\")?;\n                stdin.flush().context(\"Failed to flush stdin\")?;\n            }\n            if close {\n                self.stdin = None;\n            }\n            return Ok(());\n        }\n\n        if input.is_empty() && close {\n            return Ok(());\n        }\n\n        Err(anyhow!(\"stdin is not available for task {}\", self.id))\n    }\n\n    fn full_output(&self) -> (String, String, usize, usize) {\n        if let Some(snapshot) = self.bounded_output_snapshot(false).ok().flatten() {\n            return (snapshot.content, String::new(), snapshot.total_bytes, 0);\n        }\n        let (stdout_bytes, stderr_bytes, stdout_omitted, stderr_omitted) =\n            self.retained_output_bytes_with_omissions();\n        // Report what the stream produced, not what is still held.\n        let stdout_len = stdout_bytes.len().saturating_add(stdout_omitted);\n        let stderr_len = stderr_bytes.len().saturating_add(stderr_omitted);\n\n        (\n            String::from_utf8_lossy(&stdout_bytes).to_string(),\n            String::from_utf8_lossy(&stderr_bytes).to_string(),\n            stdout_len,\n            stderr_len,\n        )","sourceCodeStart":1349,"sourceCodeEnd":1385,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/shell.rs#L1349-L1385","documentation":"The shell task's stdin writer refuses input when no stdin channel is available for the task. If the caller sent an empty input without requesting close, the method returns Ok early; in every other case where stdin cannot be delivered (the task has no live stdin handle, e.g. it already exited or was spawned with stdin closed), it throws \"stdin is not available for task {id}\".","triggerScenarios":"Calling the shell task's write-input/send-stdin method with non-empty input (or close=true with input) on a task that was not spawned with an interactive stdin pipe, or whose process has already exited and dropped its stdin handle.","commonSituations":"Attempting to interactively prompt a long-running command that was launched without stdin attached; sending input to a task after it finished; tools/clients treating every shell job as interactive when only some are spawned with pipes.","solutions":["Confirm the task was spawned with an interactive stdin pipe (the mode that exposes stdin) before sending input.","Check the task's status first — if it has exited, stdin is gone; start a new task instead.","If you only wanted to signal completion, send an empty input with close=true only when stdin exists, otherwise handle the already-terminated case gracefully."],"exampleFix":"// before\nif task.status() == Exited {\n    task.send_input(\"y\\n\", false)?; // errors: stdin gone\n}\n\n// after\nif task.supports_stdin() && task.status() != Exited {\n    task.send_input(\"y\\n\", false)?;\n} else {\n    return Err(anyhow!(\"task {} cannot accept stdin\", task.id()));\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn can_send_stdin(task: &ShellTask) -> bool {\n    task.supports_stdin() && !task.has_exited()\n}\n// guard before writing:\n// if can_send_stdin(&task) { task.send_input(data, close)?; }","tryCatchPattern":"// treat this as a state error: do not retry blindly\nmatch task.send_input(input, close) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"stdin is not available\") => {\n        // task not interactive or already exited: surface or start a new task\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Only spawn interactive tasks when you intend to write to stdin.","Check task status for exit before sending input.","Combine empty input with close=true only when stdin is known to exist."],"tags":["stdin","shell","process","invalid-state"],"backgroundTag":"unsupported-operation","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"}