From 8ad185aec1fcf00c1dc71fd8669be259e797c012 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Wed, 11 Nov 2026 10:49:03 +0000 Subject: [PATCH] fix(cleaner): list folders du could not finish before finished ones A real report on a 1.8 TB box listed five home folders whose du ran out of time below the top 12, because what du had counted in 20 s was small. Those are the likeliest culprits, so incomplete sizes now always list first. Co-Authored-By: Claude Opus 5.5 --- packages/plugin-cleaner/src/cleaner.test.ts | 5 ++++- packages/plugin-cleaner/src/model.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/plugin-cleaner/src/cleaner.test.ts b/packages/plugin-cleaner/src/cleaner.test.ts index 79c72fb..f68bbc9 100644 --- a/packages/plugin-cleaner/src/cleaner.test.ts +++ b/packages/plugin-cleaner/src/cleaner.test.ts @@ -324,11 +324,14 @@ describe('pieces', () => { }) it('keeps what a timed-out du had counted as a lower bound, and ranks unknown sizes first', () => { - const raw = parseRecords(['META\t1000\tLinux\t1700000000\t0\t/h', 'TOP\t/h/a', 'SIZE\t/h/a\t100\t0', 'TOP\t/h/big', 'SIZE\t/h/big\t5000\t1', 'TOP\t/h/huge', 'SIZE\t/h/huge\t0\t1', 'END'].join('\n')) + const raw = parseRecords(['META\t1000\tLinux\t1700000000\t0\t/h', 'TOP\t/h/a', 'SIZE\t/h/a\t100\t0', 'TOP\t/h/big', 'SIZE\t/h/big\t5000\t1', 'TOP\t/h/huge', 'SIZE\t/h/huge\t0\t1', 'TOP\t/h/complete', 'SIZE\t/h/complete\t90000\t0', 'TOP\t/h/slow', 'SIZE\t/h/slow\t10\t1', 'END'].join('\n')) const report = buildReport(raw, { target: 'local', idleDays: 3, partialHours: 24, journalCap: '1G', imageAge: '72h', useSudo: false }) + // A folder du could not finish lists before any finished one, even with a tiny lower bound. expect(report.topDirs.map((d) => [d.path, d.bytes, d.timedOut])).toEqual([ ['/h/huge', -1, true], ['/h/big', 5000 * 1024, true], + ['/h/slow', 10 * 1024, true], + ['/h/complete', 90000 * 1024, false], ['/h/a', 100 * 1024, false], ]) }) diff --git a/packages/plugin-cleaner/src/model.ts b/packages/plugin-cleaner/src/model.ts index 1dddfa2..c64f66e 100644 --- a/packages/plugin-cleaner/src/model.ts +++ b/packages/plugin-cleaner/src/model.ts @@ -587,8 +587,9 @@ export function buildReport(raw: Raw, options: BuildOptions): Report { const bytes = size(path) return { path, bytes, timedOut: bytes < 0 || raw.partial.has(path), kind: classifyDir(path, raw.dockerRoot) } }) - // Unknown first (it ran out of time with nothing counted, so it may be the biggest), then by size; a lower bound counts as its size. - .sort((a, b) => (b.bytes < 0 ? Infinity : b.bytes) - (a.bytes < 0 ? Infinity : a.bytes)) + // Anything du could not finish first: it may well be the biggest, and a small lower bound + // (du counted for 20 s before giving up) must not push it off the list. Then by size. + .sort((a, b) => Number(b.timedOut) - Number(a.timedOut) || (b.bytes < 0 ? Infinity : b.bytes) - (a.bytes < 0 ? Infinity : a.bytes)) for (const dir of topDirs) { if (!dir.kind || !REVIEW_WHY[dir.kind]) continue