Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: disk preflight now credits an existing .partial's bytes toward the required space

[._.]/ Adam Eivy8bb236ce692c
diff --git a/server/lib/downloadPreflight.js b/server/lib/downloadPreflight.js
index 5f6647f496..d3a90da4b0 100644
--- a/server/lib/downloadPreflight.js
+++ b/server/lib/downloadPreflight.js
@@ -77,6 +77,11 @@ async function freeBytesForPath(destPath, statfsImpl) {
* failed reading cannot block a download that would have fit. `expectedBytes`
* of 0 means the size is unknown: we never refuse (cannot know it will fail)
* and never mark tight.
+ * A leftover `${destPath}.partial` from a prior attempt already occupies its
+ * share of disk — resuming only needs the REMAINING bytes, not the full
+ * payload again. Refusing on the full size would make a nearly-full disk
+ * reject a resume it can actually complete, defeating the resumable-download
+ * path in exactly the low-space scenario it exists for.
*
* @param {{ destPath?: string, expectedBytes?: number, headroomBytes?: number, statfsImpl?: typeof statfs }} opts
*/
@@ -88,16 +93,20 @@ export async function assessDownloadPreflight({
} = {}) {
const expected = Math.max(0, Number(expectedBytes) || 0);
const headroom = Math.max(0, Number(headroomBytes) || 0);
- const requiredBytes = expected > 0 ? expected + headroom : 0;
+ const partialBytes = destPath
+ ? await stat(partialPathFor(destPath)).then((s) => s.size, () => 0)
+ : 0;
+ const remaining = Math.max(0, expected - partialBytes);
+ const requiredBytes = remaining > 0 ? remaining + headroom : 0;
const freeBytes = await freeBytesForPath(destPath, statfsImpl);
let verdict = DOWNLOAD_VERDICTS.OK;
- if (freeBytes != null && expected > 0 && freeBytes < expected) {
+ if (freeBytes != null && remaining > 0 && freeBytes < remaining) {
verdict = DOWNLOAD_VERDICTS.INSUFFICIENT;
} else if (
freeBytes != null
- && expected > 0
- && freeBytes - expected < Math.max(headroom, freeBytes * TIGHT_REMAINING_RATIO)
+ && remaining > 0
+ && freeBytes - remaining < Math.max(headroom, freeBytes * TIGHT_REMAINING_RATIO)
) {
verdict = DOWNLOAD_VERDICTS.TIGHT;
}
diff --git a/server/lib/downloadPreflight.test.js b/server/lib/downloadPreflight.test.js
index b12a0b7b48..0a58197511 100644
--- a/server/lib/downloadPreflight.test.js
+++ b/server/lib/downloadPreflight.test.js
@@ -112,6 +112,58 @@ describe('assessDownloadPreflight', () => {
expect(result.freeBytes).toBeNull();
expect(result.verdict).toBe(DOWNLOAD_VERDICTS.OK);
});
+
+ describe('with a leftover .partial from a prior attempt', () => {
+ const MiB = 1024 * 1024;
+ let dir;
+
+ afterEach(async () => {
+ if (dir) await rm(dir, { recursive: true, force: true });
+ dir = null;
+ });
+
+ // A resume only needs the REMAINING bytes — refusing on the full payload
+ // size would reject a retry the resumable-download path could actually
+ // complete, on a disk that is nearly full precisely because most of the
+ // payload is already sitting in the .partial. Sizes are MiB-scale (not
+ // the real GiB payloads a weight download moves) purely to keep the test
+ // fast — the comparison the fix makes is dimensionless.
+ it('subtracts the already-downloaded bytes from the space it requires', async () => {
+ dir = await mkdtemp(join(tmpdir(), 'portos-dl-preflight-partial-'));
+ const destPath = join(dir, 'weights.gguf');
+ await writeFile(partialPathFor(destPath), Buffer.alloc(9 * MiB));
+
+ const result = await assessDownloadPreflight({
+ destPath,
+ expectedBytes: 10 * MiB,
+ headroomBytes: 1 * MiB,
+ // 3 MiB free: not enough for the full 10 MiB payload + headroom, but
+ // comfortably covers the 1 MiB actually still missing (+ headroom).
+ statfsImpl: async () => ({ bavail: 3, bsize: MiB }),
+ });
+
+ expect(result.verdict).toBe(DOWNLOAD_VERDICTS.OK);
+ expect(result.requiredBytes).toBe(2 * MiB);
+ // The reported size still reflects the whole file — only the verdict
+ // math looks at what's left to fetch.
+ expect(result.expectedBytes).toBe(10 * MiB);
+ });
+
+ it('still refuses when even the remaining bytes will not fit', async () => {
+ dir = await mkdtemp(join(tmpdir(), 'portos-dl-preflight-partial-'));
+ const destPath = join(dir, 'weights.gguf');
+ await writeFile(partialPathFor(destPath), Buffer.alloc(1 * MiB));
+
+ const result = await assessDownloadPreflight({
+ destPath,
+ expectedBytes: 10 * MiB,
+ headroomBytes: 1 * MiB,
+ statfsImpl: async () => ({ bavail: 2, bsize: MiB }),
+ });
+
+ expect(result.verdict).toBe(DOWNLOAD_VERDICTS.INSUFFICIENT);
+ });
+ });
});
describe('probeRemoteSize', () => {