@simplexai/localmodels-win32-x64 0.1.0-dev.102 → 0.1.0-dev.104

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 (153) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +126 -0
  3. package/README.md +10 -0
  4. package/bootstrap.identity +1 -1
  5. package/bootstrap.sha256 +139 -121
  6. package/modules/localmodels/__init__.py +1 -1
  7. package/modules/localmodels/__main__.py +3 -1
  8. package/modules/localmodels/catalog.json +435 -127
  9. package/modules/localmodels/catalog.py +7 -3
  10. package/modules/localmodels/catalog_recipes.py +3 -3
  11. package/modules/localmodels/cli_parser.py +7 -3
  12. package/modules/localmodels/component.py +1 -1
  13. package/modules/localmodels/console.py +1 -1
  14. package/modules/localmodels/context_policy.py +6 -5
  15. package/modules/localmodels/debug_cli.py +0 -12
  16. package/modules/localmodels/debug_mode.py +0 -6
  17. package/modules/localmodels/debug_stub_server.py +280 -7
  18. package/modules/localmodels/decode_calibration.json +3 -4
  19. package/modules/localmodels/decode_calibration.py +5 -2
  20. package/modules/localmodels/deployment_lifecycle.py +1 -1
  21. package/modules/localmodels/download-mirrors.json +77 -1
  22. package/modules/localmodels/engine_adapters/base.py +11 -1
  23. package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
  24. package/modules/localmodels/engine_adapters/suite_plan.py +57 -20
  25. package/modules/localmodels/engines-b11583.json +6 -26
  26. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
  27. package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
  28. package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
  29. package/modules/localmodels/engines-speechcpp-v0.11.3.json +68 -0
  30. package/modules/localmodels/engines-strata-0.1.47.json +1 -5
  31. package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
  32. package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
  33. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
  34. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
  35. package/modules/localmodels/engines-whisper-b5454.json +6 -30
  36. package/modules/localmodels/engines.json +13 -61
  37. package/modules/localmodels/estimator.py +10 -5
  38. package/modules/localmodels/gpu_specs.py +1 -1
  39. package/modules/localmodels/hosts.py +12 -16
  40. package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
  41. package/modules/localmodels/library_elastic.py +135 -6
  42. package/modules/localmodels/library_kept.py +9 -1
  43. package/modules/localmodels/library_model.py +28 -1
  44. package/modules/localmodels/library_poly.py +109 -11
  45. package/modules/localmodels/library_pricing.py +12 -3
  46. package/modules/localmodels/library_serve.py +162 -75
  47. package/modules/localmodels/library_smoke.py +63 -5
  48. package/modules/localmodels/library_state.py +3 -2
  49. package/modules/localmodels/library_status.py +8 -1
  50. package/modules/localmodels/llm_rank.py +13 -8
  51. package/modules/localmodels/metal.py +1 -2
  52. package/modules/localmodels/plan_envelope.py +29 -11
  53. package/modules/localmodels/planning/budget.py +14 -12
  54. package/modules/localmodels/planning/memory_pools.py +7 -1
  55. package/modules/localmodels/privacy_acceptance.py +6 -5
  56. package/modules/localmodels/py.typed +0 -0
  57. package/modules/localmodels/quant_formats.py +1 -1
  58. package/modules/localmodels/recommend_cli.py +1 -1
  59. package/modules/localmodels/remote_ops_common.py +12 -2
  60. package/modules/localmodels/remote_ops_launchd.py +8 -1
  61. package/modules/localmodels/runtime_process.py +1 -1
  62. package/modules/localmodels/service_deployment.py +2 -4
  63. package/modules/localmodels/service_probe.py +59 -13
  64. package/modules/localmodels/setup_inspection.py +72 -70
  65. package/modules/localmodels/setup_text.py +7 -56
  66. package/modules/localmodels/sidecar_downloads.py +460 -0
  67. package/modules/localmodels/sidecar_http.py +452 -0
  68. package/modules/localmodels/sidecar_state.py +516 -0
  69. package/modules/localmodels/speech_admission.py +33 -4
  70. package/modules/localmodels/speech_catalog.py +23 -0
  71. package/modules/localmodels/speech_cli.py +10 -2
  72. package/modules/localmodels/speech_jobs.py +120 -384
  73. package/modules/localmodels/speech_server.py +187 -77
  74. package/modules/localmodels/speech_state.py +90 -454
  75. package/modules/localmodels/speech_workers.py +51 -162
  76. package/modules/localmodels/stack.py +18 -0
  77. package/modules/localmodels/stack_args.py +6 -6
  78. package/modules/localmodels/stack_auto.py +1 -1
  79. package/modules/localmodels/stack_aux_gpu.py +1 -1
  80. package/modules/localmodels/stack_cleanup.py +21 -18
  81. package/modules/localmodels/stack_cli.py +6 -2
  82. package/modules/localmodels/stack_compose.py +11 -4
  83. package/modules/localmodels/stack_debug.py +1 -2
  84. package/modules/localmodels/stack_decision.py +4 -4
  85. package/modules/localmodels/stack_doctor.py +2 -2
  86. package/modules/localmodels/stack_down.py +19 -14
  87. package/modules/localmodels/stack_events.py +1 -1
  88. package/modules/localmodels/stack_gpu_memory.py +1 -1
  89. package/modules/localmodels/stack_hardware.py +3 -3
  90. package/modules/localmodels/stack_mcp.py +1 -2
  91. package/modules/localmodels/stack_picks.py +1 -1
  92. package/modules/localmodels/stack_plan.py +9 -9
  93. package/modules/localmodels/stack_ports.py +32 -4
  94. package/modules/localmodels/stack_rollback.py +1 -1
  95. package/modules/localmodels/stack_run.py +1 -1
  96. package/modules/localmodels/stack_suite.py +61 -12
  97. package/modules/localmodels/stack_up.py +51 -1
  98. package/modules/localmodels/stack_view_agent.py +1 -1
  99. package/modules/localmodels/stack_view_serve.py +0 -2
  100. package/modules/localmodels/stack_view_words.py +2 -2
  101. package/modules/localmodels/stack_warm.py +2 -2
  102. package/modules/localmodels/stack_whatif.py +524 -41
  103. package/modules/localmodels/stack_whatif_html.py +903 -0
  104. package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
  105. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
  106. package/modules/localmodels/strata_poly_server.py +251 -3
  107. package/modules/localmodels/suite.py +137 -5
  108. package/modules/localmodels/tts-moss.txt +321 -0
  109. package/modules/localmodels/tts_admission.py +381 -0
  110. package/modules/localmodels/tts_backend_speechcpp.py +487 -0
  111. package/modules/localmodels/tts_catalog.py +279 -0
  112. package/modules/localmodels/tts_cli.py +352 -0
  113. package/modules/localmodels/tts_http.py +623 -0
  114. package/modules/localmodels/tts_jobs.py +526 -0
  115. package/modules/localmodels/tts_model.py +591 -0
  116. package/modules/localmodels/tts_moss_presets.json +1 -0
  117. package/modules/localmodels/tts_serve.py +451 -0
  118. package/modules/localmodels/tts_server.py +1 -1
  119. package/modules/localmodels/tts_sidecar.py +788 -0
  120. package/modules/localmodels/tts_state.py +400 -0
  121. package/modules/localmodels/tts_worker_kokoro.py +463 -0
  122. package/modules/localmodels/tts_worker_moss.py +748 -0
  123. package/modules/localmodels/tts_workers.py +696 -0
  124. package/modules/localmodels/vision.py +5 -3
  125. package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
  126. package/modules/localmodels/web/view/view.css +0 -1
  127. package/modules/localmodels/web/view/view.js +2 -5
  128. package/modules/localmodels/web/whatif/app.js +730 -0
  129. package/modules/localmodels/web/whatif/page.html +1172 -0
  130. package/modules/localmodels/web/whatif/sim.js +303 -0
  131. package/modules/localmodels/windows_job.py +179 -11
  132. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/METADATA +14 -0
  133. package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/RECORD +132 -109
  134. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/LICENSE +201 -0
  135. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/NOTICE +126 -0
  136. package/package.json +11 -2
  137. package/tool.json +1 -1
  138. package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
  139. package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
  140. package/modules/localmodels/stack_research.py +0 -716
  141. package/modules/localmodels/stack_research_demo.py +0 -125
  142. package/modules/localmodels/stack_research_plan.py +0 -146
  143. package/modules/localmodels/web/index.html +0 -2605
  144. package/modules/localmodels/web/sizecalc/app.js +0 -1306
  145. package/modules/localmodels/web/sizecalc/calc.js +0 -269
  146. package/modules/localmodels/web/sizecalc/page.html +0 -520
  147. package/modules/localmodels/web/view/logo-claude.svg +0 -3
  148. package/modules/localmodels/web/view/logo-codex.png +0 -0
  149. package/modules/simplex_localmodels-0.1.0.dev102.dist-info/METADATA +0 -9
  150. package/modules/simplex_localmodels-0.1.0.dev102.dist-info/licenses/NOTICE +0 -68
  151. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/WHEEL +0 -0
  152. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/entry_points.txt +0 -0
  153. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -28,6 +28,7 @@ from localmodels import (
28
28
  engines,
29
29
  frontend,
30
30
  http_local,
31
+ sidecar_http,
31
32
  speech_admission,
32
33
  speech_jobs,
33
34
  speech_state,
@@ -35,10 +36,39 @@ from localmodels import (
35
36
  windows_job,
36
37
  )
37
38
  from localmodels.probe import HostFacts
39
+ from localmodels.sidecar_http import (
40
+ GPU_OOM_SIGNATURES as GPU_OOM_SIGNATURES,
41
+ )
42
+ from localmodels.sidecar_http import (
43
+ WINDOWS_ABOVE_NORMAL_PRIORITY_CLASS as WINDOWS_ABOVE_NORMAL_PRIORITY_CLASS,
44
+ )
45
+ from localmodels.sidecar_http import (
46
+ WINDOWS_CREATE_NO_WINDOW as WINDOWS_CREATE_NO_WINDOW,
47
+ )
48
+ from localmodels.sidecar_http import (
49
+ WORKER_READY_TIMEOUT_S as WORKER_READY_TIMEOUT_S,
50
+ )
51
+ from localmodels.sidecar_http import (
52
+ WORKER_STOP_GRACE_S as WORKER_STOP_GRACE_S,
53
+ )
54
+ from localmodels.sidecar_http import (
55
+ ChildWatchdog as ChildWatchdog,
56
+ )
57
+ from localmodels.sidecar_http import (
58
+ SidecarWorkerError,
59
+ )
60
+ from localmodels.sidecar_http import (
61
+ is_gpu_oom_error as is_gpu_oom_error,
62
+ )
63
+ from localmodels.sidecar_http import (
64
+ stop_subprocess as stop_subprocess,
65
+ )
38
66
  from localmodels.speech_admission import DeviceDecision
39
67
  from localmodels.speech_catalog import SpeechModelSpec
40
68
  from localmodels.speech_model import EffectiveDevice, SpeechError
41
69
 
70
+ WorkerError = SidecarWorkerError
71
+
42
72
  SENSEVOICE_REQUIREMENTS = "speech-sv.txt"
43
73
  # Simplified-Chinese prompt injected ONLY when language == "zh" and speech is present.
44
74
  ZH_SIMPLIFIED_PROMPT = "\u4ee5\u4e0b\u662f\u666e\u901a\u8bdd\u7684\u53e5\u5b50\u3002"
@@ -50,33 +80,7 @@ _ZH_PROMPT_LEAD_RE = re.compile(rf"^(?:\s*{re.escape(ZH_SIMPLIFIED_PROMPT)})+\s*
50
80
  _ZH_PROMPT_TRAIL_RE = re.compile(rf"\s*(?:{re.escape(ZH_SIMPLIFIED_PROMPT)}\s*)+$")
51
81
  _LINE_BREAK_RE = re.compile(r"\s*\n\s*")
52
82
  SILENCE_RMS_THRESHOLD = 150.0 # int16 RMS noise floor (~-46.8 dBFS)
53
- WORKER_STOP_GRACE_S = 3.0 # whisper-server b5454 hangs on SIGTERM -> SIGKILL after 3s
54
- WORKER_READY_TIMEOUT_S = 60.0
55
83
  WORKER_REQUEST_TIMEOUT_S = 300.0
56
- WINDOWS_CREATE_NO_WINDOW = 0x08000000
57
-
58
- _POSIX_WATCHDOG_SH = (
59
- 'read _; kill -TERM "$0" 2>/dev/null; n=0; '
60
- 'while kill -0 "$0" 2>/dev/null && [ "$n" -lt 3 ]; do sleep 1; n=$((n+1)); done; '
61
- 'kill -KILL "$0" 2>/dev/null'
62
- )
63
- GPU_OOM_SIGNATURES: tuple[str, ...] = (
64
- "oom",
65
- "out of memory",
66
- "cuda",
67
- "cublas",
68
- "metal",
69
- "vulkan",
70
- "vkresult",
71
- "directml",
72
- "failed to allocate",
73
- "unable to allocate",
74
- "not enough memory",
75
- "insufficient memory",
76
- "bad_alloc",
77
- "kioreturnnomemory",
78
- "newbufferwithlength",
79
- )
80
84
 
81
85
  _BOUNDARY_RE = re.compile(r'boundary=(?:"([^"]+)"|([^;\s]+))', re.IGNORECASE)
82
86
  _DISPOSITION_PARAM_RE = re.compile(r'([a-zA-Z0-9_-]+)="([^"]*)"')
@@ -207,23 +211,6 @@ def normalize_whisper_language(raw: str) -> str:
207
211
  return _WHISPER_LANGUAGE_TO_ISO.get(cleaned, cleaned)
208
212
 
209
213
 
210
- class WorkerError(RuntimeError):
211
- """Raised when an isolated speech engine child fails to start or process audio."""
212
-
213
- def __init__(self, message: str, *, detail: str = "", exit_status: int | None = None) -> None:
214
- super().__init__(message)
215
- self.detail = detail or message
216
- # Set when the child exited on its own (before readiness or mid-request); a timeout or a
217
- # launch failure leaves it None. The sidecar uses it to spot deterministic crash loops.
218
- self.exit_status = exit_status
219
-
220
-
221
- def is_gpu_oom_error(message: str) -> bool:
222
- """Return True when ``message`` matches any known GPU or OOM failure signature."""
223
- lowered = message.lower()
224
- return any(sig in lowered for sig in GPU_OOM_SIGNATURES)
225
-
226
-
227
214
  def validate_wav_and_rms(data: bytes) -> tuple[float, float]:
228
215
  """Validate 16-bit mono PCM WAV bytes and return ``(duration_seconds, int16_rms)``."""
229
216
  samples, _rate, duration = speech_worker_sensevoice.read_pcm16_wav(data)
@@ -305,12 +292,7 @@ def build_multipart_body(
305
292
 
306
293
  def ensure_run_dir(state_dir: Path | None) -> Path:
307
294
  """Ensure ``$LOCALMODELS_STATE/speech/run`` exists with 0700 permissions."""
308
- path = speech_state.run_dir(state_dir)
309
- path.mkdir(parents=True, exist_ok=True)
310
- if os.name != "nt":
311
- with contextlib.suppress(OSError):
312
- path.chmod(0o700)
313
- return path
295
+ return speech_state.STORE.ensure_run_dir(state_dir)
314
296
 
315
297
 
316
298
  def whisper_argv(
@@ -424,69 +406,6 @@ def _resolve_qwen3_asr_paths(spec: SpeechModelSpec, base_dir: str) -> tuple[str,
424
406
  return str(conv), str(enc), str(dec), str(vocab.parent)
425
407
 
426
408
 
427
- class ChildWatchdog:
428
- """Binds a child worker's lifetime to this sidecar via POSIX pipe guard or Windows Job."""
429
-
430
- def __init__(self, proc: subprocess.Popen[bytes]) -> None:
431
- self._guard: subprocess.Popen[bytes] | None = None
432
- self._write_fd: int | None = None
433
- if sys.platform == "win32":
434
- handle = getattr(proc, "_handle", None)
435
- if isinstance(handle, int):
436
- windows_job.end_with_this_process(handle)
437
- return
438
- if os.name == "posix":
439
- read_fd, write_fd = os.pipe()
440
- try:
441
- self._guard = subprocess.Popen(
442
- ["/bin/sh", "-c", _POSIX_WATCHDOG_SH, str(proc.pid)],
443
- stdin=read_fd,
444
- stdout=subprocess.DEVNULL,
445
- stderr=subprocess.DEVNULL,
446
- )
447
- self._write_fd = write_fd
448
- except OSError:
449
- os.close(write_fd)
450
- finally:
451
- os.close(read_fd)
452
-
453
- def close(self) -> None:
454
- """Stop the POSIX watchdog before closing its pipe so it does not signal a reused PID."""
455
- if self._guard is not None:
456
- with contextlib.suppress(OSError):
457
- self._guard.kill()
458
- with contextlib.suppress(OSError, subprocess.TimeoutExpired):
459
- self._guard.wait(timeout=2.0)
460
- self._guard = None
461
- if self._write_fd is not None:
462
- with contextlib.suppress(OSError):
463
- os.close(self._write_fd)
464
- self._write_fd = None
465
-
466
-
467
- def stop_subprocess(
468
- proc: subprocess.Popen[bytes],
469
- watchdog: ChildWatchdog | None = None,
470
- *,
471
- grace_s: float = WORKER_STOP_GRACE_S,
472
- ) -> None:
473
- """Terminate ``proc`` with ``SIGTERM -> grace_s -> SIGKILL`` and release its watchdog."""
474
- try:
475
- if proc.poll() is None:
476
- with contextlib.suppress(OSError):
477
- proc.terminate()
478
- try:
479
- proc.wait(timeout=max(0.1, grace_s))
480
- except subprocess.TimeoutExpired:
481
- with contextlib.suppress(OSError):
482
- proc.kill()
483
- with contextlib.suppress(OSError, subprocess.TimeoutExpired):
484
- proc.wait(timeout=5.0)
485
- finally:
486
- if watchdog is not None:
487
- watchdog.close()
488
-
489
-
490
409
  @dataclass
491
410
  class WorkerHandle:
492
411
  """Live isolated engine child subprocess owned by ``SpeechSidecar``."""
@@ -526,34 +445,10 @@ def wait_worker_ready(
526
445
  timeout_s: float = WORKER_READY_TIMEOUT_S,
527
446
  ) -> None:
528
447
  """Wait until the child engine answers loopback HTTP 200 or exits early."""
529
- deadline = time.monotonic() + timeout_s
530
448
  paths = ("/health", "/") if engine == "whisper.cpp" else ("/health",)
531
- opener = http_local.no_proxy_opener(allow_redirects=False)
532
- while time.monotonic() < deadline:
533
- code = proc.poll()
534
- if code is not None:
535
- tail = ""
536
- with contextlib.suppress(OSError):
537
- tail = stderr_path.read_text(encoding="utf-8", errors="replace")[-1200:].strip()
538
- raise WorkerError(
539
- f"{engine} worker exited with status {code}",
540
- detail=tail or f"exit code {code}",
541
- exit_status=code,
542
- )
543
- for path in paths:
544
- req = urllib.request.Request(
545
- f"http://127.0.0.1:{port}{path}",
546
- headers={"Connection": "close"},
547
- method="GET",
548
- )
549
- try:
550
- with opener.open(req, timeout=1.0) as resp:
551
- if 200 <= getattr(resp, "status", 200) < 300:
552
- return
553
- except (urllib.error.URLError, OSError, http.client.HTTPException):
554
- continue
555
- time.sleep(0.1)
556
- raise WorkerError(f"{engine} worker did not become ready within {timeout_s:.0f}s")
449
+ sidecar_http.wait_worker_ready(
450
+ proc, port, engine, stderr_path, timeout_s=timeout_s, paths=paths
451
+ )
557
452
 
558
453
 
559
454
  def resolve_whisper_binary(
@@ -612,29 +507,23 @@ def _launch_worker_process(
612
507
  """Spawn, watchdog-bind, and health-check a worker child process."""
613
508
  run_cwd = ensure_run_dir(state_dir)
614
509
  stderr_path = run_cwd / f"worker-{spec.id}-{port}.stderr.log"
615
- kwargs: dict[str, Any] = {"cwd": str(run_cwd), "env": env}
616
- if sys.platform == "win32":
617
- kwargs["creationflags"] = WINDOWS_CREATE_NO_WINDOW
618
-
619
- with stderr_path.open("wb") as err_stream:
620
- try:
621
- proc = subprocess.Popen(
622
- argv,
623
- stdin=subprocess.DEVNULL,
624
- stdout=subprocess.DEVNULL,
625
- stderr=err_stream,
626
- **kwargs,
627
- )
628
- except OSError as exc:
629
- raise WorkerError(f"failed to launch {spec.engine} worker: {exc}") from None
630
-
631
- watchdog = ChildWatchdog(proc)
632
- try:
633
- wait_worker_ready(proc, port, spec.engine, stderr_path)
634
- except Exception:
635
- stop_subprocess(proc, watchdog)
636
- raise
637
-
510
+ paths = ("/health", "/") if spec.engine == "whisper.cpp" else ("/health",)
511
+ affinity_mask = (
512
+ windows_job.speech_affinity_mask()
513
+ if sys.platform == "win32" and decision.effective_device == "cpu"
514
+ else None
515
+ )
516
+ proc, watchdog = sidecar_http.launch_worker_subprocess(
517
+ argv,
518
+ env,
519
+ run_cwd,
520
+ stderr_path,
521
+ port,
522
+ spec.engine,
523
+ ready_paths=paths,
524
+ above_normal_priority=True,
525
+ affinity_mask=affinity_mask,
526
+ )
638
527
  return WorkerHandle(
639
528
  model_id=spec.id,
640
529
  engine=spec.engine,
@@ -46,6 +46,7 @@ from localmodels.stack_plan import (
46
46
  StackPlan,
47
47
  StackRecord,
48
48
  StackReplanError,
49
+ VramShortError,
49
50
  default_options,
50
51
  platform_error,
51
52
  )
@@ -247,6 +248,22 @@ WRONG_CODE = "the --approve value is not this plan's approval code"
247
248
  EDITED_PLAN = "the plan file was changed after it was saved: it no longer matches its approval code"
248
249
 
249
250
 
251
+ def _raise_if_vram_short(plan: StackPlan, replan: BaseException) -> None:
252
+ """A shared card with too little free VRAM now fails planning again before it fails the
253
+ check before start. Name it for what it is: the check's own VramShortError
254
+ (STACK_VRAM_INSUFFICIENT, with the free and required bytes), not STACK_REPLAN_FAILED, whose
255
+ only reason was in the text."""
256
+ check = hardware.shared_start_guard(plan["llm"], plan["options"], reserve_decision=True)
257
+ if check is None:
258
+ return
259
+ try:
260
+ check()
261
+ except VramShortError as short:
262
+ raise short from replan
263
+ except (PlanError, StackError, OSError):
264
+ return # the replan's own failure stands
265
+
266
+
250
267
  def apply(
251
268
  plan: StackPlan,
252
269
  approval: str,
@@ -283,6 +300,7 @@ def apply(
283
300
  else build(plan["options"], approved=plan)
284
301
  )
285
302
  except (PlanError, StackError) as exc:
303
+ _raise_if_vram_short(plan, exc)
286
304
  raise StackReplanError(
287
305
  f"planning again from this computer's current state failed: {exc}. "
288
306
  "This computer changed, or the plan was made on another machine or "
@@ -66,7 +66,7 @@ GROUPS = (
66
66
  )
67
67
  STACK = """\
68
68
  Plan, install and run the local agent stack on this computer: the smartest LLM that fits,
69
- a gateway (Bifrost by default) and the pi agent. A GPU decision model, embedding/reranker/STT
69
+ served locally over loopback OpenAI-compatible endpoints. A GPU decision model, embedding/reranker/STT
70
70
  and TTS are optional and off by default (--decision, --aux, --tts).
71
71
  Nothing is downloaded or started until you approve a saved plan.
72
72
 
@@ -186,7 +186,7 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
186
186
  "--prefer",
187
187
  choices=PREFERENCES,
188
188
  default="smartest",
189
- help="what auto optimizes (roadmap decision 26): smartest, the highest installed "
189
+ help="what auto optimizes: smartest, the highest installed "
190
190
  "SimplexAI score that fits (default), except that a Mac of 16 GB or more takes its "
191
191
  "Spark-X2.6 ladder while no validated model scoring 50 fits, and Windows NVIDIA falls "
192
192
  "back to Spark-X2.6-4B Q8_0 when no validated model fits; concurrent, at least two "
@@ -199,7 +199,7 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
199
199
  "--route",
200
200
  choices=["none", "fastest"],
201
201
  action=cli_help.ComponentSelection,
202
- help="add the fastest LLM for easy turns (Bifrost and a decision model required)",
202
+ help="add the fastest LLM for easy turns (a decision model is required)",
203
203
  )
204
204
  decide.add_arguments(choose)
205
205
  stack_suite.add_arguments(choose)
@@ -207,7 +207,7 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
207
207
  "--vision",
208
208
  choices=vision.READERS,
209
209
  default=vision.DEFAULT,
210
- help="image input for an LLM that reads pictures (roadmap decision 31): auto puts the "
210
+ help="image input for an LLM that reads pictures: auto puts the "
211
211
  "picture reader on a GPU of 23.5 GiB or more and on the CPU below that (default); gpu, "
212
212
  "cpu, or off for text only",
213
213
  )
@@ -254,8 +254,8 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
254
254
  type=_budget,
255
255
  default=REASONING_BUDGET,
256
256
  metavar="TOKENS",
257
- help="the most tokens one reply may think before it must answer (default 8192, roadmap "
258
- "decision 37; 0 or off: no cap)",
257
+ help="the most tokens one reply may think before it must answer (default 8192, "
258
+ "0 or off: no cap)",
259
259
  )
260
260
  fit.add_argument(
261
261
  "--suite-memory",
@@ -74,7 +74,7 @@ def strata_parts(
74
74
  ) -> Parts | None:
75
75
  """The best validated Strata recipe whose installed SimplexAI score beats the llama.cpp
76
76
  pick by at least llm_rank.TIE_BAND and that fits this host, priced as if ``--llm`` named
77
- it (roadmap decisions 26 and 33: Strata keeps the experts in RAM, so a 24 GB card with 64 GB runs
77
+ it (Strata keeps the experts in RAM, so a 24 GB card with 64 GB runs
78
78
  Flash-Next). None leaves the choice to llama.cpp; why each better recipe was passed over is
79
79
  added to ``passed_over`` for the llama.cpp plan's warnings.
80
80
 
@@ -1,4 +1,4 @@
1
- """Which stack auxiliaries run on the LLM's GPU (roadmap decision 21: embedding and reranker on
1
+ """Which stack auxiliaries run on the LLM's GPU (embedding and reranker on
2
2
  the GPU when they fit, else the CPU).
3
3
 
4
4
  The decision model is placed first (2026-10-30 product decision: decision index before GPU
@@ -3,7 +3,7 @@
3
3
  An uninstall leaves nothing behind but what was downloaded and verified (the model files and
4
4
  the tool and engine archives, so the next install needs no download), the owned manifest that
5
5
  lists them (so ``--purge`` can delete them later) and the permanent empty lock files
6
- (``tools/owned.lock``, WHI-317, and ``engines/.engine.lock``, WHI-759). stack_lifecycle.remove stops and removes the
6
+ (``tools/owned.lock`` and ``engines/.engine.lock``). stack_lifecycle.remove stops and removes the
7
7
  services, the gateway and the tools; ``sweep`` then deletes what only the stack used: the
8
8
  engines its deployments ran that no remaining record names (with their download archives), the
9
9
  saved stack plans with their run records, the cached host facts, and the tool's own directories
@@ -29,7 +29,7 @@ Out = Callable[[str], None]
29
29
  # State this tool writes for a stack and nothing else reads: saved plans, run records, the
30
30
  # apply lock and journal (stacks/), the cached probe (facts/), the view window's profile,
31
31
  # measured per-device decode speeds (warm_speeds.json), and the blind Elo board (arena.json;
32
- # its empty arena.lock stays per WHI-317).
32
+ # its empty arena.lock stays).
33
33
  STACK_STATE = ("stacks", "facts", "view-app", "warm_speeds.json", "arena.json")
34
34
 
35
35
 
@@ -204,8 +204,7 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
204
204
  this tool keeps in the tools directory goes too (another user's files stay where they are),
205
205
  then the tool's own directories (OWN_DIRS) left empty and each base directory left empty.
206
206
  A directory someone else made there stays, empty or not. The manifest's empty
207
- ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
208
- .agents/skills/owned-manifest-lock), and ``engines/.engine.lock`` stays for the same reason (WHI-759, ``remote_ops_mirrors.engine_lock``)."""
207
+ ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock", and ``engines/.engine.lock`` stays for the same reason (``remote_ops_mirrors.engine_lock``)."""
209
208
  root = Path(hosts.tools_dir(tools_dir)).expanduser()
210
209
  private = root.resolve() / "gateway-home"
211
210
  if not hosts.owned_path(tools_dir).exists() and private.is_dir():
@@ -244,13 +243,6 @@ def finish(
244
243
  return 0
245
244
 
246
245
 
247
- def _same_place(a: str, b: str) -> bool:
248
- def norm(p: str) -> str:
249
- return os.path.normcase(os.path.normpath(os.path.expanduser(p)))
250
-
251
- return norm(a) == norm(b)
252
-
253
-
254
246
  def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
255
247
  """The manifest as an uninstall reads it. Each of the stack's deployments is taken from its
256
248
  own record in this state directory: one the manifest does not list yet is added, and one
@@ -259,15 +251,26 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
259
251
  run), and the manifest keeps one entry per name: on home-win a stale entry named a
260
252
  temporary directory, so the uninstall "removed" that and dropped the record of the search
261
253
  server that was running (2026-11-12). The other directory is left alone. ``dry_run`` keeps
262
- the correction in memory."""
254
+ the correction in memory.
255
+
256
+ An adopted entry's phase is its record's (``deployment_lifecycle.advance``): a failed or
257
+ interrupted deploy is adopted FAILED, not LIVE, so an uninstall that stops halfway never
258
+ leaves a failed deployment holding its port, unit and name against a live one."""
263
259
  doc = hosts.load_owned()
264
260
  for record in hosts.records(hosts.LOCAL_ID):
265
261
  plan = record["plan"]
266
262
  name, entry = plan["name"], doc["deployments"].get(plan["name"])
267
263
  if name not in members:
268
264
  continue
269
- if entry is not None and _same_place(entry["deploy_dir"], plan["service"]["deploy_dir"]):
265
+ if entry is not None and deployment_lifecycle.same_dir(
266
+ entry["deploy_dir"], plan["service"]["deploy_dir"]
267
+ ):
270
268
  continue
269
+ event = (
270
+ deployment_lifecycle.Event.DEPLOYED
271
+ if record["ok"]
272
+ else deployment_lifecycle.Event.DEPLOY_FAILED
273
+ )
271
274
  if entry is not None:
272
275
  out(
273
276
  f"- {name}: the manifest named another directory ({entry['deploy_dir']}); this "
@@ -275,13 +278,13 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
275
278
  )
276
279
  # Keep the other directory's manifest entry untouched on disk; remove acts on this
277
280
  # installation's own record in memory only.
278
- doc["deployments"][name] = hosts.owned_entry(plan)
281
+ deployment_lifecycle.advance(doc["deployments"], name, event, hosts.owned_entry(plan))
279
282
  continue
280
283
  if dry_run:
281
- doc["deployments"][name] = hosts.owned_entry(plan)
282
- else:
283
- hosts.own_deployment(plan)
284
- doc = hosts.load_owned()
284
+ deployment_lifecycle.advance(doc["deployments"], name, event, hosts.owned_entry(plan))
285
+ continue
286
+ hosts.own_deployment(plan, ok=record["ok"], adopt=True)
287
+ doc = hosts.load_owned()
285
288
  return doc
286
289
 
287
290
 
@@ -36,6 +36,7 @@ from localmodels import (
36
36
  stack_view_hub_cli,
37
37
  stack_warm,
38
38
  stack_whatif,
39
+ stack_whatif_html,
39
40
  )
40
41
  from localmodels import stack_decision as decide
41
42
  from localmodels import stack_doctor as day2_mod
@@ -84,9 +85,9 @@ def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None
84
85
  _WAITS = {
85
86
  "status": "Reading each deployment's state and health check…",
86
87
  "verify": "Sending acceptance requests to the running stack…",
87
- "doctor": "Checking services, ports, gateway and tools…",
88
+ "doctor": "Checking services, ports, GPU memory and disk…",
88
89
  "up": "Starting services that are not running and waiting for health checks…",
89
- "down": "Stopping the gateway and the stack's services…",
90
+ "down": "Stopping the stack's services…",
90
91
  }
91
92
 
92
93
 
@@ -220,6 +221,7 @@ _PLAN_ERROR_CODES = frozenset(
220
221
  "DISK_INSUFFICIENT",
221
222
  "GPU_CONFLICT",
222
223
  "PORT_PROBE_FAILED",
224
+ "PORTS_IN_USE",
223
225
  }
224
226
  )
225
227
  _SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
@@ -286,6 +288,8 @@ def run_cli(
286
288
  if args.stack_command == "memory":
287
289
  return stack_memory.cli(args)
288
290
  if args.stack_command == "what-if":
291
+ if getattr(args, "html", None):
292
+ return stack_whatif_html.cli_html(args)
289
293
  return stack_whatif.cli(args)
290
294
  facts = (
291
295
  decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
@@ -47,7 +47,7 @@ from localmodels import stack_gpu_memory as gpu_memory
47
47
  from localmodels import stack_hardware as hardware
48
48
  from localmodels.approval import digest
49
49
  from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
50
- from localmodels.plan_envelope import PlanError, require_free_port, utc_now
50
+ from localmodels.plan_envelope import PlanError, ports_assumed_free, require_free_port, utc_now
51
51
  from localmodels.planning import llm_ram
52
52
  from localmodels.planning.budget import gib, host_ram
53
53
  from localmodels.probe import HostFacts
@@ -117,6 +117,10 @@ def _native_owned(plan: Plan, port: int) -> bool:
117
117
  return False
118
118
 
119
119
 
120
+ def _no_listener(_port: int) -> bool:
121
+ return False
122
+
123
+
120
124
  def compose(
121
125
  facts: HostFacts,
122
126
  options: StackOptions,
@@ -137,9 +141,12 @@ def compose(
137
141
  ) -> StackPlan:
138
142
  """The whole-stack plan from facts read now. Pure apart from the Hub lookups in resolver and
139
143
  the local lookups each keyword stands for (tests replace them); who holds a GPU comes from
140
- the facts' service discovery alone, so saved facts price the host they describe."""
144
+ the facts' service discovery alone, so saved facts price the host they describe. Under
145
+ plan_envelope.assume_ports_free no port is in use."""
141
146
  options = options.copy()
142
147
  owned_ram = cache(owned_ram)
148
+ if ports_assumed_free():
149
+ listening = _no_listener
143
150
  stack_route.validate(options, facts)
144
151
  if error := platform_error(facts["platform"], options.get("profile"), facts["arch"]):
145
152
  raise StackError(error)
@@ -299,7 +306,7 @@ def _llama_quality(
299
306
 
300
307
  def agent_posture(options: StackOptions) -> AgentPosture:
301
308
  """The stack's agent posture with the operator's slot count. One slot is allowed since
302
- roadmap decision 26 (the smartest model does not have to serve two requests at once);
309
+ default policy (the smartest model does not have to serve two requests at once);
303
310
  ``--prefer concurrent`` keeps decision 13's two. Images are on unless the plan says
304
311
  otherwise (decision 31); a plan saved before ``--vision`` existed stays text-only. The
305
312
  thinking cap and ``--context``'s window ceiling come from the plan (decision 37)."""
@@ -459,7 +466,7 @@ def _llama_parts(
459
466
  its full size, the LLM is planned again without it (``draft=False``)."""
460
467
  posture = agent_posture(options)
461
468
  if min_prompt_cache or not draft:
462
- # WHI-898: capacity plans for blocked-now hosts price minimum required RAM, not
469
+ # Capacity plans for blocked-now hosts price minimum required RAM, not
463
470
  # optional accelerators that greedily expand into synthetic idle memory.
464
471
  posture = replace(posture, draft="off")
465
472
  aux_notes: list[str] = []
@@ -2,8 +2,7 @@
2
2
 
3
3
  ``stack plan`` normally chooses these itself (the agent posture's KV order, the catalog entry's
4
4
  last variant). For local testing and debugging an operator may pin them; the window and the
5
- thinking cap are product options already (``--context``, ``--reasoning-budget``, roadmap
6
- decision 37). The overrides are plan options, so the approval id binds them and
5
+ thinking cap are product options already (``--context``, ``--reasoning-budget``). The overrides are plan options, so the approval id binds them and
7
6
  ``stack apply`` re-plans with them; they are still priced: a pinned KV pair or variant that does
8
7
  not fit is refused, never lowered or spilled. They need ``--llm`` naming a llama.cpp model:
9
8
  ``auto`` might pick a Strata recipe, which has its own launch, and naming the model keeps the
@@ -1,6 +1,6 @@
1
1
  """Which decision model the stack runs, and on which card.
2
2
 
3
- A decision model only runs on a GPU (AGENTS.md). In the llama.cpp branch ``choose`` ranks every
3
+ A decision model only runs on a GPU. In the llama.cpp branch ``choose`` ranks every
4
4
  catalog model's measured tiers by quality inside the decision VRAM budget and takes the best one
5
5
  with which the LLM, priced again with that VRAM held back, neither spills nor loses window. An
6
6
  explicit ``--decision-vram`` takes the best tier in that budget as it is, spill included. The plan
@@ -106,7 +106,7 @@ def priced(facts: HostFacts, card: GPU, reserve: int, llm: Plan, price_llm: Pric
106
106
  def keeps(llm: Plan, again: Plan) -> bool:
107
107
  """The re-priced LLM still runs beside the tier. In agent posture an optional decision
108
108
  model may not cost the LLM its preferred window (128K, or what it reached alone when that
109
- was less), its slots or its MTP (roadmap decision 26: the LLM is the product, the decision
109
+ was less), its slots or its MTP (the LLM is the product, the decision
110
110
  model an add-on); a default plan keeps the old rule — no spill and no lost window."""
111
111
  if again["launch"].get("posture") == "agent":
112
112
  # MTP, where the LLM had it alone, is part of what a tier may not take away: the
@@ -615,7 +615,7 @@ def listing() -> str:
615
615
  lines.append(
616
616
  "Decision models only run on a GPU, on the LLM's card; stack plan picks by measured "
617
617
  "quality by default, --decision <id> picks another, --decision-vram <GiB> sets the VRAM "
618
- "budget. Data measured on lab-12021 RTX 4090 D"
618
+ "budget. Reference timings measured on an RTX 4090 D"
619
619
  )
620
620
  return "\n".join(lines)
621
621
 
@@ -705,7 +705,7 @@ def add_arguments(plan: argparse._ActionsContainer) -> None:
705
705
  action=cli_help.ComponentSelection,
706
706
  default="none",
707
707
  metavar="ID|auto|none",
708
- help="optional decision model: none (the default since roadmap decision 26: only the "
708
+ help="optional decision model: none (default: only the "
709
709
  "LLM is installed), an id from `stack decisions`, or auto (highest measured quality on "
710
710
  "the LLM's card, any license; the plan lists the others as options)",
711
711
  )
@@ -153,7 +153,7 @@ def _service(component: str, part: Plan) -> Finding:
153
153
  plan = record["plan"]
154
154
  row = lifecycle.status_rows([record])[0]
155
155
  port, log = plan["service"]["port"], f"{plan['service']['deploy_dir']}/server.log"
156
- if row["state"] == "active" and row["health"] in ("ok", "ready"):
156
+ if deployment_lifecycle.healthy(row["state"], row["health"]):
157
157
  return finding(check, "pass", f"{name} running, 127.0.0.1:{port} health {row['health']}")
158
158
  if row["state"] == "active" and row["health"] == "loading":
159
159
  return finding(
@@ -295,7 +295,7 @@ def _proxy(env: dict[str, str]) -> Finding | None:
295
295
  "host.proxy",
296
296
  "warn",
297
297
  f"{', '.join(names)} set, but NO_PROXY lacks 127.0.0.1 and localhost: "
298
- "clients may reach the local gateway through the proxy",
298
+ "clients may reach the local model servers through the proxy",
299
299
  'export NO_PROXY="127.0.0.1,localhost${NO_PROXY:+,$NO_PROXY}" (add it to your shell profile)',
300
300
  )
301
301