Skip to content

feat: results-library phase 0a — artefact integrity - #1736

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/results-library-p0-integrity
Oct 29, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/results-library-p0-integrity

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Results-library phase 0, PR 0a of 2 (#1734), shared with hpc-campaign. Makes result artefacts complete-or-absent and stops one bad file from breaking every rerun:

  • result zips are written to a temp file and renamed into place, so a killed job never leaves a truncated zip; image/FITS/HDF5 members are stored uncompressed
  • restore() no longer deletes the output directory or the zip it did not create; it extracts into a temp sibling and renames (safe for concurrent restorers), and a corrupt zip is renamed <hash>.zip.corrupt_<utc> and the fit carries on as "not complete"
  • a zipped result counts as complete when it contains a .completed member and passes testzip() (cached per path)
  • an unreadable Nautilus or dynesty checkpoint is moved to search_internal.failed_<utc>/ and the search starts fresh, instead of crashing on resume
  • timer files move to files/ and are written atomically

PR 0b (honest reads in the aggregator / AggregateCSV) follows as a stacked PR. hpc-campaign phase 1 (#1735) merges after this one; both touch abstract_search.py and merge cleanly.

API Changes

Additive, plus safer behaviour of existing calls. restore() no longer deletes a zip it does not own and no longer re-raises BadZipFile; is_complete now recognises zipped results. New read-only paths.open_result(). Timer reads fall back to the legacy location, so old output still loads.
See full details below.

Test Plan

  • test_autofit/non_linear/paths/test_artefact_integrity.py (new): killed-mid-zip resumes; two processes restore one zip concurrently and both read it; truncated-HDF5 and poisoned-dill checkpoints are quarantined and start fresh; .png/.fits/.hdf5 members are ZIP_STORED
  • Full test_autofit suite: 3,953 passed, 2 skipped, 1 xfailed
  • Smoke: pyauto-heart smoke autofit autolens_test: 47 passed, 0 failed (8 autofit scripts + 2 notebooks, 37 autolens_workspace_test scripts)
Full API Changes (for automation & release notes)

Added

  • AbstractPaths.open_result() — read-only view of a finished result: the output directory, or a zipfile.Path into the zip; never extracts
  • autofit.non_linear.paths.abstract.zip_is_complete(zip_path) — .completed member + clean testzip()
  • Checkpointer.probe(paths); checkpoint.probe_hdf5(path), checkpoint.quarantine_search_internal(paths, reason=None), checkpoint.resume_state_usable(paths, resume_state)
  • autofit.tools.util.compress_type_for(file_path) — ZIP_STORED for .png/.fits/.hdf/.hdf5/.h5, ZIP_DEFLATED otherwise
  • Timer(timer_path, legacy_path=None) — optional legacy read location

Changed behaviour

  • zip_directory writes <out>.zip.<pid>.tmp then os.replace
  • restore() leaves a complete output directory untouched; removes the zip only when remove_files is set and the path is identifier-keyed; BadZipFile → zip renamed <hash>.zip.corrupt_<utc>, warning logged, result treated as not complete
  • DirectoryPaths.is_complete is true for a zip with a .completed member
  • Nautilus retries once from scratch on a LinAlgError when resumed
  • Timer files are written to files/.start_time and files/.time

Migration

  • None required. Code that relied on restore() raising BadZipFile should check is_complete instead.

Refs #1734

🤖 Generated with Claude Code

- zip_directory writes <out>.zip.<pid>.tmp and os.replace-s it into place, so a
  result zip is complete or absent; .png/.fits/.hdf/.hdf5/.h5 members are
  ZIP_STORED, text DEFLATED (also used by preserve_in_zip appends).
- restore() is non-destructive: a complete output directory is left untouched,
  a zip is extracted into a temporary sibling and renamed into place (safe for
  concurrent restorers), the zip is deleted only when owned (remove_files and an
  identifier-keyed path), and a BadZipFile zip is renamed
  <hash>.zip.corrupt_<utc> and the search continues as not complete.
- New read-only open_result() (output directory or zipfile.Path, never extracts).
- DirectoryPaths.is_complete reads a zipped result: .completed member + clean
  testzip(), cached per path by (size, mtime).
- Checkpointer.probe / probe_hdf5 / quarantine_search_internal /
  resume_state_usable: Nautilus (h5py probe) and dynesty (savestate restore
  probe) move an unreadable search_internal/ to search_internal.failed_<utc>/ and
  start fresh; Nautilus retries once from scratch on a LinAlgError when resumed.
- Timer writes files/.start_time and files/.time atomically behind has_timer,
  reading the legacy files/search_internal/ location as a fallback.

Refs #1734

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nhQ8N4RdvbZz9cstLYtNF
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 29, 2026
@Jammy2211
Jammy2211 merged commit cb2d423 into main Oct 29, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/results-library-p0-integrity branch October 29, 2026 21:23
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 1, 2026
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.

1 participant