Repository navigation
fix(aggregator): prefer a .completed zip over an incomplete sibling dir; preserve_in_zip leaves no loose copy - #1602
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aggregator.from_directoryskipped any zip that had a<hash>/directory beside it, whether or not that directory stood for the search. Underhpc_modethe search directory is zipped and removed, and post-completion caches (PyAutoLens' multiple-image positions, PyAutoGalaxy's adapt-image SNR map) then write back intopaths._files_path, which mkdirs on access. Each writer calledpreserve_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_outputaccepted it (the preservedfiles/search.jsonis the sentinel), andcompleted_onlythen dropped the search for having no.completed— silently.On the pulled
euclid_dr1_prelimRAL job 342398 that cost 15 of 20 searches:Aggregator.from_directory(root, completed_only=True)returned 5, the derivedlens_mass.csvcarried 5 of 10 rows, andbuild_inspection_bundle.shaborted with "aggregator is empty". With this branch the same tree returns 20.Three changes:
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 underunzip_temporary, where the shadowing sibling is dropped from the walk so it cannot yield the search twice) and alogger.warningnames the path. The old check sat ahead of theunzip_temporarybranch, so both modes had the hole. The summary print now also reports how many outputscompleted_onlyexcluded, so a run that aggregates a fraction of its searches no longer looks complete.autofit/non_linear/paths/abstract.py—preserve_in_zipdeletes the loose file, and prunes the directories that emptied up to and includingoutput_path, whenremove_filesis 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. Withremove_filesunset the output directory is the primary store and the loose copy stays.test_aggregate_csvfailures that reproduced locally while CI stayed green (filed asbug/autofit/aggregate_csv_tests_fail_locally_pass_in_ci.md, hypothesised there as an environment difference; it is a library bug).scancollected outputs in rawos.walkorder, which is hash order on ext4 and insertion order on tmpfs, so the fixture searches came backfit_2, fit_1locally andfit_1, fit_2on 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, notdirsinside the walk, because the temporary extractions are scanned separately and never pass through that walk).API Changes
Aggregator.from_directorynow 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_directoryno longer treats an extracted directory beside a zip as authoritative unless it carries.completed; such a directory is now overwritten in place (or bypassed underunzip_temporary), and a warning is logged.AbstractPaths.preserve_in_zipnow removes the loose file it preserved, and any directory it emptied, whenremove_filesis 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 autohas a pre-existing xdist collection mismatch intest_prior_properties.py) — 2567 passed, 2 skipped, 0 failed. Onmainin the same worktree this is5 failed, 2557 passed, 2 skipped; the five failures are thetest_aggregate_csvordering bug fixed here, and they also reproduce on the canonicalmaincheckout.euclid_dr1_prelim342398 tree —Aggregator.from_directory(".../dr1_prelim_grade_ab", completed_only=True, unzip_temporary=True)returns 20 on this branch and 5 onmain. 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.completedloses to the zip in both modes andcompleted_only=Truestill returns 1.test_zip_not_re_extracted/test_zip_temporary_uses_an_existing_extracted_directory— rewritten to the new contract: a sibling with.completedstill wins and the directory on disk is not overwritten.test_search_outputs_are_sorted_by_path—os.walkmonkeypatched 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 tworemove_filessettings.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:91euclid_strong_lens_modeling_pipeline/catalogue/scripts/{lens_mass,lens_sersic,source_sersic,magnitudes,deblending,multi_wavelength}.pyThey pick up the fix without an edit —
csv_make.pyand 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>.zipis only preferred over the zip when it contains a.completedfile. Without one, the zip is extracted (over the directory in place, or into the temporary directory underunzip_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 bycompleted_only.autofit.non_linear.paths.abstract.AbstractPaths.preserve_in_zip(file_path)— underremove_filesthe loose file is deleted once it is a member of the zip, along with any parent directory the deletion emptied, up to and includingoutput_path. Unchanged whenremove_filesis unset.Added
autofit.non_linear.paths.abstract.AbstractPaths._remove_preserved_copy(file_path)— private helper for the above.Removed / Renamed / Changed Signature
Migration
preserve_in_zipand then read the file back from disk underremove_filesmust read the zip member instead, or recompute. The two known callers (PyAutoLensResult._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