AlexsJones/llmfit · error

CSV flush failed

Error message

CSV flush failed

What it means

Panic from .expect("CSV flush failed") on writer.flush() at the end of display_csv_fits (display.rs:991). The csv::Writer wraps std::io::stdout(), and flush pushes buffered rows through std::io::Stdout::flush — it fails with an IO error when the pipe is already broken (downstream consumer exited), when stdout is redirected to a full disk (ENOSPC), or when the target file/mount disappears mid-run. Since SIGPIPE is ignored in Rust programs, a reader closing the pipe early shows up here as a flush error rather than a signal.

Source

Thrown at llmfit-tui/src/display.rs:1042

                score_fit: round1(fit.score_components.fit),
                score_context: round1(fit.score_components.context),
                estimated_tps: round1(fit.estimated_tps),
                memory_required_gb: round2(fit.memory_required_gb),
                memory_available_gb: round2(fit.memory_available_gb),
                utilization_pct: round1(fit.utilization_pct),
                disk_size_gb: round2(fit.model.estimate_disk_gb(&fit.best_quant)),
                best_quant: fit.best_quant.clone(),
                runtime: fit.runtime.label().to_string(),
                use_case: fit.use_case.label().to_string(),
                release_date: fit.model.release_date.clone(),
                license: fit.model.license.clone(),
                is_moe: fit.model.is_moe,
                installed: fit.installed,
            })
            .expect("CSV serialization failed");
    }

    writer.flush().expect("CSV flush failed");
}

#[cfg(test)]
mod tests {
    use super::*;
    use llmfit_core::fit::{FitLevel, InferenceRuntime, ScoreComponents};
    use llmfit_core::models::{Capability, GgufSource, ModelFormat, UseCase};

    fn mock_fit(run_mode: RunMode, use_case: UseCase, model_use_case: &str) -> ModelFit {
        ModelFit {
            model: LlmModel {
                name: "test/model-7b".to_string(),
                provider: "test".to_string(),
                parameter_count: "7B".to_string(),
                parameters_raw: None,
                min_ram_gb: 4.0,
                recommended_ram_gb: 8.0,
                min_vram_gb: Some(4.0),

View on GitHub (pinned to 8f16394d74)

Solutions

  1. Write to a file first (`llmfit fit --csv > out.csv`) and post-process the file — this eliminates broken pipes entirely.
  2. Verify free space on the redirection target (df -h .) and on $TMPDIR when piping through tools like sponge/tee.
  3. Ensure the downstream pipe consumer reads until EOF instead of exiting early, or drop the pipe.
  4. As a maintainer, treat BrokenPipe on flush as success (exit 141 silently) and surface other IO errors on stderr instead of expect.

Example fix

// before
writer.flush().expect("CSV flush failed");

// after
if let Err(e) = writer.flush() {
    if e.kind() == std::io::ErrorKind::BrokenPipe {
        std::process::exit(141);
    }
    eprintln!("error: failed to flush CSV output: {e}");
    std::process::exit(1);
}
Defensive patterns

Strategy: fallback

Validate before calling

# Shell-level: ensure the flush has somewhere to go and the target is writable.
llmfit fit --csv > /tmp/llmfit-models.csv || echo "csv write failed (disk full?)" >&2
test -s /tmp/llmfit-models.csv   # confirm non-empty output landed

Try / catch

let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
    display::display_csv_fits(&fits);
}));
if result.is_err() {
    eprintln!("error: CSV flush failed (downstream reader closed early or disk full)");
    std::process::exit(141);
}

Prevention

When it happens

Trigger: The final flush after `llmfit fit --csv | head -n1` (head exits after one line, stdout breaks); redirecting to a file on a filesystem that fills up between row writes and flush; piping into a subprocess that crashes partway.

Common situations: Automation sampling large CSV outputs; cron jobs writing CSV to nearly-full volumes; interactive use with pagers quit early; NFS/FUSE mounts that drop during long outputs.

Related errors


AI-assisted analysis of AlexsJones/llmfit@8f16394d74 (2026-08-17). Data as JSON: /api/errors/5643d8194d446411. Report an issue: GitHub.