{"record":{"id":"9b4328f4c9394101","repo":"rtk-ai/rtk","slug":"stdin-exceeds-byte-limit","errorCode":null,"errorMessage":"stdin exceeds {} byte limit","messagePattern":"stdin exceeds (.+?) byte limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/system/pipe_cmd.rs","lineNumber":269,"sourceCode":"            input.to_string()\n        },\n    )\n}\n\npub fn run(filter_name: Option<&str>, passthrough: bool) -> Result<()> {\n    if passthrough {\n        std::io::copy(&mut std::io::stdin(), &mut std::io::stdout())\n            .map_err(|e| anyhow::anyhow!(\"Failed to relay stdin: {}\", e))?;\n        return Ok(());\n    }\n\n    let mut buf = String::new();\n    std::io::stdin()\n        .take((RAW_CAP + 1) as u64)\n        .read_to_string(&mut buf)\n        .map_err(|e| anyhow::anyhow!(\"Failed to read stdin: {}\", e))?;\n    if buf.len() > RAW_CAP {\n        anyhow::bail!(\"stdin exceeds {} byte limit\", RAW_CAP);\n    }\n\n    let filter_fn = match filter_name {\n        Some(name) => resolve_filter(name).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Unknown filter '{}'. Available: cargo-test, pytest, go-test, go-build, \\\n                 ctest, tsc, vitest, grep, rg, find, fd, git-log, git-diff, git-status, \\\n                 log, mypy, ruff-check, ruff-format, sqlfluff-lint, prettier, phpunit, pest, \\\n                 paratest, php-test, ecs, phpstan, pint\",\n                name\n            )\n        })?,\n        None => auto_detect_filter(&buf),\n    };\n\n    let output = apply_filter(filter_fn, &buf);\n    let shown = never_worse(&buf, &output);\n    print!(\"{}\", shown);","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/system/pipe_cmd.rs#L251-L287","documentation":"`rtk pipe` reads stdin up to a hard cap of RAW_CAP (10 MiB, from src/core/stream.rs). It reads RAW_CAP+1 bytes so it can detect overflow; if more than 10 MiB arrives, it bails instead of silently truncating, protecting the LLM context window from unbounded input.","triggerScenarios":"Piping more than 10 MiB into `rtk pipe` (e.g. `cat huge.log | rtk pipe`), with or without a --filter name; any invocation of pipe_cmd::run whose stdin exceeds RAW_CAP bytes.","commonSituations":"Piping full build logs, large test suite output, or database dumps; forgetting an upstream filter (grep/head) on a chatty command; CI artifacts streamed whole instead of summarized.","solutions":["Reduce input before piping: `cat huge.log | grep ERROR | rtk pipe` or `... | tail -n 10000 | rtk pipe`.","Apply a named filter so rtk compresses at the source: `cargo test 2>&1 | rtk pipe --filter cargo-test` where possible instead of piping raw output.","Split or rotate the oversized input and process it in chunks under 10 MiB.","Use `rtk proxy <cmd>` or run the command directly if you need the full raw output (bypassing the cap) — at the cost of token usage."],"exampleFix":"// before\ncat build.log | rtk pipe          # build.log is 40 MiB -> exceeds 10 MiB cap\n// after\ngrep -E 'ERROR|WARN' build.log | rtk pipe   # or: tail -c 10M build.log | rtk pipe","handlingStrategy":"validation","validationCode":"const MAX = 10 * 1024 * 1024; // RAW_CAP = 10_485_760 bytes\nconst stat = fs.fstatSync(0);\nif (stat.size > MAX) throw new Error(`stdin exceeds ${MAX} byte limit; filter or truncate first`);","typeGuard":"fn within_cap(len: usize, cap: usize = 10_485_760) -> bool { len <= cap }","tryCatchPattern":"match rtk_pipe_result {\n    Err(e) if e.to_string().contains(\"stdin exceeds\") => {\n        eprintln!(\"input too large; pipe through grep/head/tail or use --filter before rtk pipe\");\n        std::process::exit(1);\n    }\n    other => other?,\n}","preventionTips":["Pre-filter stdin (grep, head, tail, awk) before `rtk pipe` for large logs.","Use a named --filter (cargo-test, pytest, go-test, ...) so rtk compresses at the source.","Check file size (`du -h` / fstat) of piped artifacts in CI before invoking rtk pipe.","For genuinely huge output, bypass with `rtk proxy` only when full fidelity is required."],"tags":["cli","stdin","payload-limit","pipe"],"backgroundTag":"payload-too-large","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}