ultraworkers/claw-code · error · std::io::Error

file is too large ({} bytes, max {} bytes)

Error message

file is too large ({} bytes, max {} bytes)

What it means

`read_file` (runtime/src/file_ops.rs:195) rejects any file whose `fs::metadata().len()` exceeds `MAX_READ_SIZE`, a 10 MiB constant (file_ops.rs:14). The check runs on the WHOLE file before offset/limit windowing, so requesting a tiny line window of an oversized file still fails. `ErrorKind::InvalidData`.

Source

Thrown at rust/crates/runtime/src/file_ops.rs:195

    pub num_matches: Option<usize>,
    #[serde(rename = "appliedLimit")]
    pub applied_limit: Option<usize>,
    #[serde(rename = "appliedOffset")]
    pub applied_offset: Option<usize>,
}

/// Reads a text file and returns a line-windowed payload.
pub fn read_file(
    path: &str,
    offset: Option<usize>,
    limit: Option<usize>,
) -> io::Result<ReadFileOutput> {
    let absolute_path = normalize_path(path)?;

    // Check file size before reading
    let metadata = fs::metadata(&absolute_path)?;
    if metadata.len() > MAX_READ_SIZE {
        return Err(io::Error::new(
            io::ErrorKind::InvalidData,
            format!(
                "file is too large ({} bytes, max {} bytes)",
                metadata.len(),
                MAX_READ_SIZE
            ),
        ));
    }

    // Detect binary files
    if is_binary_file(&absolute_path)? {
        return Err(io::Error::new(
            io::ErrorKind::InvalidData,
            "file appears to be binary",
        ));
    }

    let content = fs::read_to_string(&absolute_path)?;

View on GitHub (pinned to 08106b0c37)

Solutions

  1. Slice the file with the Bash tool instead: `sed -n '1,200p' big.log` or `tail -n 200 big.log`.
  2. Split/rotate the oversized file so each part is under 10 MiB, then read the parts.
  3. If you own the build, raise `MAX_READ_SIZE` in file_ops.rs and rebuild — but prefer slicing to avoid loading 10+ MiB into context.

Example fix

# before
Read(file="build/server.log", offset=0, limit=100)   # file is too large (11258992 bytes, max 10485760 bytes)

# after
Bash(command="sed -n '1,100p' build/server.log")
Defensive patterns

Strategy: validation

Validate before calling

const MAX_READ_SIZE: u64 = 10 * 1024 * 1024; // must mirror file_ops.rs:14

fn readable_by_tool(p: &Path) -> io::Result<bool> {
    Ok(std::fs::metadata(p)?.len() <= MAX_READ_SIZE)
}

Try / catch

match read_file(path, offset, limit) {
    Err(e) if e.kind() == std::io::ErrorKind::InvalidData
        && e.to_string().contains("file is too large") => { /* fall back to bash sed/tail slicing */ }
    other => other,
}

Prevention

When it happens

Trigger: Calling the Read tool on an 11 MiB log, minified JS bundle, dataset CSV, or core dump — even with `offset`/`limit` set to a small slice; TOCTOU size change between metadata and read is not the issue here, the pre-check is unconditional.

Common situations: Agents trying to inspect large generated artifacts (lockfiles, snapshots, training logs); CI outputs; files that grew past 10 MiB since a previous successful read.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of ultraworkers/claw-code@08106b0c37 (2026-08-18). Data as JSON: /api/errors/c3096bf45a73c3ea. Report an issue: GitHub.