{"record":{"id":"924febceadba6c27","repo":"xai-org/grok-build","slug":"byte-budget-exceeded-bytes-in","errorCode":null,"errorMessage":"byte budget exceeded: {}/{} bytes in {}","messagePattern":"byte budget exceeded: (.+?)/(.+?) bytes in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-tools/src/implementations/grok_build/storage.rs","lineNumber":92,"sourceCode":"        // compare_exchange ensures only the winner initialises; losers no-op.\n        if self.counter.load(Ordering::Relaxed) == 0\n            && let Ok((max_n, total_bytes)) = scan_dir_stats(&dir).await\n            && self\n                .counter\n                .compare_exchange(0, max_n, Ordering::Relaxed, Ordering::Relaxed)\n                .is_ok()\n        {\n            self.bytes_written.fetch_add(total_bytes, Ordering::Relaxed);\n        }\n\n        let n = self.counter.fetch_add(1, Ordering::Relaxed) + 1;\n\n        let size = bytes.len() as u64;\n        let new_total = self.bytes_written.fetch_add(size, Ordering::Relaxed) + size;\n        if new_total > self.max_total_bytes {\n            self.bytes_written.fetch_sub(size, Ordering::Relaxed);\n            self.counter.fetch_sub(1, Ordering::Relaxed);\n            anyhow::bail!(\n                \"byte budget exceeded: {}/{} bytes in {}\",\n                new_total,\n                self.max_total_bytes,\n                self.dir_name\n            );\n        }\n\n        let ext = ext_override.unwrap_or(self.ext);\n        let path = dir.join(format!(\"{n}.{ext}\"));\n\n        // Atomic write: tempfile -> sync_all -> persist, all in one\n        // spawn_blocking call to avoid blocking the async executor.\n        let dest = path.clone();\n        let target_dir = dir;\n        let data = bytes.to_vec();\n        let result: anyhow::Result<()> = tokio::task::spawn_blocking(move || {\n            let tmp = tempfile::NamedTempFile::new_in(&target_dir).context(\"create temp file\")?;\n            std::fs::write(tmp.path(), &data).context(\"write temp file\")?;","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-tools/src/implementations/grok_build/storage.rs#L74-L110","documentation":"Error \"byte budget exceeded: {}/{} bytes in {}\" thrown in xai-org/grok-build.","triggerScenarios":"Thrown at crates/codegen/xai-grok-tools/src/implementations/grok_build/storage.rs:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}