{"record":{"id":"5c15d0e93171dd2f","repo":"ultraworkers/claw-code","slug":"content-is-too-large-bytes-max-bytes","errorCode":null,"errorMessage":"content is too large ({} bytes, max {} bytes)","messagePattern":"content is too large \\((.+?) bytes, max (.+?) bytes\\)","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust/crates/runtime/src/file_ops.rs","lineNumber":236,"sourceCode":"    });\n    let selected = lines[start_index..end_index].join(\"\\n\");\n\n    Ok(ReadFileOutput {\n        kind: String::from(\"text\"),\n        file: TextFilePayload {\n            file_path: absolute_path.to_string_lossy().into_owned(),\n            content: selected,\n            num_lines: end_index.saturating_sub(start_index),\n            start_line: start_index.saturating_add(1),\n            total_lines: lines.len(),\n        },\n    })\n}\n\n/// Replaces a file's contents and returns patch metadata.\npub fn write_file(path: &str, content: &str) -> io::Result<WriteFileOutput> {\n    if content.len() > MAX_WRITE_SIZE {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\n                \"content is too large ({} bytes, max {} bytes)\",\n                content.len(),\n                MAX_WRITE_SIZE\n            ),\n        ));\n    }\n\n    let absolute_path = normalize_path_allow_missing(path)?;\n    let original_file = fs::read_to_string(&absolute_path).ok();\n    if let Some(parent) = absolute_path.parent() {\n        fs::create_dir_all(parent)?;\n    }\n    fs::write(&absolute_path, content)?;\n\n    Ok(WriteFileOutput {\n        kind: if original_file.is_some() {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/ultraworkers/claw-code/blob/08106b0c3771ef5b4a5aa176acccd460e88b7325/rust/crates/runtime/src/file_ops.rs#L218-L254","documentation":"`write_file` (runtime/src/file_ops.rs:236) rejects content whose byte length exceeds `MAX_WRITE_SIZE`, 10 MiB (file_ops.rs:17). The limit applies to the full replacement payload because write_file rewrites the entire file. `ErrorKind::InvalidData`.","triggerScenarios":"Writing a generated bundle, snapshot, serialized dataset, or base64 blob larger than 10 MiB in a single Write tool call; concatenating outputs in memory then writing once.","commonSituations":"Agents materializing generated code bundles or fixtures; exporting session transcripts; embedding media as base64 in a source file.","solutions":["Split the output into multiple files each under 10 MiB.","Stream large content via the Bash tool (`cat > file <<'EOF'` chunks, or generate with a script) instead of one Write call.","Check `content.len()` before building the call and trim what actually needs writing."],"exampleFix":"# before\nWrite(file=\"snapshot.json\", content=<12MiB string>)   # content is too large (12582912 bytes, max 10485760 bytes)\n\n# after\nBash(command=\"generate_snapshot.py --out snapshot.json\")   # producer writes directly","handlingStrategy":"validation","validationCode":"const MAX_WRITE_SIZE: usize = 10 * 1024 * 1024; // must mirror file_ops.rs:17\n\nif content.len() > MAX_WRITE_SIZE {\n    // split into multiple files or write via bash heredoc chunks\n}","typeGuard":null,"tryCatchPattern":"match write_file(path, &content) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData\n        && e.to_string().contains(\"content is too large\") => { /* chunk it or generate via script */ }\n    other => other,\n}","preventionTips":["Check content.len() (bytes, not chars) before Write","Split generated bundles into <10 MiB files","Produce huge artifacts with a generator script via Bash instead of one Write"],"tags":["file-ops","write","size-limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"08106b0c3771ef5b4a5aa176acccd460e88b7325","analyzedAt":"2026-08-18T00:29:38.590Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}