Repository navigation
Description
Overview
Aggregator.from_directory(root, completed_only=True) silently returned 5 of 20 searches on the pulled euclid_dr1_prelim RAL job 342398: lens_mass.csv came out with 5 of 10 rows and build_inspection_bundle.sh aborted with "aggregator is empty". The cause is a <hash>/ directory recreated beside a completed <hash>.zip by post-completion cache writes — it holds only the cached artifacts and no .completed, and the aggregator prefers it over the zip unconditionally. The same write path also leaves a loose copy of every preserved file outside the zip even when remove_files is set, which is what recreates the shadowing directory in the first place.
Plan
- Make
Aggregator.from_directoryskip a zip only when its extracted sibling actually carries.completed; otherwise extract the zip (merging in place, or to the temporary path underunzip_temporary) and warn, naming the path. - Surface the shortfall: report how many outputs
completed_onlydropped in the aggregator's summary print, so a silent 5-of-20 becomes visible. - Make
preserve_in_ziphonourremove_files: once the member is in the archive, delete the loose file and prune the directories that emptied, so the zip really is the only store. - Rewrite the two tests that lock in the unconditional skip to the new contract, and add a
preserve_in_ziptest covering bothremove_filessettings. - File a follow-up so the two post-completion cache readers read the preserved zip member instead of recomputing once the loose copy is gone.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary; sole repo edited)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
worktree_check_conflict aggregator-sibling-dir-zip PyAutoFit exits 1: PyAutoFit is claimed by the live task start-here-mode (worktree ~/Code/PyAutoLabs-wt/start-here-mode, branch feature/start-here-mode). That task's PyAutoFit diff is documentation only (docs/overview/natural_language.md, docs/overview/quick_start.md); this task edits autofit/aggregator/aggregator.py, autofit/non_linear/paths/abstract.py and two test modules. The file sets are disjoint, so this task takes its own worktree and own branch rather than serialising or folding, recorded as a parallel-claim: block on the active.md entry.
Suggested branch: feature/aggregator-sibling-dir-zip
Worktree root: ~/Code/PyAutoLabs-wt/aggregator-sibling-dir-zip/
Work classification: Library
Root cause
After a search is zipped and its output directory removed under hpc_mode (autofit/non_linear/paths/abstract.py:181-187 forces remove_files whenever general.hpc.hpc_mode is set), post-completion caches write back into paths._files_path: PyAutoLens Result._cached_multiple_image_positions_from (autolens/analysis/result.py:299-323) and the PyAutoGalaxy adapt-image SNR cache (autogalaxy/analysis/adapt_images/adapt_images.py:14-27,134-135). _files_path mkdirs on access (abstract.py:352-358), so a <hash>/files/ tree reappears beside the zip. The writers then call paths.preserve_in_zip(path) (abstract.py:383-423), which adds or replaces the archive member but leaves the loose file in place — correct under remove_files=False, wrong under remove_files=True.
Aggregator.from_directory (autofit/aggregator/aggregator.py:239-266) then skips any zip whose <hash>/ sibling exists (:243-245). That check sits before the unzip_temporary branch, so temporary-extraction mode has the same hole. The walk descends into the sibling, _is_search_output accepts it because files/search.json is present (:101-113 — itself a preserved member), and completed_only drops it for lacking .completed (:261-262), with nothing printed.
Implementation Steps
autofit/aggregator/aggregator.py:243-245— replace the unconditionalif extracted.exists(): continuewith a skip only when(extracted / ".completed").exists(). Otherwise extract: in place,extractallonto the existing directory (which merges; the zip's copies are authoritative); underextract_temporary, to the temporary path as today. Emitlogger.warningnaming the path — a sibling directory without.completedbeside a completed zip, and that the zip was used.autofit/aggregator/aggregator.py:320-325— count the outputscompleted_onlydropped and include it in the summary print.autofit/non_linear/paths/abstract.py:383-423(preserve_in_zip) — after the member is written or replaced, ifself.remove_filesdelete the loose file and prune now-empty parent directories up to and includingoutput_path. Docstring records that underremove_filesthe zip is the only store and post-completion caches are recomputed on next access.test_autofit/aggregator/test_from_directory.py— rewritetest_zip_not_re_extracted(:42-49) andtest_zip_temporary_uses_an_existing_extracted_directory(:110-116) to the new contract: a sibling with.completedstill wins and the zip is not re-extracted; a sibling without.completedloses to the zip in both modes andcompleted_only=Truereturns 1.test_autofit/non_linear/paths/test_paths.py(besidetest__preserve_in_zip__file_survives_restore,:120) — assert that underremove_files=Trueno loose file and no emptied directory remain afterpreserve_in_zip, and that the loose file does remain underremove_files=False.- Follow-up prompt filed at
PyAutoMind/draft/refactor/autolens/cache_readers_fall_back_to_zip_member.md(small, supervised; PyAutoLens + PyAutoGalaxy + PyAutoFit): the two cache readers should read the preserved zip member when the loose file is absent instead of recomputing — today one SNR-image set plus one point solve per stage boundary.
Key Files
autofit/aggregator/aggregator.py— the zip/sibling precedence and the summary print.autofit/non_linear/paths/abstract.py—preserve_in_zip,_files_path, thehpc_mode→remove_filesforcing.test_autofit/aggregator/test_from_directory.py— the two tests that lock in the current skip.test_autofit/non_linear/paths/test_paths.py—preserve_in_zipcoverage.
Witness
An aggregator over <hash>.zip (containing .completed) plus a sibling <hash>/files/x.json with no .completed returns 1 output under completed_only=True in both in-place and unzip_temporary=True modes; after preserve_in_zip under remove_files=True no file remains outside the zip; Aggregator.from_directory over the pulled euclid_dr1_prelim 342398 tree returns 20 outputs (today 5).
Original Prompt
Click to expand starting prompt
Aggregator prefers an incomplete sibling directory over a .completed zip, and preserve_in_zip leaves a loose copy under remove_files
Type: bug
Target: PyAutoFit
Repos:
- PyAutoFit
Themes: - aggregator
- paths
Difficulty: medium
Autonomy: safe
Priority: high
Status: formalised
Consequence: judge
Witness: an aggregator over<hash>.zip(containing.completed) plus a sibling<hash>/files/x.jsonwith no.completedreturns 1 output undercompleted_only=Truein both in-place andunzip_temporary=Truemodes; afterpreserve_in_zipunderremove_files=Trueno file remains outside the zip;Aggregator.from_directoryover the pulled euclid_dr1_prelim 342398 tree returns 20 outputs (today 5).
Review-minutes: 20
Unattended: ready
Filed: 2026-09-10
Symptom
Found 2026-09-10 on the euclid_dr1_prelim RAL job 342398. Aggregator.from_directory(root, completed_only=True)
returned 5 of the 20 searches present in the pulled output tree; the derived
lens_mass.csv carried 5 of 10 rows, and build_inspection_bundle.sh aborted
with "aggregator is empty". Nothing was printed to warn that fifteen completed
searches had been silently dropped.
Every dropped search had a <hash>/ directory sitting beside its <hash>.zip.
That directory held only two files — files/galaxy_images_snr.fits and
files/multiple_image_positions.json — whose mtimes matched the zip's, and both
of which were also members of the zip. Crucially the directory contained no
.completed marker, while the zip did.
Root cause (verified)
After a search is zipped and its output directory removed under hpc_mode
(@PyAutoFit/autofit/non_linear/paths/abstract.py:181-187 forces remove_files
whenever general.hpc.hpc_mode is set), post-completion caches write back into
paths._files_path:
- PyAutoLens
Result._cached_multiple_image_positions_from
(@PyAutoLens/autolens/analysis/result.py:299-323) - the PyAutoGalaxy adapt-image SNR cache
(@PyAutoGalaxy/autogalaxy/analysis/adapt_images/adapt_images.py:14-27,134-135)
The _files_path property mkdirs the directory on access
(@PyAutoFit/autofit/non_linear/paths/abstract.py:352-358), so a <hash>/files/
tree is recreated beside the zip. The writers then call
paths.preserve_in_zip(path)
(@PyAutoFit/autofit/non_linear/paths/abstract.py:383-423), which adds or
replaces the archive member but leaves the loose file exactly where it was —
correct under remove_files=False, wrong under remove_files=True, where the
zip is meant to be the only store.
Aggregator.from_directory
(@PyAutoFit/autofit/aggregator/aggregator.py:239-266) then skips any zip whose
<hash>/ sibling already exists (:243-245). That check sits before the
unzip_temporary branch, so temporary-extraction mode has the same hole. The
walk descends into the sibling, _is_search_output accepts it because
files/search.json is present (:101-113 — the sentinel is also a preserved
zip member), and completed_only then drops it for lacking .completed
(:261-262). No warning is printed anywhere along that path.
test_autofit/aggregator/test_from_directory.py::test_zip_not_re_extracted
(:42-49) currently locks in the unconditional skip, and
test_zip_temporary_uses_an_existing_extracted_directory (:110-116) is its
temporary-mode twin.
What to do
-
aggregator.py:243-245— skip the zip only when
(extracted / ".completed").exists(). Otherwise extract the zip: in place,
extractallonto the existing directory (which merges, and the zip's copies
are authoritative); in temporary mode, to the temporary path as today. Emit a
logger.warningnaming the path — a sibling directory without.completed
beside a completed zip, and that the zip was used. Add a count of outputs
dropped bycompleted_onlyto the summary print at :320-325 so a silent
shortfall becomes visible. -
preserve_in_zip— after the member is written or replaced, if
self.remove_filesis true delete the loose file and prune now-empty parent
directories up to and includingoutput_path. State in the docstring that
underremove_filesthe zip is the only store, and that post-completion
caches are recomputed on next access. -
Tests — rewrite
test_zip_not_re_extractedand its temporary-mode twin
to the new contract: a sibling with.completedstill wins and the zip is
not re-extracted; a sibling without.completedloses to the zip in both
modes, andcompleted_only=Truereturns 1. Add apreserve_in_ziptest
besidetest__preserve_in_zip__file_survives_restore
(@PyAutoFit/test_autofit/non_linear/paths/test_paths.py:120) asserting that
underremove_files=Trueno loose file and no empty directory remain, and
that the loose file does remain underremove_files=False. -
Follow-up prompt — file
PyAutoMind/draft/refactor/autolens/cache_readers_fall_back_to_zip_member.md
(small, supervised; Repos: PyAutoLens, PyAutoGalaxy, PyAutoFit): the two
cache readers should read the preserved zip member when the loose file is
absent rather than recomputing it. Today that costs one SNR-image set plus
one point solve per stage boundary.
Activity
Jammy2211 commentedon Sep 10, 2026
Library PR Created — #1602 (
pending-release)Branch
feature/aggregator-sibling-dir-zip, commitd6fa9cdc8.Witness met.
Aggregator.from_directory(".../euclid_dr1_prelim/output/dr1_prelim_grade_ab", completed_only=True, unzip_temporary=True)returns 20 on the branch and 5 onmain. Fifteen warnings are logged, one per shadowed search; the science tree is untouched.Tests.
pytest test_autofit -q -p no:cacheprovider(serial) — 2567 passed, 2 skipped, 0 failed. Onmainin the same worktree:5 failed, 2557 passed, 2 skipped.A third fix, beyond the plan. Those five
test_aggregate_csvfailures are a genuine library bug, not the environment difference hypothesised inbug/autofit/aggregate_csv_tests_fail_locally_pass_in_ci.md.scancollected outputs in rawos.walkorder — hash order on ext4, insertion order on tmpfs — so the fixture searches came backfit_2, fit_1locally andfit_1, fit_2on CI, and 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, with a regression test that monkeypatchesos.walkto reverse its entries. That prompt can be closed against this PR.Downstream workspace impact: none. Every 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:91andcatalogue/scripts/{lens_mass,lens_sersic,source_sersic,magnitudes,deblending,multi_wavelength}.py. They pick the fix up without an edit.Follow-up filed.
PyAutoMind/draft/refactor/autolens/cache_readers_fall_back_to_zip_member.md— the two post-completion cache readers should read the preserved zip member instead of recomputing now that the loose copy is gone.Heart: YELLOW, no RED. Four reasons, all organism-scope and none touched by this branch (workspace validation not passing, three profiling-drift rows) — the same set acknowledged in-session earlier today for
a100-pixelized-baseline.Next: CI, then
/prm 1602.Jammy2211 commentedon Sep 10, 2026
Shipped
PyAutoFit#1602 merged — #1602 (merge
e354dbb6).Aggregator.from_directorynow prefers a<hash>.zipcarrying.completedover an incomplete<hash>/sibling, warns when it does, and reports thecompleted_onlydrop count.preserve_in_zipremoves the loose copy and prunes empty directories underremove_files, so nothing is left outside the zip.test_aggregate_csvfailures that reproduced locally while CI stayed green.Witness met: the pulled euclid_dr1_prelim 342398 tree aggregates 20 outputs (5 on
main). CI green on docs-build, unittest 3.12, unittest 3.13, unittest-nojax.Pending release: the fix is on
mainbut not yet in a published PyAutoFit.Follow-up filed:
draft/refactor/autolens/cache_readers_fall_back_to_zip_member.md(the post-completion caches in PyAutoLensResult._cached_multiple_image_positions_fromand the PyAutoGalaxy adapt-image SNR cache write throughpaths._files_path, whose property mkdirs beside the zip — the sibling dirs this fix now tolerates).