{"record":{"id":"b678c5dd3ea006a7","repo":"Hmbown/CodeWhale","slug":"an-existing-fleet-artifact-contains-different-bytes","errorCode":null,"errorMessage":"An existing Fleet artifact contains different bytes","messagePattern":"An existing Fleet artifact contains different bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/fleet/artifacts.rs","lineNumber":36,"sourceCode":"// without retaining all bytes. The writer shares the ceiling so it cannot\n// publish an artifact the evidence reader is unable to verify.\nconst MAX_ARTIFACT_BYTES: u64 = 16 * 1024 * 1024;\n\npub(crate) fn write(workspace: &Path, relative: &Path, bytes: &[u8]) -> Result<()> {\n    ensure!(\n        bytes.len() as u64 <= MAX_ARTIFACT_BYTES,\n        \"Fleet artifact exceeds the 16 MiB limit\"\n    );\n    let parent = WorkspaceFile::open(workspace, relative, true)?;\n    match parent.publish(bytes) {\n        Ok(()) => Ok(()),\n        Err(error) if error.kind() == io::ErrorKind::AlreadyExists => {\n            let existing = parent.open_file()?;\n            let mut saved = Vec::new();\n            existing\n                .take(bytes.len() as u64 + 1)\n                .read_to_end(&mut saved)?;\n            ensure!(\n                saved == bytes,\n                \"An existing Fleet artifact contains different bytes\"\n            );\n            Ok(())\n        }\n        Err(error) => Err(error).context(\"Publishing Fleet artifact\"),\n    }\n}\n\npub(crate) fn read_verified(\n    workspace: &Path,\n    artifact: &FleetArtifactRef,\n    preview_limit: u64,\n) -> Result<(Vec<u8>, u64)> {\n    let parent = WorkspaceFile::open(workspace, &artifact.path, false)?;\n    let file = parent.open_file()?;\n    let size = file.metadata()?.len();\n    ensure!(","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/fleet/artifacts.rs#L18-L54","documentation":"Fleet artifact publication is immutable: when the target file already exists, write re-opens it and compares the existing bytes with the new payload. If they differ, publication fails with this error instead of overwriting — an existing artifact is treated as an immutable published record. Identical re-publication is allowed and returns Ok.","triggerScenarios":"Calling artifacts::write with a relative path that already exists in the Fleet workspace but whose on-disk content differs from the bytes being written (io::ErrorKind::AlreadyExists from publish, then byte comparison fails).","commonSituations":"Two runs writing different content to the same deterministic artifact path; a retry reusing a path after the payload changed (e.g. regenerated report with new data); manual editing or corruption of a previously published artifact; a stale artifact left from an earlier version of the pipeline.","solutions":["Use a content-addressed or run-unique relative path so distinct payloads never collide.","If the new bytes are the correct replacement, this immutability is intentional — remove the stale artifact deliberately and republish, or publish under a new versioned name.","If the existing file was corrupted externally, restore it from the recorded digest/receipt or delete it and republish.","Verify the payload is actually what you intend — the mismatch may reveal a non-deterministic generation step upstream."],"exampleFix":"// before\nartifacts::write(ws, Path::new(\"report.txt\"), &new_bytes)?;\n// after\nlet path = format!(\"report-{}.txt\", sha256_hex(&new_bytes));\nartifacts::write(ws, Path::new(&path), &new_bytes)?;","handlingStrategy":"validation","validationCode":"let path = format!(\"artifacts/{}-{}\", run_id, file_name);\nif ws.join(&path).exists() {\n    // treat as immutable: publish under a new name or compare first\n}","typeGuard":null,"tryCatchPattern":"match artifacts::write(ws, &path, &bytes) {\n    Err(e) if e.to_string().contains(\"different bytes\") => {\n        eprintln!(\"artifact {} already published with other content; use a new path\", path);\n    }\n    r => r?,\n}","preventionTips":["Make artifact paths content-addressed or run-scoped so re-publication never collides.","Never manually edit files under the Fleet workspace.","Treat existing artifacts as immutable records; version instead of overwrite."],"tags":["fleet","artifacts","immutability","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T06:17:15.046Z"}