{"record":{"id":"9a88b229d65d839c","repo":"Hmbown/CodeWhale","slug":"invalid-lane-environment-key-key","errorCode":null,"errorMessage":"invalid lane environment key {key:?}","messagePattern":"invalid lane environment key (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/lane/src/runtime.rs","lineNumber":234,"sourceCode":"    match std::fs::remove_file(path) {\n        Ok(()) => Ok(()),\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),\n        Err(err) => Err(err).with_context(|| format!(\"remove {}\", path.display())),\n    }\n}\n\nfn valid_environment_key(key: &str) -> bool {\n    let mut chars = key.chars();\n    chars\n        .next()\n        .is_some_and(|ch| ch == '_' || ch.is_ascii_alphabetic())\n        && chars.all(|ch| ch == '_' || ch.is_ascii_alphanumeric())\n}\n\nfn write_lane_environment(path: &Path, environment: &[(String, String)]) -> Result<()> {\n    for (key, _) in environment {\n        if !valid_environment_key(key) {\n            bail!(\"invalid lane environment key {key:?}\");\n        }\n    }\n    let encoded = serde_json::to_vec(environment).context(\"serialize private lane environment\")?;\n    if encoded.len() as u64 > MAX_ENVIRONMENT_BYTES {\n        bail!(\n            \"private lane environment exceeds {} bytes\",\n            MAX_ENVIRONMENT_BYTES\n        );\n    }\n\n    let tmp_path = lane_environment_tmp_path(path);\n    remove_file_if_present(path)?;\n    remove_file_if_present(&tmp_path)?;\n    let mut options = OpenOptions::new();\n    options.create_new(true).write(true);\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::OpenOptionsExt;","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/lane/src/runtime.rs#L216-L252","documentation":"write_lane_environment serializes the private environment key/value pairs to a JSON file owned by the lane. Before writing anything it validates every key against valid_environment_key (underscore or ASCII alphanumeric only) and fails the whole write if any key is malformed, so no partial secret file is ever left on disk.","triggerScenarios":"Calling start() (which calls write_lane_environment) with an environment list containing a key with invalid characters, e.g. containing '-', '.', '=', spaces, or non-ASCII characters.","commonSituations":"Copying shell-style env definitions like \"MY-VAR\" or \"some.key\" into the lane environment; building keys dynamically by concatenating names with separators; inheriting env from an external system with laxer key rules.","solutions":["Rename the offending key to use only ASCII letters, digits, and underscores.","Sanitize/normalize keys before passing the environment list to start().","Check the error message's {key:?} value to identify exactly which entry is invalid.","Test environment input with the existing guard (invalid_environment_key_never_leaves_a_partial_secret_file scenario) when adding new key sources."],"exampleFix":"// before\nlet env = vec![(\"MY-VAR\".to_string(), \"1\".to_string())];\n// after\nlet env = vec![(\"MY_VAR\".to_string(), \"1\".to_string())];","handlingStrategy":"validation","validationCode":"fn valid_env_key(key: &str) -> bool { !key.is_empty() && key.chars().all(|c| c == '_' || c.is_ascii_alphanumeric()) }\nenv.iter().find(|(k, _)| !valid_env_key(k)).map_or(Ok(()), |(k, _)| Err(format!(\"invalid env key {k:?}\"))).?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = registry.start(...) { if e.to_string().contains(\"invalid lane environment key\") { env.retain(|(k, _)| valid_env_key(k)); /* retry */ } }","preventionTips":["Sanitize/normalize keys when importing environment from external sources.","Never build keys by string concatenation with separators like '-' or '.'.","Validate keys at the boundary where the environment list is constructed."],"tags":["environment","validation","secret-file"],"backgroundTag":"invalid-identifier-format","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}