{"record":{"id":"4223e14c3637e464","repo":"Hmbown/CodeWhale","slug":"task-task-id-not-found","errorCode":null,"errorMessage":"Task {task_id} not found","messagePattern":"Task (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/shell.rs","lineNumber":2849,"sourceCode":"                Some(sandbox_type.to_string())\n            } else {\n                None\n            },\n            sandbox_denied: false,\n        })\n    }\n\n    /// Get output from a background process\n    pub fn get_output(\n        &mut self,\n        task_id: &str,\n        block: bool,\n        timeout_ms: u64,\n    ) -> Result<ShellResult> {\n        let shell = self\n            .processes\n            .get_mut(task_id)\n            .ok_or_else(|| anyhow!(\"Task {task_id} not found\"))?;\n\n        if block && shell.status == ShellStatus::Running {\n            let timeout = Duration::from_millis(timeout_ms.clamp(1000, 600_000));\n            let deadline = Instant::now() + timeout;\n\n            while shell.status == ShellStatus::Running && Instant::now() < deadline {\n                if shell.poll() {\n                    break;\n                }\n                std::thread::sleep(Duration::from_millis(100));\n            }\n\n            // If still running after timeout\n            if shell.status == ShellStatus::Running {\n                return shell.snapshot();\n            }\n        } else {\n            shell.poll();","sourceCodeStart":2831,"sourceCodeEnd":2867,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/shell.rs#L2831-L2867","documentation":"ShellManager::get_output looks up the background job by task_id in its in-memory process map and errors with 'Task {id} not found' when the id is absent. Background jobs are evicted after finishing (retention age FINISHED_SHELL_MAX_AGE) and are per-manager state, so an id from an earlier session, an evicted record, or a typo has no entry.","triggerScenarios":"Calling get_output(task_id, ...) with an id that was never created, was already evicted after completion, belongs to a different manager/session instance, or was killed and cleaned up.","commonSituations":"Model/agent reuses a task_id from a previous conversation turn after the record aged out; app restart clears in-memory jobs; hardcoding or hallucinating a task id; race where cleanup() evicted the finished job before output was fetched.","solutions":["Re-check the id with the jobs/list API before fetching output; use the exact task_id returned by the spawn call.","If the job finished and was evicted, treat its output as unavailable and re-run the command.","Check for session restart or a different ShellManager instance between spawn and fetch.","Increase retention (FINISHED_SHELL_MAX_AGE) or fetch output promptly after spawn instead of late."],"exampleFix":"// before\nlet out = manager.get_output(task_id, true, 5000)?;\n// after\nif !manager.job_exists(task_id) {\n    eprintln!(\"job {task_id} no longer tracked (finished/evicted); re-run the command\");\n    return Ok(());\n}\nlet out = manager.get_output(task_id, true, 5000)?;","handlingStrategy":"validation","validationCode":"// Rust: confirm the job is tracked before fetching output\nfn job_tracked(manager: &ShellManager, task_id: &str) -> bool {\n    manager.list_jobs().iter().any(|j| j.id == task_id)\n}\n// call site:\nif !job_tracked(&manager, task_id) { return Err(anyhow!(\"job {task_id} already evicted; re-run the command\")); }","typeGuard":null,"tryCatchPattern":"match manager.get_output(task_id, true, 5000) {\n    Ok(out) => out,\n    Err(e) if e.to_string().contains(\"not found\") => {\n        eprintln!(\"job {task_id} no longer tracked (finished/evicted)\");\n        re_run_command()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always use the task_id exactly as returned by the spawn call — never reconstruct or guess it","Fetch output promptly after completion; finished records are evicted after a retention window","Re-derive the job list from the current ShellManager instance after any session restart","Treat 'not found' during output fetch as end-of-life for the job, not a transient failure — do not retry"],"tags":["background-process","task-not-found","lifecycle"],"backgroundTag":"record-not-found","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"}