Hmbown/CodeWhale · error · anyhow::Error

Command timed out after {}ms

Error message

Command timed out after {}ms

What it means

When the exec child outlives its timeout budget, the runner kills it (kill + wait) and bails with the elapsed limit in milliseconds. Output already streamed is kept; the kill guarantees the run terminates instead of hanging forever.

Source

Thrown at crates/tui/src/lib.rs:9133

            print!("{}", String::from_utf8_lossy(&stdout));
        }
        if !stderr.is_empty() {
            eprint!("{stderr_str}");
        }
        if sandbox_denied {
            eprintln!(
                "{}",
                SandboxManager::denial_message(sandbox_type, &stderr_str)
            );
        }

        if !status.success() {
            bail!("Command failed with exit code {exit_code}");
        }
    } else {
        let _ = child.kill();
        let _ = child.wait();
        bail!("Command timed out after {}ms", timeout.as_millis());
    }
    Ok(())
}

fn parse_sandbox_policy(
    policy: &str,
    network: bool,
    writable_root: Vec<PathBuf>,
    exclude_tmpdir: bool,
    exclude_slash_tmp: bool,
) -> Result<crate::sandbox::SandboxPolicy> {
    use crate::sandbox::SandboxPolicy;

    match policy {
        "danger-full-access" => Ok(SandboxPolicy::DangerFullAccess),
        "read-only" => Ok(SandboxPolicy::ReadOnly),
        "external-sandbox" => Ok(SandboxPolicy::ExternalSandbox {
            network_access: network,

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Raise the timeout (see the exec command's --help for the exact flag) to fit the workload
  2. Replace watch/serve-style commands with bounded ones (build instead of dev)
  3. Find the hang: run the command bare under `timeout 30 ...` and inspect where it stalls
  4. Give hanging prompts a non-interactive flag (--yes, CI=true) or feed stdin

Example fix

# before
codewhale exec -- npm run dev     # Command timed out after 30000ms

# after
codewhale exec --timeout 300000 -- npm run build   # bounded workload (flag name per --help)
Defensive patterns

Strategy: retry

Validate before calling

# gauge runtime before granting a budget
timeout 15 "$CMD" >/dev/null 2>&1; rc=$?
[ $rc -eq 124 ] && echo 'command exceeds 15s -- raise exec timeout' >&2

Try / catch

match run_sandboxed_exec(cmd, policy, timeout) {
    Err(e) if e.to_string().contains("Command timed out") => {
        // re-run ONCE with a larger budget; a deterministic hang will not fix itself
        run_sandboxed_exec(cmd, policy, timeout * 4)
    }
    other => other,
}

Prevention

When it happens

Trigger: Watch-mode or server commands (npm run dev, --watch flags) under exec; tests hanging on network or a missing TTY prompt; a timeout left at default while the workload legitimately needs longer.

Common situations: Long builds in CI with tight defaults; interactive prompts blocking forever in non-interactive runs; flaky external dependencies stalling the command.

Understand the failure class

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/d13d75f545f60536. Report an issue: GitHub.