@simplexai/localmodels-win32-x64 0.1.0-dev.106 → 0.1.0-dev.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/bootstrap.identity +1 -1
  3. package/bootstrap.sha256 +64 -61
  4. package/modules/localmodels/__init__.py +2 -5
  5. package/modules/localmodels/catalog.json +317 -111
  6. package/modules/localmodels/catalog.py +13 -4
  7. package/modules/localmodels/catalog_recipes.py +16 -1
  8. package/modules/localmodels/context_policy.py +3 -4
  9. package/modules/localmodels/engine_adapters/__init__.py +1 -2
  10. package/modules/localmodels/engine_adapters/llama_cpp.py +11 -5
  11. package/modules/localmodels/engine_adapters/strata_poly.py +1 -1
  12. package/modules/localmodels/engines-b11583.json +4 -4
  13. package/modules/localmodels/engines-b12973.json +248 -0
  14. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  15. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +1 -1
  16. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +5 -2
  17. package/modules/localmodels/engines-whisper-b5454.json +5 -5
  18. package/modules/localmodels/engines.json +4 -4
  19. package/modules/localmodels/estimator.py +0 -1
  20. package/modules/localmodels/gguf.py +0 -1
  21. package/modules/localmodels/library_cli.py +68 -1
  22. package/modules/localmodels/library_elastic.py +1 -1
  23. package/modules/localmodels/library_order.py +2 -2
  24. package/modules/localmodels/library_poly.py +1 -1
  25. package/modules/localmodels/library_pricing.py +1 -2
  26. package/modules/localmodels/library_unload.py +274 -0
  27. package/modules/localmodels/llm_rank.py +5 -5
  28. package/modules/localmodels/metal.py +5 -5
  29. package/modules/localmodels/planning/__init__.py +1 -2
  30. package/modules/localmodels/planning/budget.py +1 -1
  31. package/modules/localmodels/probe.py +98 -7
  32. package/modules/localmodels/remote_ops_download.py +32 -7
  33. package/modules/localmodels/remote_ops_ranges.py +1 -1
  34. package/modules/localmodels/remote_ops_remove.py +1 -1
  35. package/modules/localmodels/remote_ops_verify.py +1 -1
  36. package/modules/localmodels/runtime-lock.json +1 -1
  37. package/modules/localmodels/service_deployment.py +1 -1
  38. package/modules/localmodels/service_roots.py +148 -0
  39. package/modules/localmodels/service_upgrade.py +46 -1
  40. package/modules/localmodels/services_cli.py +8 -28
  41. package/modules/localmodels/speech_workers.py +4 -4
  42. package/modules/localmodels/stack_args.py +11 -4
  43. package/modules/localmodels/stack_auto.py +3 -3
  44. package/modules/localmodels/stack_cleanup.py +3 -3
  45. package/modules/localmodels/stack_compose.py +6 -7
  46. package/modules/localmodels/stack_down.py +368 -42
  47. package/modules/localmodels/stack_memory.py +1 -1
  48. package/modules/localmodels/stack_plan.py +5 -5
  49. package/modules/localmodels/stack_preflight.py +2 -2
  50. package/modules/localmodels/stack_suite.py +2 -2
  51. package/modules/localmodels/stack_view_hub_cli.py +1 -1
  52. package/modules/localmodels/stack_view_llm.py +2 -2
  53. package/modules/localmodels/suite.py +1 -1
  54. package/modules/localmodels/tts_backend_speechcpp.py +2 -2
  55. package/modules/localmodels/tts_workers.py +3 -3
  56. package/modules/localmodels/vision.py +2 -2
  57. package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/METADATA +1 -1
  58. package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/RECORD +60 -57
  59. package/package.json +1 -1
  60. package/tool.json +1 -1
  61. /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/WHEEL +0 -0
  62. /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/entry_points.txt +0 -0
  63. /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/LICENSE +0 -0
  64. /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/NOTICE +0 -0
  65. /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -3,7 +3,7 @@
3
3
  "tag": "b11370",
4
4
  "commit": "bed0a856606ee4a24a164066f73d2379447033f5",
5
5
  "source": "https://github.com/ggml-org/llama.cpp/releases/tag/b11370",
6
- "note": "Release asset digests from the GitHub release API, read 2026-10-12. b11370 is the build Hermes' catalog constants were measured on. min_glibc is the highest GLIBC symbol version the build's binaries import (objdump -T, 2026-10-20); builds without it were not checked. The ubuntu22.04 variant (2026-10-23) is this repository's rebuild of the same commit for hosts whose glibc is older than upstream's 2.38: scripts/build_cuda_engine.py runs the release workflow's CMake flags in nvidia/cuda:12.8.2-devel-ubuntu22.04 pinned by digest; its provenance JSON records the image, flags and toolchain, and its archives and provenance live on the project CloudFront CDN under cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/. Every upstream Linux build links GCC's OpenMP runtime (libgomp.so.1, Debian package libgomp1; readelf NEEDED, 2026-10-23), which minimal images lack, so a plan on such a host stops instead of installing it. The ubuntu22.04-r2 rebuild (2026-10-23) carries its own libgomp.so.1 and replaces r1, which needed the system copy. The ubuntu22.04-r3 rebuild (2026-10-26) also compiles the q8_0-q4_0 FlashAttention K-V kernels (GGML_CUDA_FA_QUANTS), which the agent stack's K q8_0 / V q4_0 cache needs to decode at full speed; it replaces r2. Windows x64 builds (2026-11-11) are upstream's win-cuda-12.4/13.4 and win-cpu zips with their cudart companions, digests from the same release API; the CUDA zips hold llama-server.exe beside the ggml DLLs and the cudart zip adds the CUDA runtime DLLs to the same directory.",
6
+ "note": "Release asset digests from the GitHub release API, read 2026-10-12. b11370 is the build Hermes' catalog constants were measured on. min_glibc is the highest GLIBC symbol version the build's binaries import (objdump -T, 2026-10-20); builds without it were not checked. The ubuntu22.04 variant (2026-10-23) is this repository's rebuild of the same commit for hosts whose glibc is older than upstream's 2.38: scripts/build_cuda_engine.py runs the release workflow's CMake flags in nvidia/cuda:12.8.2-devel-ubuntu22.04 pinned by digest; its provenance JSON records the image, flags and toolchain, and its archives and provenance live on the project CloudFront CDN under cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/. Every upstream Linux build links GCC's OpenMP runtime (libgomp.so.1, Debian package libgomp1; readelf NEEDED, 2026-10-23), which minimal images lack, so a plan on such a host stops instead of installing it. The ubuntu22.04-r2 rebuild (2026-10-23) carries its own libgomp.so.1 and replaces r1, which needed the system copy. The ubuntu22.04-r3 rebuild (2026-10-26) also compiles the q8_0-q4_0 FlashAttention K-V kernels (GGML_CUDA_FA_QUANTS), which the agent stack's K q8_0 / V q4_0 cache needs to decode at full speed (reference benchmark); it replaces r2. Windows x64 builds (2026-11-11) are upstream's win-cuda-12.4/13.4 and win-cpu zips with their cudart companions, digests from the same release API; the CUDA zips hold llama-server.exe beside the ggml DLLs and the cudart zip adds the CUDA runtime DLLs to the same directory.",
7
7
  "builds": [
8
8
  {
9
9
  "platform": "linux",
@@ -36,17 +36,17 @@
36
36
  "min_cuda": "12.8",
37
37
  "min_glibc": "2.34",
38
38
  "variant": "ubuntu22.04-r3",
39
- "provenance": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.provenance.json",
39
+ "provenance": "https://releases.heylinger.com/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.provenance.json",
40
40
  "assets": [
41
41
  {
42
42
  "name": "llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
43
- "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
43
+ "url": "https://releases.heylinger.com/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
44
44
  "sha256": "875cf9ee9e29afc60187312363ea721db51bb06138aef7c1ca63fc3d956b25b1",
45
45
  "size_bytes": 173034114
46
46
  },
47
47
  {
48
48
  "name": "cudart-llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
49
- "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/cudart-llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
49
+ "url": "https://releases.heylinger.com/cli/localmodels/engines/llama.cpp/b11370-cu12.8-ubuntu22.04-r3/cudart-llama-b11370-bin-ubuntu22.04-r3-cuda-12.8-x64.tar.gz",
50
50
  "sha256": "441680ed89b157f7e0bd7285771cc0d40fd61ab1110bf4c67a705dd9417ab624",
51
51
  "size_bytes": 593656099
52
52
  }
@@ -1,6 +1,5 @@
1
1
  # Ported from NousResearch/hermes-agent hermes_cli/local_runtime (MIT License,
2
2
  # Copyright (c) 2025 Nous Research) at commit 7cc3fb8cb55898747dd1dfa56fda3e16ebba028e.
3
- # Keep algorithm changes in sync with docs/local-models/architecture.md.
4
3
  """Per-layer context-memory estimator + physics check.
5
4
 
6
5
  The estimator is ADVISORY: fit's allocation is authoritative at launch and the touch generation is
@@ -1,6 +1,5 @@
1
1
  # Ported from NousResearch/hermes-agent hermes_cli/local_runtime (MIT License,
2
2
  # Copyright (c) 2025 Nous Research) at commit 7cc3fb8cb55898747dd1dfa56fda3e16ebba028e.
3
- # Keep algorithm changes in sync with docs/local-models/architecture.md.
4
3
  """GGUF metadata + tensor-table reader (stdlib only).
5
4
 
6
5
  Reads the header only (metadata + tensor infos); never touches tensor data, so it is fast enough to
@@ -147,8 +147,36 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
147
147
  "record verification status, and stop the server so active models and routing stay untouched.",
148
148
  examples=[("%(prog)s custom.hf.owner--repo:Q4_K_M --ctx 4096 --jsonl", "")],
149
149
  )
150
+ unload_cmd = verbs.add_parser("unload", help="stop a model's server; its weights stay")
151
+ unload_cmd.add_argument(
152
+ "model",
153
+ nargs="?",
154
+ default=None,
155
+ metavar="MODEL",
156
+ help="a library model id, CATALOG_ID:QUANT (omit when using --all)",
157
+ )
158
+ unload_cmd.add_argument(
159
+ "--all",
160
+ action="store_true",
161
+ help="unload every loaded or active library model and cancel active library jobs",
162
+ )
163
+ _base(unload_cmd)
164
+ unload_cmd.add_argument(
165
+ "--json",
166
+ action="store_true",
167
+ help="print one result as JSON (single-model unload always prints JSON)",
168
+ )
169
+ cli_help.document(
170
+ unload_cmd,
171
+ "Stop a model's server (or every active library model with --all); its weights stay. "
172
+ "Single-model unload prints one localmodels.library-event/v1 JSON object; --all prints "
173
+ "localmodels.library-unload-all/v1 with --json or a concise text summary otherwise.",
174
+ examples=[
175
+ ("%(prog)s qwen3.8-27b-iq3s:UD-IQ3_S --json", ""),
176
+ ("%(prog)s --all --json", "unload every active or loaded library model"),
177
+ ],
178
+ )
150
179
  for verb, text, note in (
151
- ("unload", "stop a model's server; its weights stay", "stop the server"),
152
180
  ("remove", "delete a model's weights (unloads it first)", "keeps files others use"),
153
181
  ("cancel", "stop a running download and delete its files", "the download exits 130"),
154
182
  ):
@@ -337,12 +365,51 @@ def _status(args: argparse.Namespace) -> int:
337
365
  return 0
338
366
 
339
367
 
368
+ def _unload_all(args: argparse.Namespace) -> int:
369
+ from localmodels import library_unload
370
+
371
+ as_json = bool(getattr(args, "json", False))
372
+ try:
373
+ report = library_unload.unload_all(args.base_dir)
374
+ except KeyboardInterrupt:
375
+ error = LibraryError("CANCELLED", "the unload was interrupted")
376
+ if as_json:
377
+ emit_final(error_doc(error), jsonl=False)
378
+ else:
379
+ print("error: library unload --all was interrupted", file=sys.stderr)
380
+ return error.exit_code
381
+ except Exception as exc: # noqa: BLE001 - consistent CLI error handling
382
+ if as_json:
383
+ emit_final(error_doc(LibraryError(FALLBACK["unload"], str(exc))), jsonl=False)
384
+ else:
385
+ print(f"error: library unload --all failed: {exc}", file=sys.stderr)
386
+ return EXIT_FAILED
387
+ if as_json:
388
+ print(json.dumps(report, ensure_ascii=False, indent=1))
389
+ return 0 if report["ok"] else EXIT_FAILED
390
+ return library_unload.print_report(report)
391
+
392
+
340
393
  def cli(args: argparse.Namespace) -> int:
341
394
  verb = args.library_command
342
395
  if verb == "status":
343
396
  return _status(args)
344
397
  if verb == "custom":
345
398
  return _custom(args)
399
+ if verb == "unload":
400
+ use_all = bool(getattr(args, "all", False))
401
+ model_id = getattr(args, "model", None)
402
+ if use_all and model_id is not None:
403
+ print(
404
+ "error: library unload: specify either MODEL or --all, not both",
405
+ file=sys.stderr,
406
+ )
407
+ return 2
408
+ if not use_all and model_id is None:
409
+ print("error: library unload: specify MODEL or --all", file=sys.stderr)
410
+ return 2
411
+ if use_all:
412
+ return _unload_all(args)
346
413
  from localmodels import library_jobs, library_serve, library_smoke
347
414
 
348
415
  jsonl = verb in ("download", "load", "smoke-test")
@@ -203,7 +203,7 @@ def _floor_need_bytes(
203
203
  ) -> tuple[int, int]:
204
204
  """(total_need_bytes, wired_need_bytes) at ``floor_posture`` (compact KV)."""
205
205
  active = model.entry.agent_posture(floor_posture)
206
- profile = estimator.eager(model.entry.profile(model.variant))
206
+ profile = model.entry.agent_profile(model.variant)
207
207
  window = min(active.floor, profile.n_ctx_train) if profile.n_ctx_train > 0 else active.floor
208
208
  kv = active.kv_types[-1]
209
209
  mtp = bool(model.entry.mtp_capable and model.entry.agent_mtp and active.mtp_draft_depth > 0)
@@ -1,9 +1,9 @@
1
1
  """Suitability ordering for ``library status`` rows across Apple Silicon, Linux and Windows.
2
2
 
3
- Apple Silicon Macs order rows around the Mac small-memory ladder (Decision 68). Linux and
3
+ Apple Silicon Macs order rows around the Mac small-memory ladder. Linux and
4
4
  Windows hosts order rows around validated intelligence, context window, quantization precision,
5
5
  actionable driver/runtime upgrades and memory shortfall, demoting the Windows small-card
6
- fallback below validated models whenever a validated model fits (Decision 69).
6
+ fallback below validated models whenever a validated model fits.
7
7
  """
8
8
 
9
9
  from __future__ import annotations
@@ -83,7 +83,7 @@ def _validated_for(recipe: suite.SuiteRecipe, platform: str) -> bool:
83
83
  scope = recipe.get("validated_on")
84
84
  if not scope:
85
85
  return True
86
- # Decision 48: Linux CUDA evidence also validates native Windows x64 CUDA builds.
86
+ # Linux CUDA evidence also validates native Windows x64 CUDA builds.
87
87
  return key in scope or (key == "win32" and "linux" in scope)
88
88
 
89
89
 
@@ -43,7 +43,6 @@ from localmodels.estimator import (
43
43
  AGENT_VRAM_RESERVE_BYTES,
44
44
  PhysicsRefusal,
45
45
  agent_footprint_bytes,
46
- eager,
47
46
  )
48
47
  from localmodels.library_model import LibraryError, Reason, display_name, split_id
49
48
  from localmodels.planning import budget, llm_ram, memory_pools
@@ -613,7 +612,7 @@ def floor_metadata(
613
612
  active = model.entry.agent_posture(
614
613
  context_policy.posture_for(posture(), "metal" if metal_unified else "cuda")
615
614
  )
616
- profile = eager(model.entry.profile(model.variant))
615
+ profile = model.entry.agent_profile(model.variant)
617
616
  window = profile.n_ctx_train if 0 < profile.n_ctx_train < active.floor else active.floor
618
617
  vision_on = vision.llama_reader_enabled(model.entry.mmproj, active.vision)
619
618
  mtp = bool(model.entry.mtp_capable and model.entry.agent_mtp and active.mtp_draft_depth > 0)
@@ -0,0 +1,274 @@
1
+ """``library unload --all``: unload every active library model and cancel active library jobs.
2
+
3
+ Composes with ``library_serve.stop`` and ``library_state`` / ``library_jobs`` without requiring
4
+ hardware probing or catalog resolution, so retired, custom, and legacy on-disk records unload
5
+ cleanly. Idle records and failed-download jobs (with resumable partials) are safely skipped.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import sys
11
+ from collections.abc import Callable
12
+ from typing import Literal, TypedDict
13
+
14
+ from localmodels import (
15
+ cli_help,
16
+ console,
17
+ library_jobs,
18
+ library_serve,
19
+ library_state,
20
+ runtime_index,
21
+ )
22
+ from localmodels.library_model import DETAIL_LIMIT, ERROR_CODES, LibraryError
23
+ from localmodels.library_state import Job
24
+ from localmodels.transport import Executor
25
+
26
+ UNLOAD_ALL_SCHEMA: Literal["localmodels.library-unload-all/v1"] = (
27
+ "localmodels.library-unload-all/v1"
28
+ )
29
+ Out = Callable[[str], None]
30
+
31
+ PreviousState = Literal["loaded", "starting", "failed", "loading", "downloading", "smoke_test"]
32
+ UnloadAction = Literal["unloaded", "cancelled"]
33
+ SkipReason = Literal["already_idle", "failed_download"]
34
+
35
+ _DOWNLOAD_STOP_GRACE_S = 20.0
36
+ _ACTIVE_JOB_GRACE_POSIX_S = 5.0
37
+ _ACTIVE_JOB_GRACE_WINDOWS_S = 2.0
38
+
39
+
40
+ class UnloadAllItem(TypedDict):
41
+ id: str
42
+ previous_state: PreviousState
43
+ action: UnloadAction
44
+ detail: str
45
+
46
+
47
+ class UnloadAllSkipped(TypedDict):
48
+ id: str
49
+ state: Literal["idle", "failed"]
50
+ reason: SkipReason
51
+
52
+
53
+ class UnloadAllError(TypedDict):
54
+ id: str
55
+ code: str
56
+ detail: str
57
+
58
+
59
+ class UnloadAllReport(TypedDict):
60
+ schema: Literal["localmodels.library-unload-all/v1"]
61
+ ok: bool
62
+ unloaded: list[UnloadAllItem]
63
+ skipped: list[UnloadAllSkipped]
64
+ errors: list[UnloadAllError]
65
+ runtime_index_refreshed: bool
66
+
67
+
68
+ def _previous_job_state(kind: str) -> PreviousState:
69
+ if kind == "download":
70
+ return "downloading"
71
+ if kind == "smoke_test":
72
+ return "smoke_test"
73
+ return "loading"
74
+
75
+
76
+ def _previous_record_state(raw: str) -> PreviousState:
77
+ if raw == "starting":
78
+ return "starting"
79
+ if raw == "failed":
80
+ return "failed"
81
+ return "loaded"
82
+
83
+
84
+ def _job_grace_seconds(kind: str) -> float:
85
+ if kind == "download":
86
+ return _DOWNLOAD_STOP_GRACE_S
87
+ return _ACTIVE_JOB_GRACE_WINDOWS_S if sys.platform == "win32" else _ACTIVE_JOB_GRACE_POSIX_S
88
+
89
+
90
+ def _stop_active_job(model_id: str, job: Job, base_dir: str) -> PreviousState:
91
+ """Cancel an in-flight download, load, or smoke-test job using its verified process receipt."""
92
+ kind = job["kind"]
93
+ if kind in ("unload", "remove"):
94
+ raise LibraryError("JOB_RUNNING", f"{model_id} has a running {kind}", failed=True)
95
+
96
+ with library_state.locked():
97
+ current_job = library_state.read_job(model_id)
98
+ if current_job is None or current_job.get("id") != job.get("id"):
99
+ return _previous_job_state(kind)
100
+ if not library_state.job_alive(model_id):
101
+ if kind != "download" or library_state.load(model_id) is not None:
102
+ library_state.clear_job(model_id)
103
+ return _previous_job_state(kind)
104
+ identity = library_state.receipt(model_id)
105
+ library_state.mark_cancelled(current_job)
106
+
107
+ if identity is not None:
108
+ try:
109
+ library_state.stop_process(identity, grace=_job_grace_seconds(kind))
110
+ except (OSError, RuntimeError) as exc:
111
+ code = "INVALID_STATE" if kind == "download" else "ENGINE_START_FAILED"
112
+ raise LibraryError(code, f"cannot stop active {kind}: {exc}", failed=True) from None
113
+ elif library_state.job_alive(model_id):
114
+ raise LibraryError(
115
+ "ENGINE_START_FAILED",
116
+ f"cannot stop active {kind}: missing process receipt",
117
+ failed=True,
118
+ )
119
+
120
+ with library_state.locked():
121
+ committed = library_state.load(model_id) is not None
122
+ if library_state.current(job) and not library_state.job_alive(model_id):
123
+ if kind == "download" and not committed:
124
+ gone = library_jobs.leftovers(job)
125
+ library_jobs.delete_weights(gone, library_jobs.in_use(model_id))
126
+ library_jobs.prune_empty_custom_dirs(gone, job.get("base_dir") or base_dir)
127
+ library_state.clear_job(model_id)
128
+ else:
129
+ library_state.clear_job(model_id)
130
+
131
+ return _previous_job_state(kind)
132
+
133
+
134
+ def _inspect_and_handle_job(
135
+ model_id: str, base_dir: str
136
+ ) -> tuple[PreviousState | None, UnloadAllSkipped | None]:
137
+ """Handle any live or stale job for ``model_id``; returns ``(cancelled_state, skipped)``."""
138
+ with library_state.locked():
139
+ job = library_state.read_job(model_id)
140
+ if job is None:
141
+ return None, None
142
+ alive = library_state.job_alive(model_id)
143
+ record = library_state.load(model_id)
144
+ if not alive:
145
+ if job["kind"] == "download" and record is None:
146
+ return None, {
147
+ "id": model_id,
148
+ "state": "failed",
149
+ "reason": "failed_download",
150
+ }
151
+ library_state.clear_job(model_id)
152
+ return None, None
153
+ cancelled_state = _stop_active_job(model_id, job, base_dir)
154
+ return cancelled_state, None
155
+
156
+
157
+ def _unload_one(
158
+ model_id: str,
159
+ base_dir: str,
160
+ executor: Executor,
161
+ ) -> tuple[UnloadAllItem | None, UnloadAllSkipped | None]:
162
+ """Best-effort unload/cancel of one model id; raises ``LibraryError`` on failure."""
163
+ cancelled_state, skipped = _inspect_and_handle_job(model_id, base_dir)
164
+ if skipped is not None:
165
+ return None, skipped
166
+
167
+ with library_state.locked():
168
+ record = library_state.load(model_id)
169
+ if record is None:
170
+ if cancelled_state is None:
171
+ return None, None
172
+ return {
173
+ "id": model_id,
174
+ "previous_state": cancelled_state,
175
+ "action": "cancelled",
176
+ "detail": "",
177
+ }, None
178
+ if record["state"] == "idle":
179
+ if cancelled_state is not None:
180
+ return {
181
+ "id": model_id,
182
+ "previous_state": cancelled_state,
183
+ "action": "cancelled",
184
+ "detail": "",
185
+ }, None
186
+ return None, {"id": model_id, "state": "idle", "reason": "already_idle"}
187
+ library_state.refuse_busy(model_id, "unload")
188
+ prev_state = cancelled_state or _previous_record_state(record["state"])
189
+ claim = library_state.acquire("unload", model_id, record["pool"], 0, [])
190
+
191
+ with library_state.held([claim]):
192
+ library_serve.stop(record, executor)
193
+
194
+ return {
195
+ "id": model_id,
196
+ "previous_state": prev_state,
197
+ "action": "unloaded",
198
+ "detail": "",
199
+ }, None
200
+
201
+
202
+ def _error_entry(model_id: str, exc: Exception) -> UnloadAllError:
203
+ if isinstance(exc, LibraryError):
204
+ code = exc.code if exc.code in ERROR_CODES else "ENGINE_START_FAILED"
205
+ detail = exc.detail
206
+ else:
207
+ code = "ENGINE_START_FAILED"
208
+ detail = str(exc) or type(exc).__name__
209
+ return {"id": model_id, "code": code, "detail": detail[-DETAIL_LIMIT:]}
210
+
211
+
212
+ def unload_all(base_dir: str = cli_help.DEFAULT_BASE_DIR) -> UnloadAllReport:
213
+ """Unload every active/loaded library model and cancel active jobs (best-effort)."""
214
+ records = library_state.records()
215
+ jobs = library_state.jobs()
216
+ model_ids = sorted({record["id"] for record in records} | set(jobs))
217
+
218
+ unloaded: list[UnloadAllItem] = []
219
+ skipped: list[UnloadAllSkipped] = []
220
+ errors: list[UnloadAllError] = []
221
+
222
+ if model_ids:
223
+ executor = library_jobs.executor()
224
+ for model_id in model_ids:
225
+ try:
226
+ item, skip = _unload_one(model_id, base_dir, executor)
227
+ except (LibraryError, OSError, RuntimeError, ValueError) as exc:
228
+ errors.append(_error_entry(model_id, exc))
229
+ continue
230
+ if item is not None:
231
+ unloaded.append(item)
232
+ elif skip is not None:
233
+ skipped.append(skip)
234
+
235
+ refreshed = runtime_index.refresh() is not None
236
+ return {
237
+ "schema": UNLOAD_ALL_SCHEMA,
238
+ "ok": not errors,
239
+ "unloaded": unloaded,
240
+ "skipped": skipped,
241
+ "errors": errors,
242
+ "runtime_index_refreshed": refreshed,
243
+ }
244
+
245
+
246
+ def print_report(report: UnloadAllReport, out: Out = print) -> int:
247
+ """Print a concise human-readable summary of ``library unload --all``."""
248
+ t = console.term(sys.stdout)
249
+ for item in report["unloaded"]:
250
+ out(
251
+ f"{t.mark('ok')} {item['id']} {item['action']} (was {item['previous_state']})"
252
+ + (f": {item['detail']}" if item["detail"] else "")
253
+ )
254
+ for skip in report["skipped"]:
255
+ reason = "already idle" if skip["reason"] == "already_idle" else "failed download kept"
256
+ out(f"{t.mark('skip')} {skip['id']} skipped ({reason})")
257
+ for err in report["errors"]:
258
+ out(f"{t.mark('fail')} {err['id']} {err['code']}: {err['detail']}")
259
+ if not report["unloaded"] and not report["skipped"] and not report["errors"]:
260
+ out("No library models or active jobs under this state directory")
261
+ if report["ok"]:
262
+ count = len(report["unloaded"])
263
+ out(
264
+ t.paint(
265
+ f"Unloaded {count} active library model(s); downloaded weights remain on disk",
266
+ "green",
267
+ "bold",
268
+ )
269
+ if count
270
+ else t.paint("No active library models were running", "green", "bold")
271
+ )
272
+ return 0
273
+ out(t.paint("Some library models could not be unloaded", "red", "bold"))
274
+ return 1
@@ -2,7 +2,7 @@
2
2
 
3
3
  The gate is the agent posture — a window of at least 64K for the
4
4
  posture's slots, weights and KV resident. Gated entries are ordered by ``quality.score``, which
5
- for scored entries is the installed SimplexAI score (docs/local-models/model-scoring.md),
5
+ for scored entries is the installed SimplexAI score,
6
6
  then by predicted decode speed; ``choose`` applies the user's scenario (``--prefer``).
7
7
  ``recommend`` and ``stack --llm auto`` both use this module; the catalog's fit and speed physics
8
8
  stay in ``catalog``.
@@ -32,7 +32,7 @@ from localmodels.plan_envelope import PlanError
32
32
  from localmodels.planning.budget import HARNESS_RAM, RAM_FLOOR, host_ram
33
33
  from localmodels.probe import HostFacts
34
34
 
35
- # Installed SimplexAI scores closer than this are a tie (model-scoring.md; AIHOT: 3 points or more
35
+ # Installed SimplexAI scores closer than this are a tie (AIHOT: 3 points or more
36
36
  # rarely swap): a challenger with another engine must beat the llama.cpp pick by at least this.
37
37
  TIE_BAND = 3
38
38
  # Scores within this band are statistically indistinguishable (AIHOT: under 1 point is a coin
@@ -113,7 +113,7 @@ MAC_DEFAULT_YIELD_SCORE = 50
113
113
  MAC_LADDER = ("ornith-1.5-9b", "spark-x2.6-4b-q4km")
114
114
  MAC_LADDER_FASTEST = ("spark-x2.6-4b-q4km", "ornith-1.5-9b")
115
115
  MAC_LADDER_MIN_BYTES = 16 * metal.GIB
116
- # Validated darwin entries the ladder replaces in automatic selection (decision 57): Ling-3.0-tiny
116
+ # Validated darwin entries the ladder replaces in automatic selection: Ling-3.0-tiny
117
117
  # (25) was the 32 GB+ fallback. Explicit --llm still installs it.
118
118
  MAC_LADDER_REPLACES = frozenset({"ling-3.0-tiny"})
119
119
 
@@ -135,7 +135,7 @@ class MacLadder:
135
135
 
136
136
 
137
137
  def mac_ladder(facts: HostFacts) -> MacLadder | None:
138
- """This Mac's ladder (decisions 57, 61 and 68), or None off Apple Silicon and below 16 GB."""
138
+ """This Mac's ladder, or None off Apple Silicon and below 16 GB."""
139
139
  if not metal.supported(facts) or facts["ram"]["total_bytes"] < MAC_LADDER_MIN_BYTES:
140
140
  return None
141
141
  return MacLadder(MAC_LADDER, MAC_LADDER_FASTEST)
@@ -154,7 +154,7 @@ def keeps_default(scores: Iterable[int]) -> bool:
154
154
 
155
155
  def listed_default(facts: HostFacts, fits: list[tuple[str, int]]) -> str | None:
156
156
  """The ladder rung to list first among ``(id, score)`` fits, or None once another fit
157
- reaches the yield score (decision 40) or no rung fits."""
157
+ reaches the yield score or no rung fits."""
158
158
  ladder = mac_ladder(facts)
159
159
  if ladder is None:
160
160
  return None
@@ -31,7 +31,7 @@ HOST_KEEP_BYTES = 2 * GIB
31
31
  # (total, working set). M4 16 GB and M6 24 GB read 74.0% (measured on Apple Silicon Macs); oMLX 0.7.4 records 107.5 GiB on a 128 GiB MacBook
32
32
  # (omlx/cluster/node_role.py); macOS 27 on the 256 GB M5 Ultra read 222.7 GiB (MT1). A simulated
33
33
  # Mac interpolates the share linearly in between; a real one uses its own probe reading, which
34
- # also shows a raised sysctl (local-119: 249036 MiB set, the same value read, 2026-11-09).
34
+ # also shows a raised sysctl (e.g. 249036 MiB set, the same value read on a 256 GB Mac).
35
35
  _DEFAULT_WORKING_SETS = (
36
36
  (16 * GIB, 12713115648),
37
37
  (24 * GIB, 19069665280),
@@ -44,7 +44,7 @@ RAISED_WIRED_FRACTION = 0.95
44
44
  # The environment every Metal llama-server gets: keep its residency set (weights, KV, compute
45
45
  # buffers) wired for a day of idling instead of upstream's few minutes. PIN1 (2026-11-09): by
46
46
  # default a 27B UD-IQ3_S server's 15.3 GiB of wired memory dropped to none about 226 s into idling
47
- # on local-119, and on a 24 GB Mac under desktop memory pressure 1.4 GiB of it was paged out while
47
+ # on macOS, and on a 24 GB Mac under desktop memory pressure 1.4 GiB of it was paged out while
48
48
  # idle; with this setting it stayed wired through 6 min idle and an 8 GiB incompressible hog that
49
49
  # pushed other apps 5-7 GiB into swap, and a short request's first token came in 1.5 s against
50
50
  # 2.8 s. --load-mode mmap+mlock added nothing measurable on top. Other apps take the swap instead.
@@ -58,8 +58,8 @@ RESERVE_MIN_BYTES = 3 * GIB
58
58
  RESERVE_MAX_BYTES = 8 * GIB
59
59
  # kern.memorystatus_vm_pressure_level: 1 normal, 2 warning, 4 critical. Under warning macOS is
60
60
  # already compressing, so a plan that fills the memory available can tip it into critical, where
61
- # it kills processes (a 73.4 GB plan against 73.8 GB available was aborted on local-119,
62
- # 2026-10-29). A shared Mac can sit at warning for hours with tens of GB free, so warning plans
61
+ # it kills processes (a 73.4 GB plan against 73.8 GB available was aborted under memory warning).
62
+ # A shared Mac can sit at warning for hours with tens of GB free, so warning plans
63
63
  # keep this share of the RAM available back instead of refusing.
64
64
  PRESSURE_NORMAL = 1
65
65
  PRESSURE_WARN = 2
@@ -388,7 +388,7 @@ def owned_bytes(facts: HostFacts) -> int:
388
388
  def foreign_cached_bytes(facts: HostFacts) -> int:
389
389
  """The file-cached weights of inference servers this tool does not own: an upstream server
390
390
  unwires its weights a few minutes into idling, and macOS then counts them as available.
391
- They are still that server's model (decision 43), so they are not free for a plan."""
391
+ They are still that server's model, so they are not free for a plan."""
392
392
  return sum(
393
393
  int(p.get("cached_bytes") or 0) for p in _metal_processes(facts) if p["owned"] is not True
394
394
  )
@@ -1,3 +1,2 @@
1
1
  """Memory and capacity pricing as pure functions: per-model memory by context length
2
- (``memcalc``, read by ``memcalc_load``) and weight size by device class (``sizecalc``).
3
- See docs/local-models/architecture.md#子包."""
2
+ (``memcalc``, read by ``memcalc_load``) and weight size by device class (``sizecalc``)."""
@@ -287,7 +287,7 @@ def idle_cards(facts: HostFacts, need_bytes: int) -> list[GPU]:
287
287
  return False
288
288
  # A Windows desktop always holds part of its card through WDDM contexts that are not
289
289
  # foreign work (foreign_work); up to the desktop baseline, with no inference server
290
- # there, the card is still idle (decision 60), and a Strata engine sizes itself from
290
+ # there, the card is still idle, and a Strata engine sizes itself from
291
291
  # what is free when it starts.
292
292
  taken = max(g["used_bytes"], g["total_bytes"] - g["free_bytes"])
293
293
  desktop = (