The export on the disk
Sluice sorts photos into year and month folders, and to do that it believes what each file says about itself. A photo’s name tells Sluice which file holds its date. Its size tells Sluice whether it’s a real photo or something small to set aside. Its date decides the folder.
Each of those three was wrong somewhere in real files. The costliest cases didn’t turn up by thinking about the file formats, but by counting real files or comparing against an older version.
An AI agent wrote Sluice’s code, a separate review agent read each change, and I signed off every commit. Sluice started out as a set of PowerShell scripts and was later rewritten as a desktop app, and that rewrite matters for the dates.
Names: 773 files at exactly 46 characters
Google Takeout is Google’s export of a photo library. It doesn’t keep a photo’s date inside the photo. Takeout writes the date to a small JSON file beside the photo, called a sidecar, named after the photo:
IMG_1234.jpg
IMG_1234.jpg.supplemental-metadata.json
Sluice reads the date from the sidecar. Once the photo is sorted, the sidecar has done its job, and a sweep deletes the ones nothing needs anymore. A sidecar stays while its photo is still in the Inbox, the folder new photos land in.
Long names make that harder. Takeout cuts a long sidecar name short, and the cut usually takes the photo’s file extension with it:
Screenshot_2019-07-04-14-22-33-123_com.android.chrome.jpg
Screenshot_2019-07-04-14-22-33-123_com.android.json
The cut name no longer spells its photo’s name, so the sweep matches it by prefix instead, looking
for a photo whose name starts with it. On short names a shared start is coincidence, so in July the
sweep got a rule. It trusts that match only from 46 characters up, because 46 is where Takeout cuts.
Google doesn’t document that anywhere. The figure came from people who studied its exports, in an
issue on GooglePhotosTakeoutHelper,
an open-source tool for fixing Takeout exports. They found sidecar names cut to 51 characters with
the .json kept, which leaves 46 for the rest. Sluice never reads a date through
a cut name, by the way. A photo like this one takes its date from the EXIF data inside it.
At the end of July the sweep was rebuilt, and it gained a second check on what it may delete at all.
A JSON file only counts as a sidecar if a photo’s file extension, like .jpg, appears in its name.
That keeps an album’s metadata.json safe.
During that rebuild the agent deleted the 46-character rule. It argued that the new check covered cut names better. It also argued that no real Takeout export cut names as long as 46 characters anyway. Both arguments went into the summary it wrote for me to review. The Takeout export sitting on the same machine hadn’t been opened.
Then, before a test run on real files, the export got counted. It held 14,789 sidecars, 773 of them with a cut name. Every one was exactly 46 characters long, with a photo beside it whose name started with the cut. The community figure held to the character.
So a cut name wasn’t an edge case. With its .jpg cut off, it failed the new check, and its length
was the only thing left marking it as a sidecar. Without the 46-character rule, the sweep couldn’t
recognise any of the 773, and it would have left them in the Inbox for good. That’s clutter rather
than damage, since the sweep deletes JSON files and never photos.
The rule came back with two jobs instead of one. A name of 46 characters or more counts as a sidecar even with its extension gone. And a cut sidecar still belongs to any photo whose name starts with it, from 46 characters up, as before. The deletion never reached a commit.
Afterwards, the agent’s note on it read “an empirical claim about a third-party format is cheap to check when the format is on disk. Assert it after looking, not before.”
Sizes: the photo that reported one tile
Sluice sets images under 640 pixels on the long side aside in a review folder, to decide on later. Everything else goes on toward the library, the folders kept photos end up in. To check the size, Sluice reads it from the metadata stored in the file, which is much faster than decoding every pixel. In under three weeks, that reading turned out wrong in five different ways.
- An iPhone photo is 4032 by 3024. The HEIF part of the file reports a width and height too. What Sluice’s metadata reader found there was 512 by 512, one of the tiles Apple splits the photo into.
- Some Android photos had their size tags present but holding 0. The reader returned exactly that, and Sluice took it as a photo 0 pixels wide. In a test run on copies of real photos, 42 of the 47 photos in one album went to review as too small. They were full-resolution 16-megapixel shots.
- A TIFF holding several images hands them over in storage order, and nothing Sluice read said which one was the photo. Taking the first could mean taking a smaller image’s size.
- A Nikon raw file has more than one block of EXIF data, and the first one has no size in it.
- Reading the EXIF size fixed the iPhone case, until a photo’s EXIF had been stripped. Then only the HEIF tag was left, and Sluice took its 512 by 512 again.
The iPhone, Android and Nikon cases came from real files. The TIFF came from a test file built for it, and the stripped EXIF from a review of what the code claimed to do.
Each fix made Sluice trust a single tag less. For the TIFF and the Nikon file, it now looks at every image and every block of EXIF data and takes the largest size. A size of 0 counts as missing. For the iPhone, it reads the EXIF size tag by its exact name and takes the larger of that and the HEIF tag. And whenever the metadata says under 640, Sluice also decodes the pixels and takes the larger of the two answers. Above 640 the exact number changes nothing, so nearly every photo still takes the fast path.
Dates: the old version was wrong
The new version was checked against the old scripts. Each ran on its own copy of the same real photos, and then the folders they produced were compared file by file. The first run, in July, compared the sort step alone on 856 files, and every difference it found had a known cause.
In September the comparison ran over the whole pipeline end to end, on one year’s folder of photos. About 110 files landed in a different month. The new version’s month matched the date in the file’s name, and the old scripts’ didn’t.
The bug was in the old scripts. When a photo had no sidecar they could use, they asked Windows for
the date it shows in Explorer. That date arrives as text, formatted for the machine’s region, so on
this machine 8 February is 08/02/2026, day first. The scripts then parsed that text the US way,
month first.
- With a day of 12 or lower,
08/02/2026parses without error, as 2 August. - With a day above 12,
19/05/2023is no valid US date. The parse fails, and the scripts fall through to their next source. That’s usually the date in the filename, which is right by luck. Where the name had none, it was the file’s last-modified time, the day of the export.
Before anything changed, the files got counted. Of the 405 files that year the old scripts couldn’t pair with a sidecar, 108 came out with day and month swapped. Those were the “about 110”.
There were two ways forward. One was to fix the old scripts, which meant fixing one function the same way in both scripts that had a copy. The other was to record a known difference and teach the comparison to forgive it. That touched five places, including both of its checks on the sorted library folders. I took the fix. Forgiving the difference would have turned the comparison green by loosening its checks on the library, the part of the output the comparison exists to protect.
The fixed function asks Windows for the date as a date value, so no text and no region setting are involved. It was checked on every unpaired file with a date in its name to compare against, 381 of them. It got every one right, including 369 the old function had misread or couldn’t read.
Keeping the old version runnable
The worst of these bugs didn’t turn up by reasoning about the formats. The names and the Android sizes needed the real files counted. The dates needed a second version to disagree with.
The date bug sat in the old scripts the whole time, and its output looked fine on its own. A photo filed in August instead of February doesn’t announce itself. The bug surfaced only because the old scripts stayed runnable until the new version matched them on real photos. None of these bugs reached anyone using Sluice, since all were found before release.
Once the two versions matched, the comparison code was deleted, 1,067 lines of it. The old scripts are still in the repository.
Those were the only tests that ever ran against a real Google export, and the export itself has since been deleted. Sluice handles real exports exactly as before. What changed is the testing. A unit test now checks Sluice against a table built from that export. It lists every name shape the export held, how many of each, and what Sluice must do with each one. The names in the table are made up, but the shapes and counts are the export’s own.