xai-org/grok-build · error
failed to write chrome trace: {}
Error message
failed to write chrome trace: {} What it means
After creating the output file, generate_chrome_trace serializes the trace with serde_json::to_writer_pretty; any serialization/stream error is wrapped in this message. Because the trace value is a simple serde_json::json! literal, failures here are almost always I/O errors on the write side (disk full, closed/failed file handle) rather than JSON encode bugs.
Source
Thrown at crates/codegen/xai-grok-telemetry/src/instrumentation.rs:505
});
events.push(trace_event);
seen += 1;
}
if seen == 0 {
return Err(anyhow!("no timing events found in {:?}", input));
}
let trace = serde_json::json!({
"displayTimeUnit": "ms",
"traceEvents": events,
});
let mut output_file = std::fs::File::create(&output)
.map_err(|err| anyhow!("failed to create chrome trace {:?}: {}", output, err))?;
serde_json::to_writer_pretty(&mut output_file, &trace)
.map_err(|err| anyhow!("failed to write chrome trace: {}", err))?;
Ok(output)
}
pub fn finalize() -> Result<()> {
let mode = mode();
if mode == InstrumentationMode::Disabled {
return Ok(());
}
drop_guard(LOG_GUARD.get());
drop_guard(CHROME_GUARD.get());
Ok(())
}
fn drop_guard<T>(guard: Option<&Mutex<Option<T>>>) {
if let Some(lock) = guardView on GitHub (pinned to bc7f02eddd)
Solutions
- Check free disk space (`df -h`) on the output target and clear space
- Retry after confirming the filesystem is healthy and writable
- Verify no disk quota is exceeded in CI/container environments
- If it persists, inspect `err.source()`/raw io error for the specific OS code
Example fix
// before
serde_json::to_writer_pretty(&mut output_file, &trace)
.map_err(|err| anyhow!("failed to write chrome trace: {}", err))?;
// after
serde_json::to_writer_pretty(&mut output_file, &trace)
.map_err(|err| anyhow!("failed to write chrome trace: {}", err))?;
output_file.sync_all()
.map_err(|err| anyhow!("failed to flush chrome trace: {}", err))?; Defensive patterns
Strategy: try-catch
Validate before calling
// check space before writing
let meta = output.parent().and_then(|d| fs2::available_space(d).ok());
if meta.map_or(false, |bytes| bytes < 1_000_000) { eprintln!("low disk space"); } Try / catch
match generate_chrome_trace(opts) {
Err(e) if e.to_string().contains("failed to write chrome trace") => {
eprintln!("write failed mid-stream: {e}; check disk space and retry");
let _ = std::fs::remove_file(&partial_output); // clean partial file
}
other => other,
} Prevention
- Monitor free disk space before large writes
- Clean up partial output files on failure
- Avoid writing traces to network/removable mounts
- Retain the underlying io::Error source for diagnosis
When it happens
Trigger: Calling generate_chrome_trace where the write to the already-created output file fails mid-stream — typically ENOSPC (disk full), a broken pipe, or an I/O error from the underlying file handle.
Common situations: Generating a large trace on a nearly-full disk; writing to a network mount or removable drive that dropped; container/CI disk quota exhausted during the write.
Related errors
- failed to open instrumentation log {:?}: {}
- failed to create chrome trace {:?}: {}
- Failed to set working directory to {:?}: {}
- Failed to load config: {e}
- reading command stdout: {e}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/340cc83b87286202.
Report an issue: GitHub.