{"record":{"id":"54e9994333a9136f","repo":"xai-org/grok-build","slug":"reference-snapshot-did-not-match-expected-sha256","errorCode":null,"errorMessage":"reference snapshot did not match expected sha256; upload skipped","messagePattern":"reference snapshot did not match expected sha256; upload skipped","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-file-utils/src/queue.rs","lineNumber":1220,"sourceCode":"        };\n        let snapshot = self\n            .queue_dir\n            .join(temp_file_name(artifact_name, session_id, turn_number));\n        let disk_bytes = match reflink_copy::reflink_or_copy(source_path, &snapshot) {\n            Ok(copied) => copied.unwrap_or(0),\n            Err(e) => {\n                return Err(anyhow::Error::new(e).context(format!(\n                    \"Failed to snapshot {} into upload queue\",\n                    source_path.display()\n                )));\n            }\n        };\n        match check_snapshot(&snapshot, expected_sha256) {\n            SnapshotCheck::Match => {}\n            SnapshotCheck::Stale => {\n                try_remove_temp(&snapshot, Some(&self.stats));\n                self.stats.reference_stale.fetch_add(1, Ordering::Relaxed);\n                let _ = tx.send(Err(anyhow::anyhow!(\n                    \"reference snapshot did not match expected sha256; upload skipped\"\n                )));\n                return Ok(EnqueueResult {\n                    completion_rx: rx,\n                    original_size,\n                });\n            }\n            SnapshotCheck::Io(e) => {\n                try_remove_temp(&snapshot, Some(&self.stats));\n                self.stats.failed.fetch_add(1, Ordering::Relaxed);\n                let _ = tx.send(Err(e));\n                return Ok(EnqueueResult {\n                    completion_rx: rx,\n                    original_size,\n                });\n            }\n        }\n        tracing::debug!(","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-file-utils/src/queue.rs#L1202-L1238","documentation":"This error is produced by the background upload queue when a reference snapshot's SHA-256 no longer matches the expected digest (SnapshotCheck::Stale). The queue detects that the file content changed since the snapshot was taken and refuses to upload stale data, notifying the caller's completion channel with this error instead. It indicates an integrity guard, not a transport failure: the upload is intentionally skipped to avoid publishing content that no longer matches what the caller snapshotted.","triggerScenarios":"Enqueueing a file whose on-disk bytes (or temp snapshot) were modified or truncated between snapshot creation and the SHA-256 verification at upload time; calling to_url/builder_for/client_for flows that feed the queue with a snapshot that was rotated, re-written, or removed before upload; concurrent writes to the same temp file while a queued upload is pending.","commonSituations":"Two processes writing the same temp/reference file concurrently; a build or formatter regenerating the reference right after it was queued; a snapshot kept alive past its validity window while the source file changed underneath; disk-level partial writes corrupting the temp snapshot.","solutions":["Do not modify or delete the source/temp snapshot file until the completion receiver resolves; hold it for the duration of the queue wait.","Take a fresh snapshot and re-enqueue the upload after all writes to the file have completed.","Check completion_rx for this error and treat it as 'upload skipped' rather than a network failure; retry the whole enqueue operation.","Ensure only one writer owns the snapshot at a time (use unique temp paths per upload instead of shared reference files)."],"exampleFix":"// before\nlet result = queue.enqueue(path).await;\nstd::fs::write(path, new_content)?; // mutates snapshot before upload\n\n// after\nlet result = queue.enqueue(path).await;\nlet outcome = result.completion_rx.await; // wait before touching the file\nstd::fs::write(path, new_content)?;","handlingStrategy":"validation","validationCode":"// Verify snapshot integrity before enqueue\nfn ensure_snapshot_matches(path: &Path, expected_sha256: &str) -> anyhow::Result<()> {\n    let bytes = std::fs::read(path)?;\n    let digest = sha2::Sha256::digest(&bytes);\n    if format!(\"{:x}\", digest) != expected_sha256 {\n        anyhow::bail!(\"snapshot changed on disk; re-snapshot before enqueue\");\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write to or delete a snapshot file between enqueue and completion.","Use unique temp paths per upload instead of shared reference files.","Always await the completion receiver before mutating the source file.","Re-take snapshots after any regeneration step (formatters, codegen)."],"tags":["rust","integrity","sha256","upload-queue","stale-snapshot"],"backgroundTag":"snapshot-hash-mismatch","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}