Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Disk space: stop only when the bytes do not fit, warn inside the working-room margin, a resumed download's partial file is not counted twice

Niko1221537f8fef8e3d
diff --git a/setup.py b/setup.py
index 0ccfb424c..d97308ff9 100644
--- a/setup.py
+++ b/setup.py
@@ -7000,8 +7000,10 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte
size = fam["sha256"][gguf.name][0]
part = gguf.with_name(gguf.name + ".part")
left = 0 if gguf.exists() and done(gguf) else (size - (part.stat().st_size if part.is_file() else 0)) / 1e9
+ if left and free_gb(folder) < left:
+ fail(f"not enough free disk space in {folder}: need ~{left:.0f} GB, {free_gb(folder):.0f} GB free", "use --models-dir on a bigger drive")
if left and free_gb(folder) < left + 1:
- fail(f"not enough free disk space in {folder}: need ~{left + 1:.0f} GB", "use --models-dir on a bigger drive")
+ warn(f"little free disk space in {folder}: {free_gb(folder):.1f} GB free for about {left:.1f} GB. Setup goes on and should fit")
step(3, "Python packages")
pip_install(requirement_lines() if REQUIREMENTS.exists() else PY_PACKAGES,
@@ -7145,8 +7147,10 @@ def preview_family(a) -> int:
left = sum(fam["sha256"][f.name][0] - (f.with_name(f.name + ".part").stat().st_size
if f.with_name(f.name + ".part").is_file() else 0)
for f in files if not (f.exists() and done(f))) / 1e9
+ if left and free_gb(folder) < left:
+ fail(f"not enough free disk space in {folder}: need ~{left:.0f} GB, {free_gb(folder):.0f} GB free", "use --models-dir on a bigger drive")
if left and free_gb(folder) < left + 1:
- fail(f"not enough free disk space in {folder}: need ~{left + 1:.0f} GB", "use --models-dir on a bigger drive")
+ warn(f"little free disk space in {folder}: {free_gb(folder):.1f} GB free for about {left:.1f} GB. Setup goes on and should fit")
step(5, f"downloading {fam['title']} {model}")
for f in files:
url = (fam["mmproj_hf"] if f.name == fam["mmproj"] else fam["hf"]) + f.name
@@ -8129,13 +8133,19 @@ def main() -> int:
q2_avx = model == "Q2_0" and avx512 and family == "qwen"
prep_gb = MODELS[model].get("prepare_gb", 0.0) if ready and MODELS[model].get("prepare") and \
not prepared_done(model, models_dir) else 0.0
- need = to_fetch + prep_gb + (2 if mtp_have else 8) + \
+ margin = 2 if mtp_have else 8 # working room: a guess, not bytes that will be written
+ real = to_fetch + prep_gb + \
(40 if q2_avx and not pack_bin else 0) + (1 if vision != "none" else 0) + \
(MODELS[model]["arena_gb"] + 1 if low_ram and not q2_avx and not pack_bin else 0)
- if free_gb(models_dir) < need:
- fail(f"not enough free disk space in {models_dir}: need ~{need:.0f} GB" +
+ need = real + margin
+ free_now = free_gb(models_dir)
+ if free_now < real:
+ fail(f"not enough free disk space in {models_dir}: need ~{real:.0f} GB, {free_now:.0f} GB free" +
(f" ({on_disk:.0f} GB of the model is already there)" if on_disk >= 1 and not have_model else ""),
"use --models-dir on a bigger drive")
+ if free_now < need:
+ warn(f"little free disk space in {models_dir}: {free_now:.0f} GB free for about {real:.0f} GB of files. "
+ "Setup goes on and should fit; free up space if it stops")
# ---- 3. python packages
step(3, "Python packages")
diff --git a/strata_control/updater.py b/strata_control/updater.py
index 390708a97..65c5e62be 100644
--- a/strata_control/updater.py
+++ b/strata_control/updater.py
@@ -366,11 +366,26 @@ def extract(archive: Path, destination: Path, fmt: str, installed_bytes: int, *,
raise UpdateError(f"the package could not be unpacked: {longpath.describe_oserror(exc)}", 6) from None
-def _free_space_check(root: Path, need: int) -> None:
+def _free_space_check(root: Path, need: int, ctx: "Context | None" = None, sha256: str = "", component: str = "") -> None:
+ """Stop only when the drive cannot hold the bytes that are still to be written (the package not yet downloaded plus its unpacked
+ size). The 1.15 margin is a guess at working room, not a need: below it the update warns and goes on. A resumed download's
+ partial file is already on the drive, so it is not counted a second time."""
root.mkdir(parents=True, exist_ok=True)
free = shutil.disk_usage(root).free
- if free < need * SKEW_FREE_BYTES:
- raise UpdateError(f"not enough free space in {root}: {free // (1 << 20)} MiB free, about {int(need * SKEW_FREE_BYTES) // (1 << 20)} MiB needed", 6)
+ have = 0
+ if ctx is not None and sha256:
+ try:
+ have = (updates_dir(ctx.components) / "partial" / f"{sha256[:16]}.part").stat().st_size
+ except OSError:
+ have = 0
+ real = max(need - have, 0)
+ drive = root.anchor or str(root)
+ if free < real:
+ raise UpdateError(f"not enough free space on {drive}: {free // (1 << 20)} MiB free, {real // (1 << 20)} MiB needed. "
+ f"Free up some space on {drive} and run the update again", 6)
+ if free < real * SKEW_FREE_BYTES and ctx is not None:
+ ctx.say("warn", f"Little free space on {drive}: {free // (1 << 20)} MiB free for about {real // (1 << 20)} MiB. "
+ "The update goes on and should fit; free up space if it stops.", component=component or "update")
def _download(ctx: Context, state_name: str, url_ref: str, size: int, sha256: str, label: str, feed: feedmod.Feed) -> Path:
@@ -752,7 +767,7 @@ def update_engine(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
return result
root = ctx.components
_warn_if_deep(ctx, ec.engine_dir(root) / folder_name(pkg), longpath.LONGEST_IN_PACKAGE.get(pkg.backend, longpath.LONGEST_IN_PACKAGE_DEFAULT) + 1)
- _free_space_check(root, pkg.size + pkg.installed_bytes)
+ _free_space_check(root, pkg.size + pkg.installed_bytes, ctx, pkg.sha256, "engine")
archive = _download(ctx, "engine", pkg.url, pkg.size, pkg.sha256, f"engine {pkg.label}", feed)
# busy check after the long download: a model may have been started meanwhile; the verified archive is kept for the retry
wait_until_idle(ctx.serving, wait=ctx.wait, emit=ctx.emit, cancel=ctx.cancel, poll=ctx.poll)
@@ -918,7 +933,7 @@ def update_control(ctx: Context, feed: feedmod.Feed, state: State) -> dict:
return result
pkg = next(p for p in feed.control if p.platform == ctx.hardware["platform"])
root = ctx.components
- _free_space_check(root, pkg.size + pkg.installed_bytes)
+ _free_space_check(root, pkg.size + pkg.installed_bytes, ctx, pkg.sha256, "control")
archive = _download(ctx, "control", pkg.url, pkg.size, pkg.sha256, f"Control {pkg.version}", feed)
stage = new_stage(root, "c")
try:
@@ -1008,7 +1023,7 @@ def update_app(ctx: Context, feed: feedmod.Feed) -> dict:
if not key:
raise UpdateError("this build has no app update key (update_keys.json app_minisign_public); the app installer cannot be verified, so it was not downloaded", 5)
root = ctx.components
- _free_space_check(root, entry["size"])
+ _free_space_check(root, entry["size"], ctx, entry["sha256"], "app")
archive = _download(ctx, "app", entry["url"], entry["size"], entry["sha256"], f"Strata app {feed.app.version}", feed)
def chunks():
diff --git a/tests/terminal/test_disk_space.py b/tests/terminal/test_disk_space.py
new file mode 100644
index 000000000..cac894364
--- /dev/null
+++ b/tests/terminal/test_disk_space.py
@@ -0,0 +1,66 @@
+"""Disk-space checks stop only when the bytes to write do not fit; the working-room margin warns; a resumed download's partial file is not counted twice."""
+
+import tempfile
+import unittest
+from collections import namedtuple
+from pathlib import Path
+from unittest import mock
+
+from strata_control import updater
+
+Usage = namedtuple("Usage", "total used free")
+MiB = 1 << 20
+
+
+class Ctx:
+ def __init__(self, root):
+ self.components = root
+ self.said = []
+
+ def say(self, phase, message, **extra):
+ self.said.append((phase, message))
+
+
+class FreeSpace(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.root = Path(self.tmp.name)
+ self.addCleanup(self.tmp.cleanup)
+
+ def check(self, free_mib, need_mib, ctx=None, sha=""):
+ with mock.patch.object(updater.shutil, "disk_usage", return_value=Usage(10 ** 12, 0, free_mib * MiB)):
+ updater._free_space_check(self.root, need_mib * MiB, ctx, sha, "engine")
+
+ def test_plenty_of_room_is_silent(self):
+ ctx = Ctx(self.root)
+ self.check(5000, 1000, ctx)
+ self.assertEqual(ctx.said, [])
+
+ def test_between_the_real_need_and_the_margin_warns_and_goes_on(self):
+ ctx = Ctx(self.root)
+ self.check(1050, 1000, ctx) # 1.15x would be 1150
+ self.assertEqual(len(ctx.said), 1)
+ self.assertEqual(ctx.said[0][0], "warn")
+
+ def test_below_the_real_need_stops_and_names_the_drive_and_the_step(self):
+ with self.assertRaises(updater.UpdateError) as caught:
+ self.check(800, 1000, Ctx(self.root))
+ self.assertEqual(caught.exception.exit_code, 6)
+ self.assertIn("800 MiB free", str(caught.exception))
+ self.assertIn("Free up some space", str(caught.exception))
+
+ def test_the_partial_file_of_a_resumed_download_is_not_counted_twice(self):
+ ctx = Ctx(self.root)
+ sha = "ab" * 32
+ part = updater.updates_dir(self.root) / "partial"
+ part.mkdir(parents=True)
+ (part / f"{sha[:16]}.part").write_bytes(b"x" * 600)
+ with mock.patch.object(updater.shutil, "disk_usage", return_value=Usage(10 ** 12, 0, 500)):
+ updater._free_space_check(self.root, 1000, ctx, sha, "engine") # 400 still to write, 500 free: fine and silent
+ self.assertEqual(ctx.said, [])
+ with self.assertRaises(updater.UpdateError):
+ updater._free_space_check(self.root, 1000, ctx, "") # without the partial file's credit 1000 > 500
+
+
+if __name__ == "__main__":
+ unittest.main()