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: two more disk-preflight gaps from codex's third review pass

[._.]/ Adam Eivyafeee5e35445
diff --git a/server/lib/downloadPreflight.js b/server/lib/downloadPreflight.js
index d3a90da4b0..e4eea98782 100644
--- a/server/lib/downloadPreflight.js
+++ b/server/lib/downloadPreflight.js
@@ -272,10 +272,18 @@ export async function streamResumableDownload({
throw new ServerError('Download returned no body', { status: 502, code: 'DOWNLOAD_FAILED' });
}
- // Server ignored Range and sent the whole file — discard the leftover prefix.
+ // Server ignored Range and sent the whole file — discard the leftover
+ // prefix. The preflight the caller ran before starting only reserved the
+ // REMAINING bytes (crediting the partial already on disk); now the FULL
+ // payload is about to land instead, so recheck capacity against this
+ // response's own Content-Length before writing over the freed space.
if (resumeFrom > 0 && res.status === 200) {
await rm(tmpPath, { force: true }).catch(() => {});
resumeFrom = 0;
+ const freshLength = Number(res.headers?.get?.('content-length')) || 0;
+ if (freshLength > 0) {
+ assertDownloadFits(await assessDownloadPreflight({ destPath, expectedBytes: freshLength }));
+ }
}
const rangeTotal = parseContentRangeTotal(res.headers?.get?.('content-range'));
diff --git a/server/lib/downloadPreflight.test.js b/server/lib/downloadPreflight.test.js
index 0a58197511..3cd6f611f1 100644
--- a/server/lib/downloadPreflight.test.js
+++ b/server/lib/downloadPreflight.test.js
@@ -319,6 +319,31 @@ describe('streamResumableDownload', () => {
expect(await readFile(destPath, 'utf8')).toBe('full');
});
+ // The caller's own preflight only reserved space for the bytes still
+ // missing (crediting the .partial already on disk) — once the server
+ // ignores Range and the FULL payload is about to land instead, refuse
+ // rather than write past what the volume can hold.
+ it('refuses a Range-ignored restart the disk cannot actually hold', async () => {
+ const destPath = await makeDir();
+ await writeFile(partialPathFor(destPath), 'XX');
+ const fetchImpl = async (_url, opts) => {
+ expect(opts.headers.Range).toBe('bytes=2-');
+ return {
+ ok: true,
+ status: 200,
+ // No real disk holds this many bytes, so the recheck must reject
+ // regardless of the test machine's actual free space.
+ headers: { get: (name) => (name === 'content-length' ? String(Number.MAX_SAFE_INTEGER) : null) },
+ body: webBody('full'),
+ };
+ };
+ await expect(streamResumableDownload({
+ url: 'https://example.com/w.gguf', destPath, fetchImpl,
+ })).rejects.toMatchObject({ code: 'DISK_INSUFFICIENT' });
+ // Aborted before writing anything — the doomed transfer never started.
+ await expect(readFile(destPath, 'utf8')).rejects.toThrow();
+ });
+
it('deletes a completed download that does not match the published hash', async () => {
const destPath = await makeDir();
const payload = Buffer.from('ggufgg');
diff --git a/server/services/loras.js b/server/services/loras.js
index a3b9a2bcc3..69c47b9ec7 100644
--- a/server/services/loras.js
+++ b/server/services/loras.js
@@ -23,6 +23,7 @@ import { ServerError } from '../lib/errorHandler.js';
import {
assessDownloadPreflight,
assertDownloadFits,
+ probeRemoteSize,
siblingDownloadMeta,
streamResumableDownload,
} from '../lib/downloadPreflight.js';
@@ -696,8 +697,21 @@ const resolveHfLoraInstallPlan = async (input, { fetchImpl = fetch } = {}) => {
const filename = `lora-${slug}${explicitVariant ? `-${explicitVariant}` : ''}-hf.safetensors`;
const destPath = join(PATHS.loras, filename);
const hfSibling = (Array.isArray(model?.siblings) ? model.siblings : []).find((row) => row?.rfilename === file);
+ // The model-metadata response never carries per-sibling sizes without the
+ // `blobs=true` expand we deliberately skip (see fetchHuggingfaceModel) —
+ // siblingDownloadMeta is ~always 0 here. Without a real number the preflight
+ // can never refuse an oversized LoRA, so probe the resolved file directly
+ // (same fallback specDecodeModels.js already uses for GGUF weights).
+ let expectedBytes = siblingDownloadMeta(hfSibling).bytes;
+ if (!expectedBytes) {
+ const probed = await probeRemoteSize(buildHfResolveUrl(repo, revision, file), {
+ headers: buildHfAuthHeaders(token),
+ fetchImpl,
+ });
+ expectedBytes = probed.bytes;
+ }
- return { repo, revision, token, model, family, fluxVariant, file, filename, destPath, expectedBytes: siblingDownloadMeta(hfSibling).bytes };
+ return { repo, revision, token, model, family, fluxVariant, file, filename, destPath, expectedBytes };
};
// Install a LoRA from a HuggingFace repo (Flux.2 Klein image adapters, fal /
diff --git a/server/services/loras.test.js b/server/services/loras.test.js
index 24028a9873..1e658f071b 100644
--- a/server/services/loras.test.js
+++ b/server/services/loras.test.js
@@ -852,6 +852,27 @@ describe('installFromHuggingface', () => {
expect(calls.some((u) => u.includes('/resolve/main/pytorch_lora_weights.safetensors'))).toBe(true);
});
+ // HF's model-metadata response never carries per-sibling sizes (the
+ // `blobs=true` expand is deliberately not requested), so the preflight
+ // must probe the resolved file's own Content-Length via a HEAD request —
+ // otherwise expectedBytes stays 0 and disk-insufficient can never fire.
+ it('previews the probed Content-Length when the metadata response has no sibling size', async () => {
+ const fetchImpl = async (url, opts = {}) => {
+ if (url.startsWith('https://huggingface.co/api/models/fal/ltx2.3-audio-reactive-lora')) {
+ return mockJsonResponse(HF_MODEL);
+ }
+ if (url.includes('/resolve/main/pytorch_lora_weights.safetensors') && opts.method === 'HEAD') {
+ return { ok: true, status: 200, headers: { get: (name) => (name === 'content-length' ? '123456789' : null) } };
+ }
+ throw new Error(`unexpected fetch: ${url} ${opts.method || 'GET'}`);
+ };
+ const preview = await lorasService.previewHuggingfaceInstall(
+ { url: 'https://huggingface.co/fal/ltx2.3-audio-reactive-lora', token: 'hf_test' },
+ { fetchImpl },
+ );
+ expect(preview.expectedBytes).toBe(123456789);
+ });
+
it('installs an exact versioned file beside the repo default', async () => {
const versionedModel = {
...HF_MODEL,