Skip to content

fix: tolerate a torn .meta cache in SourceFileMutationData.load() - #630

Merged
boxed merged 1 commit into
boxed:mainfrom
RonaldHensbergen:fix/torn-meta-cache-load
Nov 7, 2026
Merged

boxed merged 1 commit into
boxed:mainfrom
RonaldHensbergen:fix/torn-meta-cache-load

Conversation

@RonaldHensbergen

Copy link
Copy Markdown
Contributor

Problem

SourceFileMutationData.load() (src/mutmut/mutation/data.py) only catches FileNotFoundError. A mutants/*.meta cache file that is empty or truncated because the run was killed mid-write (CI runner shutdown, timeout, Ctrl-C during save) therefore crashes every later command that loads the cache — mutmut run, mutmut results, mutmut export-cicd-stats, mutmut badge, mutmut browse — with:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Observed in the wild in composable-data-stack's kill-matrix workflow (RonaldHensbergen/composable-data-stack#1175), where a time-capped PR run was killed mid-write and the export step went red on the torn cache.

Fix

Catch json.JSONDecodeError alongside FileNotFoundError in load(): an unparseable cache is treated like a missing one, so the run starts from empty state and the next save() overwrites the torn file. This mirrors MutantLineSpans.load() in the same module, which already catches (FileNotFoundError, json.JSONDecodeError).

Tests

New TestSourceFileMutationDataLoad in tests/mutation/test_mutation.py:

  • round-trip save/load still restores exit codes and durations;
  • missing meta file loads as empty;
  • empty, truncated, and non-JSON meta files (parametrized) load as empty instead of raising JSONDecodeError — these 3 fail on the unpatched code with exactly the reported error.

uv run pytest tests/ --ignore=tests/e2e: 468 passed, 3 skipped. ruff check and ruff format --check clean on the changed files.

load() only caught FileNotFoundError, so a mutants/*.meta file left
empty or truncated when a run was killed mid-write crashed
run/results/export-cicd-stats/browse with json.decoder.JSONDecodeError.
Treat an unparseable cache file like a missing one and start from
empty state, matching MutantLineSpans.load() in the same module.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@boxed

boxed commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thanks!

@RonaldHensbergen

Copy link
Copy Markdown
Contributor Author

Thanks for the repo!

@RonaldHensbergen
RonaldHensbergen deleted the fix/torn-meta-cache-load branch November 7, 2026 16:52
RonaldHensbergen added a commit to RonaldHensbergen/composable-data-stack that referenced this pull request Nov 7, 2026
…he-sanitizer

fix(ci): drop kill-matrix meta-cache sanitizer, pin mutmut to the boxed/mutmut#630 commit (#1193)
RonaldHensbergen added a commit to RonaldHensbergen/composable-data-stack that referenced this pull request Nov 9, 2026
…acks the #630 fix

The two ExportStepFunctionalTest torn-cache tests crashed with
json.JSONDecodeError on a dev machine with a PyPI mutmut (3.8.1)
installed, because the torn-mutants/*.meta tolerance (boxed/mutmut#630)
exists only in the git commit pinned by make test-mutation and the
mutation workflow. Probe the installed mutmut once (export-cicd-stats
against an empty mutants/foo.py.meta) and skip those tests with a clear
message when the fix is absent; the no-mutmut stub path (CI) and the
pinned-commit path are unchanged. Verified in all three modes: no
mutmut -> 10 passed; PyPI 3.8.1 -> 8 passed, 2 skipped; pinned commit ->
10 passed.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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.

2 participants