Skip to content

fix(eval): don't drop a random-named report file in the CWD - #141

Open
ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-128-evaluate-report-file
Open

ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-128-evaluate-report-file

Conversation

@ddaihao2022

Copy link
Copy Markdown
Contributor

Summary

Closes #128

evaluate() called save_json_report() unconditionally. When save_report was None it generated evaluation_results_<uuid>.json, so every call from a notebook, a test or a loop left a new file behind in the working directory — and the report embeds every mismatch with the full model output, so a full run can be tens of MB. (tests/conftest.py already had a session fixture sweeping evaluation_results* out of the CWD, which is a good sign this was biting in practice.)

Changes

  • llmsql/evaluation/evaluate.py — write the file only when save_report is given. The report dict is already returned to the caller, so API users lose nothing. Also dropped the now-unused uuid import.
  • llmsql/_cli/evaluate.py — the CLI still writes a report by default (a one-shot CLI run should leave one behind), but at a deterministic path derived from --outputs: <outputs>.eval.json. Re-running on the same predictions overwrites the previous report instead of piling up new ones, and --save-report still wins when given.
  • llmsql/evaluation/evaluate.py — the SQLite connection now goes through contextlib.closing() around the evaluation loop. It used to be closed by a bare conn.close() at the very end of the function, so any exception raised by evaluate_sample() leaked the connection (also mentioned in the issue).
  • llmsql/evaluation/README.md — updated the two places that documented the old evaluation_results_{uuid}.json default.

Not done (marked optionally in the issue): capping stored mismatches via max_saved_mismatches. That changes the report schema for anyone parsing it today, so it felt like a separate decision — happy to add it if you want it in this PR.

Tests

  • test_no_report_file_is_written_when_save_report_is_none replaces test_saves_report_with_auto_filename, which asserted exactly the behaviour this issue asks us to remove.
  • test_report_is_written_to_the_given_path keeps the save_report=<path> path covered.
  • tests/cli/test_cli.py: two new tests pin the default <outputs>.eval.json name and check that an explicit --save-report is passed through untouched.

Verification

Local (Windows, no GPU):

PYTHONPATH=. pytest tests/evaluation tests/cli -q
  • tests/evaluation: 24 passed before, still green with the new/updated tests (25 passed).
  • tests/cli: the 5 new/updated report tests pass. 4 pre-existing failures in tests/cli/test_cli.py / tests/cli/test_model_args.py are unrelated — they need transformers, which isn't installed here.
  • Reverting evaluate.py / _cli/evaluate.py makes test_no_report_file_is_written_when_save_report_is_none and test_evaluate_default_report_path_is_deterministic fail, so the new tests really pin the fix.
  • Not run locally: tests/inference/* and the vLLM/GPU-marked suites (multi-GB wheels + GPU).

Closes LLMSQL#128

`evaluate()` called `save_json_report()` unconditionally. When `save_report`
was None it generated `evaluation_results_<uuid>.json`, so every call from a
notebook, a test or a loop left a new file behind in the working directory —
and the report embeds every mismatch with the full model output, so a full run
can be tens of MB. The repo even had a session fixture that sweeps
`evaluation_results*` out of the CWD after the test session.

Changes:

* `evaluate()` writes the file only when `save_report` is given. The report
  dict was already returned to the caller, so nothing is lost for API users.
* `llmsql evaluate` still produces a report by default (a one-shot CLI run
  should leave one behind), but at a deterministic path derived from
  `--outputs`: `<outputs>.eval.json`. Re-running on the same predictions
  overwrites the previous report instead of piling up new ones.
* The SQLite connection now goes through `contextlib.closing()` around the
  evaluation loop. It used to be closed only by a bare `conn.close()` at the
  end of the function, so any exception raised by `evaluate_sample()` leaked it.
* Dropped the now-unused `uuid` import and updated `evaluation/README.md`,
  which documented the old default filename.

Tests:

* `test_no_report_file_is_written_when_save_report_is_none` replaces the old
  `test_saves_report_with_auto_filename`, which asserted the exact behaviour
  the issue asks us to remove.
* `test_report_is_written_to_the_given_path` keeps the `save_report=<path>`
  path covered.
* Two CLI tests pin the default `<outputs>.eval.json` name and check that an
  explicit `--save-report` is passed through untouched.
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Evaluation] evaluate() always writes a randomly named report file into the working directory

1 participant