Skip to content

fix(aggregator): prefer a .completed zip over an incomplete sibling dir; preserve_in_zip leaves no loose copy - #1602

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/aggregator-sibling-dir-zip
Sep 10, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/aggregator-sibling-dir-zip

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Aggregator.from_directory skipped any zip that had a <hash>/ directory beside it, whether or not that directory stood for the search. Under hpc_mode the search directory is zipped and removed, and post-completion caches (PyAutoLens' multiple-image positions, PyAutoGalaxy's adapt-image SNR map) then write back into paths._files_path, which mkdirs on access. Each writer called preserve_in_zip, which added the member to the archive but left the loose file behind, so <hash>/files/ reappeared holding two cache artifacts and no .completed. The aggregator walked that directory instead of the zip, _is_search_output accepted it (the preserved files/search.json is the sentinel), and completed_only then dropped the search for having no .completed — silently.

On the pulled euclid_dr1_prelim RAL job 342398 that cost 15 of 20 searches: Aggregator.from_directory(root, completed_only=True) returned 5, the derived lens_mass.csv carried 5 of 10 rows, and build_inspection_bundle.sh aborted with "aggregator is empty". With this branch the same tree returns 20.

Three changes:

  1. autofit/aggregator/aggregator.py — the zip is skipped only when its extracted sibling actually carries .completed. Otherwise the zip is extracted (merging onto the sibling in place, or into the temporary directory under unzip_temporary, where the shadowing sibling is dropped from the walk so it cannot yield the search twice) and a logger.warning names the path. The old check sat ahead of the unzip_temporary branch, so both modes had the hole. The summary print now also reports how many outputs completed_only excluded, so a run that aggregates a fraction of its searches no longer looks complete.
  2. autofit/non_linear/paths/abstract.py — preserve_in_zip deletes the loose file, and prunes the directories that emptied up to and including output_path, when remove_files is set. There the zip is the search's only store, so the loose copy is not a second home for the file but the directory that caused the shadowing. With remove_files unset the output directory is the primary store and the loose copy stays.
  3. Search-output ordering — this is the cause of the five test_aggregate_csv failures that reproduced locally while CI stayed green (filed as bug/autofit/aggregate_csv_tests_fail_locally_pass_in_ci.md, hypothesised there as an environment difference; it is a library bug). scan collected outputs in raw os.walk order, which is hash order on ext4 and insertion order on tmpfs, so the fixture searches came back fit_2, fit_1 locally and fit_1, fit_2 on CI. Everything that pairs a row to an output by index — the summary CSV writers, add_label_column — paired them differently per machine. The collected lists are now sorted by path before they are returned (the collected lists, not dirs inside the walk, because the temporary extractions are scanned separately and never pass through that walk).

API Changes

  • Aggregator.from_directory now returns its search outputs in path order; previously they came back in filesystem directory-entry order, which differs between machines. Anything that indexed into an aggregator now gets a stable, reproducible order — and a different one from before on ext4.
  • Aggregator.from_directory no longer treats an extracted directory beside a zip as authoritative unless it carries .completed; such a directory is now overwritten in place (or bypassed under unzip_temporary), and a warning is logged.
  • AbstractPaths.preserve_in_zip now removes the loose file it preserved, and any directory it emptied, when remove_files is set. Callers that expected the file to remain on disk after preserving must read it back from the zip or recompute it.

No signatures changed and nothing was removed or renamed. See full details below.

Test Plan

  • pytest test_autofit/aggregator test_autofit/non_linear/paths -q -p no:cacheprovider — 113 passed.
  • pytest test_autofit -q -p no:cacheprovider (serial; -n auto has a pre-existing xdist collection mismatch in test_prior_properties.py) — 2567 passed, 2 skipped, 0 failed. On main in the same worktree this is 5 failed, 2557 passed, 2 skipped; the five failures are the test_aggregate_csv ordering bug fixed here, and they also reproduce on the canonical main checkout.
  • Manual witness on the pulled euclid_dr1_prelim 342398 tree — Aggregator.from_directory(".../dr1_prelim_grade_ab", completed_only=True, unzip_temporary=True) returns 20 on this branch and 5 on main. Fifteen warnings are logged, one per shadowed search; the science tree is left untouched (unzip_temporary=True).

New tests:

  • test_incomplete_sibling_directory_loses_to_the_zip / test_zip_temporary_incomplete_sibling_directory_loses_to_the_zip — a sibling without .completed loses to the zip in both modes and completed_only=True still returns 1.
  • test_zip_not_re_extracted / test_zip_temporary_uses_an_existing_extracted_directory — rewritten to the new contract: a sibling with .completed still wins and the directory on disk is not overwritten.
  • test_search_outputs_are_sorted_by_path — os.walk monkeypatched to reverse its directory entries; the aggregated outputs still come back in path order.
  • test__preserve_in_zip__removes_the_loose_copy_under_remove_files / test__preserve_in_zip__keeps_the_loose_copy_without_remove_files — the two remove_files settings.

Downstream workspace impact

None — no workspace changes needed. Every downstream consumer already calls the unchanged signature Aggregator.from_directory(directory=..., completed_only=True, unzip_temporary=True):

  • euclid_strong_lens_modeling_pipeline/workflow/csv_make.py:91
  • euclid_strong_lens_modeling_pipeline/catalogue/scripts/{lens_mass,lens_sersic,source_sersic,magnitudes,deblending,multi_wavelength}.py

They pick up the fix without an edit — csv_make.py and the catalogue scripts will simply see the searches that were being dropped. The ordering change means catalogue rows come out in a different (now stable) order than the last local run; no script indexes an aggregator positionally against an external list.

Full API Changes (for automation & release notes)

Changed Behaviour

  • autofit.aggregator.Aggregator.from_directory(...) — search outputs and grid search outputs are returned sorted by path. Previously the order was the filesystem's directory-entry order, which is hash order on ext4 and insertion order on tmpfs, so the same results tree gave different orders on different machines.
  • autofit.aggregator.Aggregator.from_directory(...) — a <name>/ directory beside <name>.zip is only preferred over the zip when it contains a .completed file. Without one, the zip is extracted (over the directory in place, or into the temporary directory under unzip_temporary, in which case the sibling is skipped by the walk) and a warning is logged naming the path.
  • autofit.aggregator.Aggregator.from_directory(...) — the summary printed on load reports the number of outputs excluded by completed_only.
  • autofit.non_linear.paths.abstract.AbstractPaths.preserve_in_zip(file_path) — under remove_files the loose file is deleted once it is a member of the zip, along with any parent directory the deletion emptied, up to and including output_path. Unchanged when remove_files is unset.

Added

  • autofit.non_linear.paths.abstract.AbstractPaths._remove_preserved_copy(file_path) — private helper for the above.

Removed / Renamed / Changed Signature

  • None.

Migration

  • Code that called preserve_in_zip and then read the file back from disk under remove_files must read the zip member instead, or recompute. The two known callers (PyAutoLens Result._cached_multiple_image_positions_from, PyAutoGalaxy's adapt-image SNR cache) already recompute when the file is absent; making them read the preserved member instead is filed as a follow-up (PyAutoMind/draft/refactor/autolens/cache_readers_fall_back_to_zip_member.md).

Fixes #1601

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CybZmqjyQRDpfK3Cs1JaW2

`Aggregator.from_directory` skipped any zip that had a `<hash>/` directory
beside it, whether or not that directory stood for the search. Under
`hpc_mode` the search directory is zipped and removed, and post-completion
caches (PyAutoLens' multiple-image positions, PyAutoGalaxy's adapt-image SNR
map) then write back into `paths._files_path`, which mkdirs on access. Each
writer called `preserve_in_zip`, which added the member to the archive but
left the loose file behind, so `<hash>/files/` reappeared holding two cache
artifacts and no `.completed`. The aggregator walked that directory instead
of the zip, `_is_search_output` accepted it (the preserved `files/search.json`
is the sentinel), and `completed_only` then dropped the search for having no
`.completed` — silently.

On the pulled euclid_dr1_prelim RAL job 342398 that cost 15 of 20 searches:
`Aggregator.from_directory(root, completed_only=True)` returned 5, the derived
`lens_mass.csv` carried 5 of 10 rows, and `build_inspection_bundle.sh` aborted
with "aggregator is empty". With this change the same tree returns 20.

- The zip is skipped only when its extracted sibling carries `.completed`.
  Otherwise the zip is extracted (merging onto the sibling in place, or into
  the temporary directory under `unzip_temporary`, where the shadowing sibling
  is dropped from the walk) and a warning names the path. The check moved
  ahead of the `unzip_temporary` branch before, so both modes had the hole.
- The summary print reports how many outputs `completed_only` excluded, so a
  run that aggregates a fraction of its searches no longer looks complete.
- `preserve_in_zip` deletes the loose file, and prunes the directories that
  emptied up to `output_path`, when `remove_files` is set — there the zip is
  the search's only store, so the loose copy is not a second home for the file
  but the directory that caused the shadowing.

Also fixes the search-output ordering, which is the cause of the five
`test_aggregate_csv` failures that reproduced locally while CI stayed green:
`scan` collected outputs in raw `os.walk` order, which is hash order on ext4
and insertion order on tmpfs, so the fixture searches came back `fit_2, fit_1`
here and `fit_1, fit_2` on CI. Everything that pairs a row to an output by
index — the summary CSV writers, `add_label_column` — paired them differently
per machine. The collected lists are now sorted by path before they are
returned (not `dirs` inside the walk, since the temporary extractions are
scanned separately). The full suite is green locally for the first time:
2567 passed, 2 skipped.

Fixes #1601

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CybZmqjyQRDpfK3Cs1JaW2
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 10, 2026
@Jammy2211
Jammy2211 merged commit e354dbb into main Sep 10, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/aggregator-sibling-dir-zip branch September 10, 2026 20:29
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 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.

fix(aggregator): prefer a .completed zip over an incomplete sibling dir; preserve_in_zip leaves no loose copy

1 participant