the exception was never the outcome, the delta was
a reclaim pass reported bytes it never touched, and the fix taught me that only measured deltas count as outcomes.
what it looked like from the outside
for a while the nightly cleanup jobs on the one-box stack looked healthier than they had any right to be. the logs said each pass freed a few hundred megabytes, sometimes more, and the reported numbers were confident and specific. the disk, meanwhile, disagreed. free space crept up on some days and sat still on others, and the gap between what the logs claimed and what the volume actually gained was never dramatic enough on any single night to force an investigation.
i read the symptom the way most people would: the job runs, it logs, the disk is tighter than it should be, so probably the cleanup is just small and the growth elsewhere is just large. two slow forces, no fault. that reading is comfortable because it requires no contradiction between the tools and the filesystem. the tools were, as far as i knew, honest programs doing modest work.
the reason it was easy to misread is that partial success looks identical to full success in a log line. a pass that walked most of the way through a directory tree and then died still did real work. it removed real files. if it reports the bytes it removed before dying, the number is mostly true. nobody audits 'mostly true' on a machine they own, at night, for a side business nobody is watching.
the day-job instinct should have fired earlier. in production systems i would never accept a self-reported outcome from a batch process without reconciling it against an external measurement. but on the side stack i had quietly lowered the bar, because the stakes were low and the machine was mine. that is exactly how fiction gets a foothold -- not through malice, but through a standard applied lazily to a system that deserves the same one.
the wrong theory
my first theory was that the cleanup jobs were racing the writers. cleanup walks the tree, an ingest job drops new files in, and the freed bytes get partially consumed before the next free-space sample. under that theory the logs were accurate and the disk was moving under our feet. it fit the evidence: the numbers were plausible, the disk never contradicted them by much, and timing races are the default explanation for any discrepancy between a process's view of the world and the world itself.
the second theory was simpler and more embarrassing: the jobs were counting wrong. maybe they summed file sizes from the directory listing rather than from actual deletions, or they included files that failed to unlink, or they were measuring logical bytes against compressed storage. any of these would produce a confident number that overstates reality. i had written both tools myself, quickly, and quick code is where counting bugs live.
both theories shared a flaw i didn't see yet. they assumed the reported number was a measurement of something that actually happened, possibly biased. neither theory considered that the number might describe a run that never finished -- that the tool had raised mid-pass and the handler had folded a partial result into a summary as if it were complete. the exception, i later understood, was not the outcome. it was evidence the outcome didn't exist.
the wrong theory persisted because it was unfalsifiable with the instrumentation i had. i had no independent measure of what a pass removed, so any gap could be explained by races, compression, or rounding. a theory that can absorb any observation isn't a theory; it's a comfort. i needed a number that came from outside the tool.
what actually settled it
the method that decided it was boring and should have been in place from the start. before each reclaim pass, stat the volume: total bytes used. run the pass. after it exits, however it exits, stat the volume again. take the delta. that delta is the ground truth -- what the filesystem actually gave back, regardless of what the tool believes it did.
then compare the tool's report against that delta. the first comparison after instrumenting this was clarifying. one pass reported freeing about twice what the volume actually returned. another reported a number close to the truth on a night the job completed cleanly. the pattern was immediate: discrepancy only on runs that ended early. the clean runs reconciled almost exactly, which ruled out counting bugs in the happy path entirely.
i went into the failure path and found the shape of it. an exception partway through the walk propagated to a handler that still emitted the summary line, using the tally accumulated so far. the log read like a completed run. nothing marked it partial except an error line several lines above, easy to skim past. the tool was reporting bytes it had listed but never deleted -- the returned count was fiction in the most literal sense, a forecast dressed as a result.
i checked the second tool and found the same pattern with a different accent. it caught the exception, logged it, and returned its tally as if the tally were the outcome. two independently written tools, same sin, because both were built from the same assumption: that the tool's internal ledger is the truth. the filesystem had been quietly correcting that assumption every night, and i hadn't been listening to it.
the fix
the fix stayed small. both tools now snapshot used bytes before the walk and after the walk, compute the real delta, and report that delta as the headline number. the internal tally still exists, but it's demoted to a diagnostic -- useful for understanding what the tool attempted, useless for daily totals. if the reported reclaim exceeds the measured delta, the run emits a warning and marks itself reconciled-false, which the rollup counts honestly.
the exception handling changed to match the rule: a partial pass is reported as a partial pass, with the measured delta as its outcome and the error attached, not absorbed. no handler may convert a failure into a confident number. if the tool dies, the log says what was actually freed -- a real, smaller number -- and nothing more. the guarantee that the exception never arrives is off the table; what's guaranteed is that no exception arrives silently.
what i deliberately did not change: the walk logic, the deletion order, the scheduling, the retention rules. the temptation after finding a bug in reporting is to also refactor the thing being reported on, and i've learned to resist that. one defect class per change. the tools did their work correctly most of the time; only the accounting was broken, so only the accounting got touched.
i also didn't build a reconciliation dashboard or a history table. the daily total now composes from measured deltas, and if a warning fires it surfaces in the same feed as everything else on the box. a one-person stack doesn't need an audit apparatus; it needs numbers that survive an audit. the difference between those two is a few stat calls and the discipline to trust the filesystem over the tool.
the rule i keep now
the rule i keep now is that a process never reports its own outcome; it reports the world before and after, and the delta is the truth. self-reported byte counts, record counts, durations -- all of it is a claim, not a measurement, and any claim produced by a run that raised is fiction by construction, because the run didn't finish and its ledger describes intent rather than effect. the same discipline transfers everywhere i point these loops: measure state externally at the boundaries, reconcile the claim against the delta, warn loudly when the claim exceeds reality, and refuse to let an exception handler launder a partial pass into a clean summary. the code for this is a handful of lines. the reason it matters is that daily totals compound from nightly claims, and unreconciled fiction accumulates until the day you need the numbers and discover they were never numbers at all. it's the same standard i apply without thinking in the day job, and the side stack earned it the same way every system earns it -- by lying first.
the rule: the exception is not the outcome -- measure the delta across the run, reconcile the claim against it, and never let a partial pass report a whole number.