Hmbown/CodeWhale · error

Task not found

Error message

Task {task_id} not found

What it means

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.

Solutions

  1. Re-check the id with the jobs/list API before fetching output; use the exact task_id returned by the spawn call.
  2. If the job finished and was evicted, treat its output as unavailable and re-run the command.
  3. Check for session restart or a different ShellManager instance between spawn and fetch.
  4. Increase retention (FINISHED_SHELL_MAX_AGE) or fetch output promptly after spawn instead of late.

Example fix

// before
let out = manager.get_output(task_id, true, 5000)?;
// after
if !manager.job_exists(task_id) {
    eprintln!("job {task_id} no longer tracked (finished/evicted); re-run the command");
    return Ok(());
}
let out = manager.get_output(task_id, true, 5000)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: confirm the job is tracked before fetching output
fn job_tracked(manager: &ShellManager, task_id: &str) -> bool {
    manager.list_jobs().iter().any(|j| j.id == task_id)
}
// call site:
if !job_tracked(&manager, task_id) { return Err(anyhow!("job {task_id} already evicted; re-run the command")); }

Try / catch

match manager.get_output(task_id, true, 5000) {
    Ok(out) => out,
    Err(e) if e.to_string().contains("not found") => {
        eprintln!("job {task_id} no longer tracked (finished/evicted)");
        re_run_command()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/4223e14c3637e464. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/shell.rs:2849

                Some(sandbox_type.to_string())
            } else {
                None
            },
            sandbox_denied: false,
        })
    }

    /// Get output from a background process
    pub fn get_output(
        &mut self,
        task_id: &str,
        block: bool,
        timeout_ms: u64,
    ) -> Result<ShellResult> {
        let shell = self
            .processes
            .get_mut(task_id)
            .ok_or_else(|| anyhow!("Task {task_id} not found"))?;

        if block && shell.status == ShellStatus::Running {
            let timeout = Duration::from_millis(timeout_ms.clamp(1000, 600_000));
            let deadline = Instant::now() + timeout;

            while shell.status == ShellStatus::Running && Instant::now() < deadline {
                if shell.poll() {
                    break;
                }
                std::thread::sleep(Duration::from_millis(100));
            }

            // If still running after timeout
            if shell.status == ShellStatus::Running {
                return shell.snapshot();
            }
        } else {
            shell.poll();

View on GitHub (pinned to 73e0f67d83)