{"record":{"id":"524c69f3c251a0ce","repo":"Hmbown/CodeWhale","slug":"private-lane-environment-exceeds-bytes-524c69","errorCode":null,"errorMessage":"private lane environment {} exceeds {} bytes","messagePattern":"private lane environment (.+?) exceeds (.+?) bytes","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/lane/src/runtime.rs","lineNumber":342,"sourceCode":"            reader.consume(take);\n            if ended_line {\n                break;\n            }\n        }\n        if line.is_empty() && reached_eof {\n            return Ok(());\n        }\n        append_child_output(&log_path, stream, &line)?;\n        if reached_eof {\n            return Ok(());\n        }\n    }\n}\n\nfn read_lane_environment(path: &Path) -> Result<Vec<(String, String)>> {\n    let metadata = fs::metadata(path).with_context(|| format!(\"stat {}\", path.display()))?;\n    if metadata.len() > MAX_ENVIRONMENT_BYTES {\n        bail!(\n            \"private lane environment {} exceeds {} bytes\",\n            path.display(),\n            MAX_ENVIRONMENT_BYTES\n        );\n    }\n    let bytes = fs::read(path).with_context(|| format!(\"read {}\", path.display()))?;\n    if bytes.len() as u64 > MAX_ENVIRONMENT_BYTES {\n        bail!(\n            \"private lane environment {} exceeds {} bytes\",\n            path.display(),\n            MAX_ENVIRONMENT_BYTES\n        );\n    }\n    let environment: Vec<(String, String)> =\n        serde_json::from_slice(&bytes).with_context(|| format!(\"parse {}\", path.display()))?;\n    for (key, _) in &environment {\n        if !valid_environment_key(key) {\n            bail!(\"invalid lane environment key {key:?}\");","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/lane/src/runtime.rs#L324-L360","documentation":"Raised by read_lane_environment when the private lane environment file (a JSON array of key/value pairs the parent pinned for the lane) stats larger than MAX_ENVIRONMENT_BYTES (1 MiB, runtime.rs:174). The guard prevents a corrupt, foreign, or hostile file from being read wholesale into memory. This is the first of two checks: a stat-based pre-check before fs::read.","triggerScenarios":"Calling a lane start that leads to read_lane_environment(path) where fs::metadata(path).len() > 1_048_576. Concretely: LaneStartSpec environment serialized by write_lane_environment exceeded 1 MiB, or the environment path points at a stale/unrelated large file in a reused log directory.","commonSituations":"Passing bulky values (base64 blobs, long tokens, serialized payloads) through the lane environment; a log directory reused across lane generations so an old environment file survives; external tooling writing into the lane's private state directory.","solutions":["Shrink the environment to essential keys and re-start the lane","Inspect the file named in the message (ls -l / stat) and delete it if it is stale, then retry the start","Move large values out of the environment and pass them via a file path or command argument","If you control the writer, keep the serialized environment under 1 MiB before the lane is launched so both guards stay green"],"exampleFix":"// before\nlet spec = LaneStartSpec {\n    command: vec![\"bash\".into()],\n    environment: all_exports.clone(), // may exceed 1 MiB\n    ..\n};\n\n// after\nlet environment: Vec<(String, String)> = all_exports\n    .into_iter()\n    .filter(|(k, _)| matches!(k.as_str(), \"PATH\" | \"HOME\" | \"CODEWHALE_*\"))\n    .collect();\nassert!(serde_json::to_vec(&environment).unwrap().len() <= 1024 * 1024);\nlet spec = LaneStartSpec { command: vec![\"bash\".into()], environment, .. };","handlingStrategy":"validation","validationCode":"const MAX_ENVIRONMENT_BYTES: usize = 1024 * 1024;\n\nfn environment_within_bound(environment: &[(String, String)]) -> bool {\n    serde_json::to_vec(environment)\n        .map(|bytes| bytes.len() <= MAX_ENVIRONMENT_BYTES)\n        .unwrap_or(false)\n}\n\n// before start:\nassert!(environment_within_bound(&spec.environment), \"environment too large\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize and size-check the environment before every lane start","Keep secrets and payloads out of the lane environment; pass file paths instead","Use fresh log/state directories per lane generation so stale oversized files cannot be inherited"],"tags":["rust","lane","environment","size-limit","file-io"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}