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++

Deleting a model: a file that is already gone counts as removed; the host verifies the files are really gone

Niko1221917d2fc345ba
diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjs
index 73f658a0a..1d6f247b4 100644
--- a/apps/host/server/native-control.mjs
+++ b/apps/host/server/native-control.mjs
@@ -168,7 +168,11 @@ export function createNativeControl({directory,requests=()=>[],changed=()=>{},sp
job.summary='Deleting downloaded files…';emit();
const result=await tool('strata_remove',{model:args.model,confirm:true});
if(result.failed?.length)throw new Error(`Some files could not be removed: ${result.failed.slice(0,3).join('; ')}`);
- await refresh(true);return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
+ await refresh(true);
+ /* Verify it is really gone: the model must no longer be listed as installed, and the files the plan named must not exist. */
+ const still=(result.plan?.remove??[]).map(i=>i.path).filter(p=>{try{return existsSync(p);}catch{return false;}});
+ if(still.length)throw new Error(`Some files could not be removed: ${still.slice(0,3).map(p=>basename(p)).join('; ')}`);
+return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};}
/* The configuration a load starts the engine with (before its port and key): the saved model config, the user's choices and the resource profile. The tuner measures exactly this, so a saved tuning belongs to the same choices a load makes. */
function buildConfig(args,config){
const vision=runtimeVision(config,args.vision);
diff --git a/tools/strata_mcp.py b/tools/strata_mcp.py
index f6a70f338..e7d76561f 100644
--- a/tools/strata_mcp.py
+++ b/tools/strata_mcp.py
@@ -205,6 +205,14 @@ def proc_terminate(pid, ident) -> bool:
return False
+def _rmtree_ignore_missing(func, path, exc_info):
+ """shutil.rmtree error hook: a file that vanished while its folder was being removed is already gone."""
+ exc = exc_info[1] if isinstance(exc_info, tuple) else exc_info
+ if isinstance(exc, FileNotFoundError):
+ return
+ raise exc
+
+
def proc_kill_tree(pid, ident) -> bool:
"""End a process WE started together with the processes it started (setup's pip / cmake, the engine)."""
if not proc_alive(pid, ident):
@@ -1308,15 +1316,20 @@ class Tools:
if tracked and not tracked.get("ended") and tracked.get("model") == plan["model"]:
raise ToolError("this model is running: stop it first")
failed = []
+ # The plan can list a folder and files inside it, or a file that is already gone (an earlier delete, a file moved by hand):
+ # a path that is not there is already removed, not an error. Only what is still there afterwards counts as a failure.
for item in sorted(plan["remove"], key=lambda x: (x["path"] == str(config), x["path"])):
p = Path(item["path"])
try:
- if p.is_dir():
- shutil.rmtree(p)
+ if p.is_dir() and not p.is_symlink():
+ shutil.rmtree(p, onerror=_rmtree_ignore_missing)
else:
- p.unlink()
+ p.unlink(missing_ok=True)
+ except FileNotFoundError:
+ pass
except OSError as e:
- failed.append(f"{p.name}: {e}")
+ if p.exists() or p.is_symlink():
+ failed.append(f"{p.name}: {e}")
files, dirs = s.model_paths(s.read_config(config)) if config.exists() else ([], [])
for p in {x.parent for x in [Path(i["path"]) for i in plan["remove"]] if x.suffix == ".gguf"}:
try:
diff --git a/tools/test_strata_mcp.py b/tools/test_strata_mcp.py
index 9dd2210ad..a1098d87c 100644
--- a/tools/test_strata_mcp.py
+++ b/tools/test_strata_mcp.py
@@ -611,3 +611,40 @@ class Helpers(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
+
+
+class RemoveMissingFilesTest(unittest.TestCase):
+ """Deleting a model whose plan lists files that are already gone (or inside a folder removed earlier) is a success, not 'Some files could not be removed'."""
+
+ def test_missing_paths_are_already_removed(self):
+ import importlib.util, tempfile, threading
+ from pathlib import Path
+ spec = importlib.util.spec_from_file_location("strata_mcp_rm", Path(__file__).with_name("strata_mcp.py"))
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ with tempfile.TemporaryDirectory() as d:
+ root = Path(d)
+ folder = root / "Gyro-M"
+ folder.mkdir()
+ (folder / "a.gguf").write_bytes(b"x")
+ (folder / "b.gguf").write_bytes(b"y")
+ gone = root / "already-gone.gguf"
+ cfg = root / "model.json"
+ cfg.write_text("{}")
+ plan = {"model": "gyro-m", "gb": 0.1, "remove": [
+ {"path": str(folder)}, {"path": str(folder / "a.gguf")}, {"path": str(gone)}, {"path": str(cfg)}]}
+
+ class S:
+ lock = threading.RLock()
+ def find_config(self, model): return cfg
+ def removal_plan(self, config): return plan
+ def install_job(self): return None
+ def tracked_server(self): return None
+ def model_paths(self, c): return ([], [])
+ def read_config(self, c): return {}
+
+ result = mod.Tools(S()).strata_remove(model="gyro-m", confirm=True)
+ self.assertEqual(result["failed"], [], result)
+ self.assertFalse(folder.exists()); self.assertFalse(cfg.exists())
+ again = mod.Tools(S()).strata_remove(model="gyro-m", confirm=True)
+ self.assertEqual(again["failed"], [], "a second delete of the same model finds nothing left and still succeeds")