You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
index --prune: remove deleted photos nightly, only when every indexed folder is there - #37
Photos deleted from disk stayed in search until someone ran archivis prune by hand; the nightly index never removes anything. This adds index --prune and turns it on for the nightly job. Its safeguard: a run that can't vouch for having seen everything (an unmounted drive, an unreadable folder, a failed lookup) removes nothing.
Order of a --prune run
The index runs to completion (not stopped early), so moved and renamed photos already have their new paths.
The Photos and app-copy clean-ups run, moving hand-given face names and ratings off copies onto the photos they copy.
The prune removes the catalogue entries of files deleted from the folders the job indexes.
Auto-labelling runs, so deleted photos' faces aren't used as examples.
When it prunes nothing
The log then has error: not removing deleted photos, because this run may not have seen them all: with one line per reason. The next run that sees everything catches up. The reasons:
A folder the job names is missing, not a folder, empty (an unmounted drive's mount point) or unreadable (e.g. no Full Disk Access), either when the run starts or when it ends. One folder or several (as after a restart) both count. A folder that was not ready at the start blocks pruning even if it is ready by the end.
The run had gaps (Stats.Gaps):
a folder or file it could not read;
a file gone between being listed and being read;
a failed catalogue lookup, by path or by fingerprint;
a file that failed;
a move or photo it could not save;
a file under --min-bytes (so not indexed) that is a catalogued photo whose old file is gone, i.e. a move. Files skipped for size are small, so they are fingerprinted to check; icons that match nothing don't count.
The Photos or app-copy clean-up failed, so names and ratings were not moved off copies.
A missing copy that Photos or another photo app made is kept if it carries a hand-named face, a rating or a star: the clean-ups keep such copies when there is no original or twin to hand them to, so nothing else holds them. The log line says how many it kept, and a manual archivis prune still removes them.
Before a missing photo is removed, its hand-named faces, ratings and stars move to an identical catalogued photo whose file is still there, if any (matched by full-content fingerprint only; legacy edge-only fingerprints move nothing). This covers one copy of two deleted, and a photo moved and then catalogued afresh by index --force. It applies to archivis prune too, and both report what moved.
Prune's own protection still applies on top: a folder whose files are all gone, and that is itself gone or empty, is kept. On success, the log says pruned: removed N deleted photos from the catalogue, plus any folders kept that way.
Also
--prune with --force is refused: forced re-analysis doesn't recognise moved photos.
A folder to index that is itself a symbolic link is now walked; before, it was silently not indexed. Its photos keep the link's name. Links inside it are still not followed.
Left as designed, by the owner's decision: a photo moved into an excluded folder, or into a link to a folder inside an indexed folder is out of the run's view, like one moved out of the indexed folders, and its old record is pruned. A photo still at its catalogued path is never pruned.
Docs
DEPLOY.md:
the macOS index agent and the Ubuntu archivis-index.service get --prune, with an explanation;
a block turns it on for an existing macOS job (agents, or system services by swapping two comment marks);
a sed line does the same for Ubuntu.
README: mentions index --prune.
Tests (each fails without its fix)
TestPruneAfterIndex:
every folder present, and a folder that is a link: deleted files removed;
nothing removed, with the reason in the log, when:
one drive is gone, an empty mount point, or both drives are gone;
a folder was not there, or was empty, at the start but is there at the end;
a file is in place of a folder, or a link points to a missing folder;
the run had gaps;
a folder is unreadable (skipped as root).
TestPruneSparesLabelledCopies (store) and TestPruneAfterIndexSparesLabelledCopies: missing app copies with a name, rating or star are kept and reported; a plain copy and an ordinary rated photo are pruned; archivis prune removes them all.
TestPruneMovesLabelsToTwin (store): a removed photo's name, rating and star move to an identical photo still there; a face already named by hand keeps its name; nothing moves when every copy is missing, or in a dry run.
TestCleanUpBeforePrune: a deleted Photos copy's rating ends up on its original.
TestCleanUpFailureHoldsPrune: a failed clean-up stops the prune.
TestIndexRefusesForcePrune: --prune with --force is refused.
TestRunCountsGaps: an unreadable folder counts a gap; TestFailedBatchSavesTheRest now also expects one for an unsaved photo.
TestRunCountsSmallMoves: a catalogued small photo renamed counts a gap; an icon, or a small copy beside its original, doesn't.
TestRunWalksLinkedRoot: a linked folder is indexed, as given or with a trailing separator.
CI services (macOS) runs the new DEPLOY.md block as written (<!-- ci: prune-on -->):
first on the agent from step 7, which already has --prune and is unchanged;
then on a plist without it.
It checks for exactly one --prune, after index, and that the agent is loaded.
…en every folder is there
After a complete run (moved files already have their new paths), index
--prune removes the catalogue entries of files deleted from the folders it
indexes. It prunes nothing, and logs an error naming each folder, if any
folder to index was missing when the run started or is missing, empty or
unreadable at the end: an unmounted drive (or several, after a restart), an
empty mount point, or a library the service may not read. The next run
that finds every folder catches up. Prune's own check (folders whose files
are all gone and that are gone or empty are kept) still applies.
DEPLOY.md: the nightly job has --prune on macOS and Ubuntu, with a block to
turn it on for a job set up without it (run by the deploy job: already on,
then on a plist without it). README mentions it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
Adds opt-in index --prune and enables it in documented nightly jobs to remove deleted photos from the catalogue, with folder-availability safeguards intended to protect offline drives.
Changes:
Adds post-index pruning with folder checks and diagnostic logging.
Documents the flag and upgrade steps for existing macOS and Ubuntu jobs.
Adds pruning safety tests and macOS deployment-script checks.
File
Description
README.md
Introduces index --prune and its usage.
DEPLOY.md
Enables nightly pruning and documents upgrade commands.
cmd/archivis/prune.go
Implements folder checks and post-index pruning.
cmd/archivis/prune_test.go
Tests successful pruning and unavailable-folder safeguards.
cmd/archivis/main.go
Registers the flag, tracks skipped roots, and invokes pruning.
.github/workflows/ci.yml
Checks the macOS upgrade block with and without an existing flag.
…hat saw everything
From Copilot's review of #37:
- Pruning now follows CleanPhotosLibraries and CleanAppCaches (one helper,
cleanUpAfterIndex), so a copy whose file is gone, among others still
there, hands its names and ratings to its original before it is removed.
- The indexer counts gaps (Stats.Gaps): folders and files it could not
read, failed files, and moves or photos it could not save. A run with
gaps prunes nothing: a photo moved where it could not look still has its
old path.
- Every folder is checked as indexing starts as well as at the end: one
missing, empty (an unmounted mount point), not a folder or unreadable at
the start holds off pruning even if it is ready by the end.
Tests: TestCleanUpBeforePrune, TestRunCountsGaps, new TestPruneAfterIndex
cases; each fails without its fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical pruning paths risk losing photo records, labels, and ratings after cleanup failures, with unscanned symlink roots, or when --force bypasses move recognition.
…ter a failed clean-up
From Copilot's second review of #37:
- --force analyses moved photos as new, leaving their old records to be
pruned with their names and ratings: --prune and --force are refused
together, before anything is opened.
- The indexer doesn't walk a folder that is a symbolic link (WalkDir does
not follow a root link, and Abs drops a trailing separator), so
folderProblem checks the cleaned path with Lstat and reports a link.
- A failed Photos or app-copy clean-up leaves names and ratings on copies;
pruning then waits, listing the failure with its other reasons.
Tests: TestIndexRefusesForcePrune, TestCleanUpFailureHoldsPrune, and two
symlink cases in TestPruneAfterIndex; each fails without its fix.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Critical unresolved issues leave pruning unsafe when exclusions, skipped symlinks, catalogue or fingerprint lookup failures, filesystem races, and Windows-incompatible tests can bypass gap detection or compilation.
No open issues 🎉
7 previously missed issues
In code that hasn't changed since last review
Exclude patterns leave unseen subtrees vulnerable to pruning
cmd/archivis/main.go:422
When --exclude is supplied, the walk intentionally skips matching paths, but this still enables pruning for the entire root. A previously catalogued photo under an excluded directory can be missing while that directory remains nonempty; with zero Gaps, Store.Prune will delete it even though this run never inspected that subtree (and a move there is likewise invisible). Reject --prune with exclusions or carry the excluded subtrees into the prune safety check.
Move lookup failures are ignored by the prune safety check
cmd/archivis/main.go:422
Stats.Gaps does not cover catalogue-read failures during move recognition: Lookup/ByFingerprint errors are ignored and the file is then saved as a new record. If the old path is gone, the subsequent prune removes that old record even though this run failed to determine that it was a move. Count these lookup/reuse errors as gaps (or abort pruning when they occur).
Skipped directory symlinks can make pruning delete unseen records
cmd/archivis/prune.go:65
The final readiness check only examines the named root, but filepath.WalkDir also silently skips directory symlinks below that root. Such a symlink does not add a gap, so moving a photo into it leaves the old path unseen while this check passes and st.Prune can delete the old record and its metadata. Treat skipped directory symlinks as a gap or otherwise exclude their subtrees from pruning.
Unix-only os.Geteuid call breaks Windows test compilation
cmd/archivis/prune_test.go:121
os.Geteuid is not available in the Windows os package, so this new test file will fail to compile on the repository's windows-latest CI job; the runtime.GOOS short-circuit cannot prevent compile-time symbol resolution. Use a platform-neutral permission probe or a build-tagged helper instead of calling the Unix-only API here.
Unix-only os.Geteuid call breaks Windows test compilation
internal/indexer/analyze_test.go:381
os.Geteuid is not available in the Windows os package, so this new test file will fail to compile on the repository's windows-latest CI job; the runtime.GOOS short-circuit cannot prevent compile-time symbol resolution. Use a platform-neutral permission probe or a build-tagged helper instead of calling the Unix-only API here.
Fingerprint lookup failures can let pruning delete moved records
internal/indexer/indexer.go:49
Gaps is used here as proof that move recognition was reliable, but Indexer.process silently falls back to analysing a file when ByFingerprint fails (reuse returns false on that error). If that read error is transient and the new result saves successfully, a moved photo is recorded under its new path while the old row remains; pruning then removes the old row and its labels/ratings despite Gaps == 0. Surface fingerprint-lookup failures as gaps before allowing automatic pruning.
Post-listing file disappearance should block pruning
internal/indexer/indexer.go:191
A file can be renamed after WalkDir has listed the old path but after the destination was traversed, so d.Info() returns ENOENT here even though the photo still exists at an unvisited path. Treating that as no gap lets the run pass the prune gate and Store.Prune then deletes the old catalogue row (and its labels/ratings). The indexer cannot distinguish this race from a deletion; count this post-listing disappearance as a gap so pruning is deferred to the next run.
…id-run as gaps
- A folder to index that is a symbolic link was never walked: WalkDir does
not follow a root link, and Abs drops the trailing separator that would
make it. The walk now names such a folder with a separator, so it is
indexed with its photos under the link's name (links inside it are still
not followed). folderProblem judges a link by the folder it points to.
- For index --prune, more of what a run can't vouch for counts as a gap: a
failed catalogue lookup (by path, or for earlier copies by fingerprint,
where a moved photo would be analysed as new), and a file gone between
listing and reading (deleted, or renamed into a folder already walked).
From Copilot's review of f8a5436. Test: TestRunWalksLinkedRoot (fails
without the fix); TestPruneAfterIndex's link cases updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
Move lookup failures (main.go:422) and fingerprint lookup failures (indexer.go:49): real. A failed Lookup, or a failed ByFingerprint in reuse, now logs a warning and counts a gap. A photo whose move couldn't be recognised therefore holds off pruning. I haven't written a test for these two error paths: the store can't be made to fail a read on demand without a test hook.
A file gone between listing and reading (indexer.go:191): real. It can't be told apart from a rename into a folder already walked, so it now counts a gap rather than being skipped as deleted. At worst it holds pruning off for one night.
Also in this commit, at the user's request: a folder to index that is itself a symbolic link is now walked. Before, it was silently not indexed, because WalkDir doesn't follow a root link and Abs drops the trailing separator that would make it. Its photos keep the link's name, so prune finds them under the same folder. folderProblem now judges a link by the folder it points to: a link to an unmounted drive is "not there". Test: TestRunWalksLinkedRoot (fails without the fix), plus the updated link cases in TestPruneAfterIndex.
Not real
os.Geteuid breaks Windows compilation (prune_test.go:121, analyze_test.go:381): os.Geteuid exists on every platform; on Windows it returns -1 (see the os package docs). test (windows-latest) compiled and passed these test files on b6f90b7 and f8a5436.
By design: left for the user to decide
Exclude patterns (main.go:422) and links to folders inside a folder (prune.go:65): the run doesn't look in either. A photo moved into one disappears from the run just as a photo moved out of the indexed folders altogether does (to the Desktop, say), and pruning drops its old record in both cases. A photo that is still where it was catalogued, under an excluded path or not, is never pruned: Prune only removes paths that Lstat reports as not existing.
Treating these as gaps would stop pruning for good on any tree with an exclusion or an inner link. Refusing --prune with --exclude would do the same for those jobs. I've asked the user which they want.
The user has decided: exclusions and links to folders inside an indexed folder stay as they are. A photo moved into one is treated like a photo moved out of the indexed folders, and pruning keeps running.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical indexing bug still allows photos under nested directory symlinks to remain unseen while automatic pruning deletes their existing catalogue entries.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical pruning-safety issue remains because skipped image candidates can leave a gap-free run that deletes valid catalogue entries, and two documentation inconsistencies also need correction.
…olds pruning off
A file under --min-bytes isn't indexed, so a photo catalogued with a lower
--min-bytes and then renamed would have its old record pruned. Files
skipped for their size are now fingerprinted (they are small) and looked
up: one that matches a catalogued photo whose file is gone counts a gap,
with a warning naming it. Small files that match nothing (icons, tiny
thumbnails) don't hold pruning off.
The owner's call on Copilot's finding in #37. Test: TestRunCountsSmallMoves
(fails without the check).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because pruning can delete retained copies or stale rows despite failed indexing or incomplete cleanup, risking loss of labels and ratings.
…s or stars
The clean-ups keep a Photos or app copy when it has no catalogued
original or twin to hand its names and ratings to. If its file goes
(usually a deleted photo, but Photos can also drop a preview), pruning it
would lose them. The nightly prune (Store.PruneSparingCopies) now keeps
such a copy when it carries a hand-named face, a rating or a star, and
says how many it kept; archivis prune still removes them.
The owner's decision on Copilot's review of 0c6cd9a. Tests:
TestPruneSparesLabelledCopies, TestPruneAfterIndexSparesLabelledCopies
(both fail without it).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
On review 5807163189 (on 0c6cd9a), which has no threads, only the summary: "pruning can delete retained copies … despite … incomplete cleanup, risking loss of labels and ratings."
The real risk is this. The clean-ups deliberately keep a Photos or app copy when there is no catalogued original or twin to hand its names and ratings to. If that copy's file goes, pruning removes the row and the names and ratings with it. Usually the photo was deleted, but Photos can also drop or regenerate a preview while the photo is still there.
The owner decided: the nightly prune spares such copies. Done in 8ee7311:
Store.PruneSparingCopies keeps a missing path inside a photo app's library or cache (InAppCache) when it carries a hand-named face, a rating or a star.
The pruned: line reports how many it kept.
archivis prune by hand still removes them.
Tests: TestPruneSparesLabelledCopies and TestPruneAfterIndexSparesLabelledCopies, both of which fail without the change. DEPLOY.md and the description are updated.
The other half of the summary ("despite failed indexing or incomplete cleanup") was already handled: a run with gaps, or with a failed clean-up, prunes nothing (b6f90b7, f8a5436, 9c042b6, 0c6cd9a).
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because interactions between move detection, forced reanalysis, and pruning can silently delete photos’ names, ratings, and stars.
…l photo still there
Before removing a missing photo, prune (nightly or by hand) looks for an
identical catalogued photo (same fingerprint) whose file is still there,
and moves the removed photo's hand-named faces (with the clean-ups'
moveManualLabels: never over a face already named by hand), ratings and
stars onto it. This covers one copy of two deleted, and a photo moved and
then catalogued afresh by index --force, whose old record held the labels.
Both prune paths report what moved.
The owner's decision on Copilot's review of 8ee7311. Test:
TestPruneMovesLabelsToTwin (fails without it).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
On review 5807698376 (on 8ee7311), which has no threads, only a summary: "interactions between move detection, forced reanalysis, and pruning can silently delete photos' names, ratings, and stars."
The path behind it:
A photo is moved.
archivis index --force is run by hand. It re-analyses without recognising moves, so a new record appears at the new path with none of the labels.
The old record keeps the hand-named faces, ratings and stars.
The next prune, nightly or by hand, removes the old record, and the labels go with it.
Deleting one copy of two identical photos loses its labels the same way. (--prune together with --force is already refused, since f8a5436.)
The owner decided: before removing a missing photo, prune hands its labels to an identical catalogued photo still there. Done in d796b10:
moveToTwin looks up the same fingerprint, finds a photo whose file exists and isn't being pruned, and moves:
hand-named faces, with the clean-ups' moveManualLabels, never over a face already named by hand;
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two critical issues remain in twin metadata transfer: legacy partial fingerprints can misattribute metadata, and non-missing-row database errors can cause metadata loss.
… lookup error
From Copilot's review of d796b10:
- A legacy fingerprint (24 hex digits: size and the first and last
64 KiB) can be shared by different photos, and the deleted file can't be
compared, so moveToTwin now moves labels only on a full-content one (32).
- A failed lookup other than sql.ErrNoRows is returned, so the prune rolls
back instead of deleting a photo whose labels weren't moved.
Test: a legacy-fingerprint case in TestPruneMovesLabelsToTwin (fails
without the check).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because the change contains correctness-sensitive pruning and indexing edge cases that could cause metadata loss or remove catalogued files despite incomplete indexing.
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
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.
Photos deleted from disk stayed in search until someone ran
archivis pruneby hand; the nightly index never removes anything. This addsindex --pruneand turns it on for the nightly job. Its safeguard: a run that can't vouch for having seen everything (an unmounted drive, an unreadable folder, a failed lookup) removes nothing.Order of a
--prunerunWhen it prunes nothing
The log then has
error: not removing deleted photos, because this run may not have seen them all:with one line per reason. The next run that sees everything catches up. The reasons:Stats.Gaps):--min-bytes(so not indexed) that is a catalogued photo whose old file is gone, i.e. a move. Files skipped for size are small, so they are fingerprinted to check; icons that match nothing don't count.A missing copy that Photos or another photo app made is kept if it carries a hand-named face, a rating or a star: the clean-ups keep such copies when there is no original or twin to hand them to, so nothing else holds them. The log line says how many it kept, and a manual
archivis prunestill removes them.Before a missing photo is removed, its hand-named faces, ratings and stars move to an identical catalogued photo whose file is still there, if any (matched by full-content fingerprint only; legacy edge-only fingerprints move nothing). This covers one copy of two deleted, and a photo moved and then catalogued afresh by
index --force. It applies toarchivis prunetoo, and both report what moved.Prune's own protection still applies on top: a folder whose files are all gone, and that is itself gone or empty, is kept. On success, the log says
pruned: removed N deleted photos from the catalogue, plus any folders kept that way.Also
--prunewith--forceis refused: forced re-analysis doesn't recognise moved photos.Docs
archivis-index.serviceget--prune, with an explanation;sedline does the same for Ubuntu.index --prune.Tests (each fails without its fix)
TestPruneAfterIndex:TestPruneSparesLabelledCopies(store) andTestPruneAfterIndexSparesLabelledCopies: missing app copies with a name, rating or star are kept and reported; a plain copy and an ordinary rated photo are pruned;archivis pruneremoves them all.TestPruneMovesLabelsToTwin(store): a removed photo's name, rating and star move to an identical photo still there; a face already named by hand keeps its name; nothing moves when every copy is missing, or in a dry run.TestCleanUpBeforePrune: a deleted Photos copy's rating ends up on its original.TestCleanUpFailureHoldsPrune: a failed clean-up stops the prune.TestIndexRefusesForcePrune:--prunewith--forceis refused.TestRunCountsGaps: an unreadable folder counts a gap;TestFailedBatchSavesTheRestnow also expects one for an unsaved photo.TestRunCountsSmallMoves: a catalogued small photo renamed counts a gap; an icon, or a small copy beside its original, doesn't.TestRunWalksLinkedRoot: a linked folder is indexed, as given or with a trailing separator.CI
services (macOS)runs the new DEPLOY.md block as written (<!-- ci: prune-on -->):--pruneand is unchanged;It checks for exactly one
--prune, afterindex, and that the agent is loaded.https://claude.ai/code/session_01WwontTm7iEMh1uyZbQbJ9d
Generated by Claude Code