{"record":{"id":"340cc83b87286202","repo":"xai-org/grok-build","slug":"failed-to-write-chrome-trace","errorCode":null,"errorMessage":"failed to write chrome trace: {}","messagePattern":"failed to write chrome trace: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-telemetry/src/instrumentation.rs","lineNumber":505,"sourceCode":"        });\n\n        events.push(trace_event);\n        seen += 1;\n    }\n\n    if seen == 0 {\n        return Err(anyhow!(\"no timing events found in {:?}\", input));\n    }\n\n    let trace = serde_json::json!({\n        \"displayTimeUnit\": \"ms\",\n        \"traceEvents\": events,\n    });\n\n    let mut output_file = std::fs::File::create(&output)\n        .map_err(|err| anyhow!(\"failed to create chrome trace {:?}: {}\", output, err))?;\n    serde_json::to_writer_pretty(&mut output_file, &trace)\n        .map_err(|err| anyhow!(\"failed to write chrome trace: {}\", err))?;\n\n    Ok(output)\n}\n\npub fn finalize() -> Result<()> {\n    let mode = mode();\n    if mode == InstrumentationMode::Disabled {\n        return Ok(());\n    }\n\n    drop_guard(LOG_GUARD.get());\n    drop_guard(CHROME_GUARD.get());\n\n    Ok(())\n}\n\nfn drop_guard<T>(guard: Option<&Mutex<Option<T>>>) {\n    if let Some(lock) = guard","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-telemetry/src/instrumentation.rs#L487-L523","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nserde_json::to_writer_pretty(&mut output_file, &trace)\n    .map_err(|err| anyhow!(\"failed to write chrome trace: {}\", err))?;\n// after\nserde_json::to_writer_pretty(&mut output_file, &trace)\n    .map_err(|err| anyhow!(\"failed to write chrome trace: {}\", err))?;\noutput_file.sync_all()\n    .map_err(|err| anyhow!(\"failed to flush chrome trace: {}\", err))?;","handlingStrategy":"try-catch","validationCode":"// check space before writing\nlet meta = output.parent().and_then(|d| fs2::available_space(d).ok());\nif meta.map_or(false, |bytes| bytes < 1_000_000) { eprintln!(\"low disk space\"); }","typeGuard":null,"tryCatchPattern":"match generate_chrome_trace(opts) {\n    Err(e) if e.to_string().contains(\"failed to write chrome trace\") => {\n        eprintln!(\"write failed mid-stream: {e}; check disk space and retry\");\n        let _ = std::fs::remove_file(&partial_output); // clean partial file\n    }\n    other => other,\n}","preventionTips":["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"],"tags":["io","disk-full","serde-json","telemetry"],"backgroundTag":"failed-to-write-file","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}