@simplexai/localmodels-win32-x64 0.1.0-dev.103 → 0.1.0-dev.105
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.
- package/LICENSE +201 -0
- package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
- package/README.md +10 -0
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +159 -158
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +204 -86
- package/modules/localmodels/apple_sensors.py +23 -0
- package/modules/localmodels/approval.py +25 -2
- package/modules/localmodels/catalog.json +584 -158
- package/modules/localmodels/catalog.py +18 -3
- package/modules/localmodels/catalog_recipes.py +64 -6
- package/modules/localmodels/cli_help.py +10 -0
- package/modules/localmodels/cli_parser.py +313 -230
- package/modules/localmodels/component.py +21 -3
- package/modules/localmodels/console.py +1 -1
- package/modules/localmodels/context_policy.py +6 -5
- package/modules/localmodels/custom_probe.py +4 -2
- package/modules/localmodels/debug_cli.py +0 -12
- package/modules/localmodels/debug_mode.py +0 -6
- package/modules/localmodels/decode_calibration.json +3 -4
- package/modules/localmodels/decode_calibration.py +5 -2
- package/modules/localmodels/deploy.py +11 -1
- package/modules/localmodels/deployment_lifecycle.py +1 -1
- package/modules/localmodels/download-mirrors.json +1 -1
- package/modules/localmodels/engine_adapters/base.py +11 -1
- package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
- package/modules/localmodels/engine_adapters/suite_plan.py +61 -24
- package/modules/localmodels/engines-b11583.json +6 -26
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
- package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
- package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
- package/modules/localmodels/engines-strata-0.1.47.json +1 -5
- package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
- package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
- package/modules/localmodels/engines-whisper-b5454.json +6 -30
- package/modules/localmodels/engines.json +13 -61
- package/modules/localmodels/estimator.py +10 -5
- package/modules/localmodels/gpu_specs.py +1 -1
- package/modules/localmodels/host_sensors.py +25 -2
- package/modules/localmodels/hosts.py +38 -21
- package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
- package/modules/localmodels/library_cli.py +34 -16
- package/modules/localmodels/library_custom.py +9 -1
- package/modules/localmodels/library_direct.py +41 -1
- package/modules/localmodels/library_elastic.py +135 -6
- package/modules/localmodels/library_jobs.py +23 -4
- package/modules/localmodels/library_kept.py +9 -1
- package/modules/localmodels/library_model.py +174 -2
- package/modules/localmodels/library_order.py +175 -69
- package/modules/localmodels/library_poly.py +150 -21
- package/modules/localmodels/library_presentation.py +485 -0
- package/modules/localmodels/library_pricing.py +15 -4
- package/modules/localmodels/library_serve.py +342 -70
- package/modules/localmodels/library_smoke.py +63 -5
- package/modules/localmodels/library_state.py +48 -10
- package/modules/localmodels/library_status.py +37 -17
- package/modules/localmodels/llm_rank.py +22 -11
- package/modules/localmodels/metal.py +1 -2
- package/modules/localmodels/plan_envelope.py +40 -13
- package/modules/localmodels/planning/budget.py +14 -12
- package/modules/localmodels/planning/memory_pools.py +7 -1
- package/modules/localmodels/privacy_acceptance.py +6 -5
- package/modules/localmodels/probe.py +34 -7
- package/modules/localmodels/py.typed +0 -0
- package/modules/localmodels/quant_formats.py +10 -3
- package/modules/localmodels/recommend_cli.py +1 -1
- package/modules/localmodels/records.py +19 -2
- package/modules/localmodels/remote_ops_launchd.py +8 -1
- package/modules/localmodels/remote_ops_verify.py +91 -24
- package/modules/localmodels/runtime_index.py +303 -0
- package/modules/localmodels/runtime_process.py +1 -1
- package/modules/localmodels/service_deployment.py +2 -4
- package/modules/localmodels/service_probe.py +59 -13
- package/modules/localmodels/setup_inspection.py +94 -73
- package/modules/localmodels/setup_text.py +7 -56
- package/modules/localmodels/sidecar_downloads.py +34 -0
- package/modules/localmodels/sidecar_http.py +61 -5
- package/modules/localmodels/sidecar_state.py +52 -2
- package/modules/localmodels/speech_admission.py +20 -4
- package/modules/localmodels/speech_catalog.py +23 -0
- package/modules/localmodels/speech_cli.py +30 -16
- package/modules/localmodels/speech_jobs.py +42 -17
- package/modules/localmodels/speech_serve.py +9 -2
- package/modules/localmodels/speech_server.py +185 -81
- package/modules/localmodels/speech_state.py +4 -1
- package/modules/localmodels/speech_workers.py +11 -0
- package/modules/localmodels/stack.py +1 -1
- package/modules/localmodels/stack_args.py +276 -145
- package/modules/localmodels/stack_auto.py +91 -6
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_cleanup.py +21 -18
- package/modules/localmodels/stack_cli.py +120 -115
- package/modules/localmodels/stack_compose.py +16 -5
- package/modules/localmodels/stack_debug.py +15 -6
- package/modules/localmodels/stack_decision.py +4 -4
- package/modules/localmodels/stack_doctor.py +2 -2
- package/modules/localmodels/stack_down.py +2 -0
- package/modules/localmodels/stack_events.py +1 -1
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +17 -15
- package/modules/localmodels/stack_mcp.py +1 -2
- package/modules/localmodels/stack_mlx.py +8 -1
- package/modules/localmodels/stack_picks.py +20 -21
- package/modules/localmodels/stack_plan.py +12 -11
- package/modules/localmodels/stack_ports.py +31 -4
- package/modules/localmodels/stack_review.py +28 -7
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_run.py +1 -1
- package/modules/localmodels/stack_suite.py +72 -21
- package/modules/localmodels/stack_up.py +2 -0
- package/modules/localmodels/stack_view.py +180 -35
- package/modules/localmodels/stack_view_agent.py +1 -1
- package/modules/localmodels/stack_view_demo.py +2 -0
- package/modules/localmodels/stack_view_gpu.py +36 -2
- package/modules/localmodels/stack_view_schema.py +26 -3
- package/modules/localmodels/stack_view_serve.py +0 -2
- package/modules/localmodels/stack_view_slots.py +3 -1
- package/modules/localmodels/stack_view_telemetry.py +90 -4
- package/modules/localmodels/stack_view_tick.py +246 -40
- package/modules/localmodels/stack_view_words.py +9 -2
- package/modules/localmodels/stack_warm.py +2 -2
- package/modules/localmodels/stack_whatif.py +524 -41
- package/modules/localmodels/stack_whatif_html.py +900 -0
- package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
- package/modules/localmodels/strata_poly_server.py +114 -3
- package/modules/localmodels/suite.py +265 -6
- package/modules/localmodels/telemetry_math.py +458 -18
- package/modules/localmodels/transport.py +8 -1
- package/modules/localmodels/tts_admission.py +2 -17
- package/modules/localmodels/tts_catalog.py +29 -1
- package/modules/localmodels/tts_cli.py +45 -22
- package/modules/localmodels/tts_http.py +10 -4
- package/modules/localmodels/tts_jobs.py +49 -19
- package/modules/localmodels/tts_serve.py +9 -2
- package/modules/localmodels/tts_server.py +1 -1
- package/modules/localmodels/tts_sidecar.py +69 -28
- package/modules/localmodels/tts_state.py +7 -2
- package/modules/localmodels/vision.py +5 -3
- package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
- package/modules/localmodels/web/view/view.css +0 -1
- package/modules/localmodels/web/view/view.js +2 -5
- package/modules/localmodels/web/whatif/app.js +730 -0
- package/modules/localmodels/web/whatif/page.html +1172 -0
- package/modules/localmodels/web/whatif/sim.js +297 -0
- package/modules/localmodels/win_probe.py +89 -16
- package/modules/localmodels/windows_job.py +179 -11
- package/modules/simplex_localmodels-0.1.0.dev105.dist-info/METADATA +14 -0
- package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +151 -145
- package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/LICENSE +201 -0
- package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/NOTICE +126 -0
- package/package.json +11 -2
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
- package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
- package/modules/localmodels/stack_research.py +0 -716
- package/modules/localmodels/stack_research_demo.py +0 -125
- package/modules/localmodels/stack_research_plan.py +0 -146
- package/modules/localmodels/web/index.html +0 -2605
- package/modules/localmodels/web/sizecalc/app.js +0 -1306
- package/modules/localmodels/web/sizecalc/calc.js +0 -269
- package/modules/localmodels/web/sizecalc/page.html +0 -520
- package/modules/localmodels/web/view/logo-claude.svg +0 -3
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"""Atomic runtime index projection (``$LOCALMODELS_STATE/runtime-index.json``).
|
|
2
|
+
|
|
3
|
+
Provides a single, zero-Python-startup disk contract (``localmodels.runtime-index/v1``)
|
|
4
|
+
that external consumers (such as the Linger Go daemon) can read directly to discover
|
|
5
|
+
installed/loaded LLM models, loopback health/slots/metrics endpoints, ``pi_spec`` metadata,
|
|
6
|
+
and active speech/TTS sidecar endpoints.
|
|
7
|
+
|
|
8
|
+
Locking invariant: ``.runtime-index.lock`` is a strict leaf lock. Every state mutator first
|
|
9
|
+
commits its own authoritative state file (library model record or sidecar ``runtime.json``)
|
|
10
|
+
and then calls ``refresh()``, which acquires ``.runtime-index.lock``, re-reads all current
|
|
11
|
+
state files from disk, and atomically replaces ``runtime-index.json``. Concurrent writers
|
|
12
|
+
can therefore never overwrite newer state with a stale snapshot and cannot deadlock.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import datetime as dt
|
|
18
|
+
import json
|
|
19
|
+
import logging
|
|
20
|
+
import os
|
|
21
|
+
from collections.abc import Mapping
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any, Literal, TypedDict
|
|
24
|
+
|
|
25
|
+
from localmodels import (
|
|
26
|
+
__version__,
|
|
27
|
+
catalog,
|
|
28
|
+
hosts,
|
|
29
|
+
library_direct,
|
|
30
|
+
library_state,
|
|
31
|
+
speech_state,
|
|
32
|
+
tts_state,
|
|
33
|
+
)
|
|
34
|
+
from localmodels.library_model import PiSpec
|
|
35
|
+
from localmodels.library_state import Record
|
|
36
|
+
|
|
37
|
+
SCHEMA: Literal["localmodels.runtime-index/v1"] = "localmodels.runtime-index/v1"
|
|
38
|
+
_LOG = logging.getLogger("localmodels.runtime_index")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _ModelIndexRequired(TypedDict):
|
|
42
|
+
id: str
|
|
43
|
+
state: str
|
|
44
|
+
pool: str | None
|
|
45
|
+
engine: str | None
|
|
46
|
+
pi_model: str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ModelIndexEntry(_ModelIndexRequired, total=False):
|
|
50
|
+
base_url: str
|
|
51
|
+
health_url: str
|
|
52
|
+
slots_url: str | None
|
|
53
|
+
metrics_url: str | None
|
|
54
|
+
metrics_requires_auth: bool
|
|
55
|
+
api_key_file: str | None
|
|
56
|
+
pid_file: str | None
|
|
57
|
+
pi_spec: PiSpec
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class SidecarIndexEntry(TypedDict):
|
|
61
|
+
runtime_file: str
|
|
62
|
+
base_url: str
|
|
63
|
+
health_url: str
|
|
64
|
+
status_url: str
|
|
65
|
+
api_key_file: str | None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class SidecarsIndex(TypedDict):
|
|
69
|
+
speech: SidecarIndexEntry | None
|
|
70
|
+
tts: SidecarIndexEntry | None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class RuntimeIndex(TypedDict):
|
|
74
|
+
schema: Literal["localmodels.runtime-index/v1"]
|
|
75
|
+
updated_at: str
|
|
76
|
+
tool_version: str
|
|
77
|
+
models: list[ModelIndexEntry]
|
|
78
|
+
sidecars: SidecarsIndex
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def state_root(state_dir: Path | None = None) -> Path:
|
|
82
|
+
return hosts.state_dir() if state_dir is None else state_dir
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def index_path(state_dir: Path | None = None) -> Path:
|
|
86
|
+
return state_root(state_dir) / "runtime-index.json"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def lock_path(state_dir: Path | None = None) -> Path:
|
|
90
|
+
return state_root(state_dir) / ".runtime-index.lock"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _rfc3339_utc_now() -> str:
|
|
94
|
+
return dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _join_origin(base_url: str, path: str) -> str:
|
|
98
|
+
origin = base_url.rstrip("/").removesuffix("/v1")
|
|
99
|
+
suffix = path if path.startswith("/") else "/" + path
|
|
100
|
+
return origin + suffix
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _pi_model_of(record: Record) -> str:
|
|
104
|
+
if direct := record.get("pi_model"):
|
|
105
|
+
return str(direct)
|
|
106
|
+
if (reg := record.get("registration")) is not None and (pm := reg.get("pi_model")):
|
|
107
|
+
return str(pm)
|
|
108
|
+
plan = record["plan"]
|
|
109
|
+
served = str(plan["endpoint"].get("model") or plan["model"]["model_id"])
|
|
110
|
+
return library_direct.pi_model(record["id"], served)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _engine_of(record: Record, catalog_by_id: Mapping[str, catalog.CatalogEntry]) -> str | None:
|
|
114
|
+
plan = record["plan"]
|
|
115
|
+
launch_runtime = str(plan.get("launch", {}).get("runtime") or "")
|
|
116
|
+
build = str(plan.get("engine", {}).get("build") or "")
|
|
117
|
+
entry = catalog_by_id.get(record["catalog_id"])
|
|
118
|
+
runtime = launch_runtime or (entry.runtime if entry is not None else "")
|
|
119
|
+
if not runtime and isinstance(ce := record.get("catalog_entry"), Mapping):
|
|
120
|
+
runtime = str(ce.get("runtime") or "")
|
|
121
|
+
if runtime == "strata-poly" or build.startswith("strata-poly"):
|
|
122
|
+
return "polystrata"
|
|
123
|
+
if runtime == "strata" or build.startswith("strata"):
|
|
124
|
+
return "strata"
|
|
125
|
+
if runtime == "mlx-lm" or build.startswith("mlx-lm"):
|
|
126
|
+
return "mlx-lm"
|
|
127
|
+
if build or plan.get("engine", {}).get("binary"):
|
|
128
|
+
return "llama.cpp"
|
|
129
|
+
return None
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _loaded_endpoint_fields(
|
|
133
|
+
record: Record,
|
|
134
|
+
engine: str | None,
|
|
135
|
+
catalog_by_id: Mapping[str, catalog.CatalogEntry],
|
|
136
|
+
) -> dict[str, Any]:
|
|
137
|
+
plan = record["plan"]
|
|
138
|
+
ep = plan["endpoint"]
|
|
139
|
+
svc = plan["service"]
|
|
140
|
+
argv = [str(a) for a in (svc.get("argv") or ())]
|
|
141
|
+
base_url = str(ep.get("base_url") or "")
|
|
142
|
+
health_path = str(ep.get("health_path") or svc.get("health_path") or "/health")
|
|
143
|
+
if "slots_path" in ep:
|
|
144
|
+
slots_path = ep["slots_path"]
|
|
145
|
+
else:
|
|
146
|
+
slots_path = "/slots" if "--slots" in argv else None
|
|
147
|
+
if "metrics_path" in ep:
|
|
148
|
+
metrics_path = ep["metrics_path"]
|
|
149
|
+
else:
|
|
150
|
+
metrics_path = (
|
|
151
|
+
"/metrics" if (engine in ("polystrata", "strata") or "--metrics" in argv) else None
|
|
152
|
+
)
|
|
153
|
+
if "metrics_requires_auth" in ep:
|
|
154
|
+
metrics_requires_auth = bool(ep["metrics_requires_auth"])
|
|
155
|
+
else:
|
|
156
|
+
env = svc.get("env") or {}
|
|
157
|
+
keyed = (
|
|
158
|
+
"--api-key-file" in argv
|
|
159
|
+
or "STRATA_API_KEY" in env
|
|
160
|
+
or any("auth_proxy" in arg for arg in argv)
|
|
161
|
+
)
|
|
162
|
+
metrics_requires_auth = bool(metrics_path and keyed)
|
|
163
|
+
deploy_dir = str(svc.get("deploy_dir") or "")
|
|
164
|
+
expanded = Path(os.path.expanduser(deploy_dir)) if deploy_dir else None
|
|
165
|
+
return {
|
|
166
|
+
"base_url": base_url,
|
|
167
|
+
"health_url": _join_origin(base_url, health_path) if base_url else "",
|
|
168
|
+
"slots_url": _join_origin(base_url, slots_path) if (base_url and slots_path) else None,
|
|
169
|
+
"metrics_url": (
|
|
170
|
+
_join_origin(base_url, metrics_path) if (base_url and metrics_path) else None
|
|
171
|
+
),
|
|
172
|
+
"metrics_requires_auth": metrics_requires_auth,
|
|
173
|
+
"api_key_file": str(expanded / "api-key") if expanded is not None else None,
|
|
174
|
+
"pid_file": str(expanded / "server.pid") if expanded is not None else None,
|
|
175
|
+
"pi_spec": library_direct.pi_spec_for_record(record, catalog_by_id=catalog_by_id),
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _model_entry(
|
|
180
|
+
record: Record,
|
|
181
|
+
catalog_by_id: Mapping[str, catalog.CatalogEntry],
|
|
182
|
+
) -> ModelIndexEntry:
|
|
183
|
+
engine = _engine_of(record, catalog_by_id)
|
|
184
|
+
entry: ModelIndexEntry = {
|
|
185
|
+
"id": record["id"],
|
|
186
|
+
"state": record["state"],
|
|
187
|
+
"pool": record.get("pool") or None,
|
|
188
|
+
"engine": engine,
|
|
189
|
+
"pi_model": _pi_model_of(record),
|
|
190
|
+
}
|
|
191
|
+
if record["state"] == "loaded":
|
|
192
|
+
loaded = _loaded_endpoint_fields(record, engine, catalog_by_id)
|
|
193
|
+
entry["base_url"] = loaded["base_url"]
|
|
194
|
+
entry["health_url"] = loaded["health_url"]
|
|
195
|
+
entry["slots_url"] = loaded["slots_url"]
|
|
196
|
+
entry["metrics_url"] = loaded["metrics_url"]
|
|
197
|
+
entry["metrics_requires_auth"] = loaded["metrics_requires_auth"]
|
|
198
|
+
entry["api_key_file"] = loaded["api_key_file"]
|
|
199
|
+
entry["pid_file"] = loaded["pid_file"]
|
|
200
|
+
entry["pi_spec"] = loaded["pi_spec"]
|
|
201
|
+
return entry
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def _sidecar_entry(
|
|
205
|
+
runtime_file: Path,
|
|
206
|
+
record: Mapping[str, Any] | None,
|
|
207
|
+
status_path: str,
|
|
208
|
+
) -> SidecarIndexEntry | None:
|
|
209
|
+
if record is None or not record.get("running") or record.get("state") == "stopped":
|
|
210
|
+
return None
|
|
211
|
+
raw_url = record.get("base_url")
|
|
212
|
+
if not isinstance(raw_url, str) or not raw_url.strip():
|
|
213
|
+
return None
|
|
214
|
+
base = raw_url.strip().rstrip("/")
|
|
215
|
+
raw_key = record.get("key_file")
|
|
216
|
+
api_key_file = raw_key if isinstance(raw_key, str) and raw_key else None
|
|
217
|
+
return {
|
|
218
|
+
"runtime_file": str(runtime_file),
|
|
219
|
+
"base_url": base,
|
|
220
|
+
"health_url": f"{base}/health",
|
|
221
|
+
"status_url": f"{base}{status_path}",
|
|
222
|
+
"api_key_file": api_key_file,
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _load_catalog_by_id(records: list[Record]) -> dict[str, catalog.CatalogEntry]:
|
|
227
|
+
needs_catalog = any(
|
|
228
|
+
r["state"] == "loaded"
|
|
229
|
+
or (
|
|
230
|
+
not str(r["plan"].get("engine", {}).get("build") or "")
|
|
231
|
+
and not str(r["plan"].get("launch", {}).get("runtime") or "")
|
|
232
|
+
)
|
|
233
|
+
for r in records
|
|
234
|
+
)
|
|
235
|
+
if not needs_catalog:
|
|
236
|
+
return {}
|
|
237
|
+
try:
|
|
238
|
+
return {entry.id: entry for entry in catalog.load_catalog_file()}
|
|
239
|
+
except (OSError, ValueError):
|
|
240
|
+
return {}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def build(state_dir: Path | None = None) -> RuntimeIndex:
|
|
244
|
+
"""Build the ``localmodels.runtime-index/v1`` snapshot from current on-disk state."""
|
|
245
|
+
records = sorted(library_state.records(state_dir), key=lambda r: r["id"])
|
|
246
|
+
catalog_by_id = _load_catalog_by_id(records)
|
|
247
|
+
speech_entry = _sidecar_entry(
|
|
248
|
+
speech_state.runtime_path(state_dir),
|
|
249
|
+
speech_state.load_runtime_record(state_dir),
|
|
250
|
+
"/v1/speech/status",
|
|
251
|
+
)
|
|
252
|
+
tts_entry = _sidecar_entry(
|
|
253
|
+
tts_state.runtime_path(state_dir),
|
|
254
|
+
tts_state.load_runtime_record(state_dir),
|
|
255
|
+
"/v1/tts/status",
|
|
256
|
+
)
|
|
257
|
+
return {
|
|
258
|
+
"schema": SCHEMA,
|
|
259
|
+
"updated_at": _rfc3339_utc_now(),
|
|
260
|
+
"tool_version": __version__,
|
|
261
|
+
"models": [_model_entry(record, catalog_by_id) for record in records],
|
|
262
|
+
"sidecars": {
|
|
263
|
+
"speech": speech_entry,
|
|
264
|
+
"tts": tts_entry,
|
|
265
|
+
},
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def write(state_dir: Path | None = None) -> Path:
|
|
270
|
+
"""Atomically rebuild and persist ``$LOCALMODELS_STATE/runtime-index.json`` under leaf lock;
|
|
271
|
+
raises what reading the state or writing the file raised."""
|
|
272
|
+
with hosts.file_lock(lock_path(state_dir)):
|
|
273
|
+
snapshot = build(state_dir)
|
|
274
|
+
return hosts.save_private(index_path(state_dir), snapshot)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def refresh(state_dir: Path | None = None) -> Path | None:
|
|
278
|
+
"""``write``, after the caller committed its own state: the index is a projection of that
|
|
279
|
+
state, so a failure to rebuild it is logged and leaves the committed operation's outcome (and
|
|
280
|
+
any error it is about to raise) untouched. None: the index was not refreshed this time."""
|
|
281
|
+
try:
|
|
282
|
+
return write(state_dir)
|
|
283
|
+
except (OSError, ValueError, KeyError, TypeError) as exc:
|
|
284
|
+
reason = exc.strerror if isinstance(exc, OSError) and exc.strerror else ""
|
|
285
|
+
_LOG.warning(
|
|
286
|
+
"runtime-index.json not refreshed (%s%s)",
|
|
287
|
+
type(exc).__name__,
|
|
288
|
+
f": {reason}" if reason else "",
|
|
289
|
+
)
|
|
290
|
+
return None
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def load(state_dir: Path | None = None) -> RuntimeIndex | None:
|
|
294
|
+
"""Read ``runtime-index.json`` if present and valid; otherwise return ``None``."""
|
|
295
|
+
try:
|
|
296
|
+
raw = json.loads(index_path(state_dir).read_text(encoding="utf-8"))
|
|
297
|
+
except (OSError, ValueError):
|
|
298
|
+
return None
|
|
299
|
+
if not isinstance(raw, dict) or raw.get("schema") != SCHEMA:
|
|
300
|
+
return None
|
|
301
|
+
if not isinstance(raw.get("models"), list) or not isinstance(raw.get("sidecars"), dict):
|
|
302
|
+
return None
|
|
303
|
+
return raw # type: ignore[return-value]
|
|
@@ -77,7 +77,7 @@ _terminate_tree = terminate_tree
|
|
|
77
77
|
def await_group_exit(pgid: int, timeout: float = GROUP_EXIT_S) -> bool:
|
|
78
78
|
"""Wait until no process is left in the group. SIGKILL takes effect only when each member
|
|
79
79
|
next runs (a member in a system call finishes it first), so without this wait a probe could
|
|
80
|
-
return while its timed-out tree still writes files
|
|
80
|
+
return while its timed-out tree still writes files. True when the group is gone;
|
|
81
81
|
False after ``timeout`` (the caller goes on: the kill stays pending)."""
|
|
82
82
|
deadline = time.monotonic() + timeout
|
|
83
83
|
while True:
|
|
@@ -15,6 +15,7 @@ from localmodels import (
|
|
|
15
15
|
catalog,
|
|
16
16
|
component,
|
|
17
17
|
deploy,
|
|
18
|
+
deployment_lifecycle,
|
|
18
19
|
hosts,
|
|
19
20
|
metal,
|
|
20
21
|
probe,
|
|
@@ -136,10 +137,7 @@ def _binding(plan: Plan, key: str) -> dict[str, str]:
|
|
|
136
137
|
def healthy(record: FinishedRecord) -> bool:
|
|
137
138
|
rows = lifecycle.status_rows([record])
|
|
138
139
|
return bool(
|
|
139
|
-
rows
|
|
140
|
-
and rows[0]["ok"]
|
|
141
|
-
and rows[0]["state"] == "active"
|
|
142
|
-
and rows[0]["health"] in ("ok", "ready")
|
|
140
|
+
rows and rows[0]["ok"] and deployment_lifecycle.healthy(rows[0]["state"], rows[0]["health"])
|
|
143
141
|
)
|
|
144
142
|
|
|
145
143
|
|
|
@@ -31,7 +31,7 @@ import subprocess
|
|
|
31
31
|
import sys
|
|
32
32
|
import urllib.error
|
|
33
33
|
import urllib.request
|
|
34
|
-
from collections.abc import Callable, Sequence
|
|
34
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
35
35
|
from concurrent.futures import ThreadPoolExecutor
|
|
36
36
|
from pathlib import Path
|
|
37
37
|
|
|
@@ -322,16 +322,28 @@ def parse_darwin_ps(
|
|
|
322
322
|
its physical footprint) the part of it that is file cache. Python servers need their
|
|
323
323
|
module/script argument to identify the engine; no arguments or model paths are kept.
|
|
324
324
|
``parent`` gives a process's parent, for an engine its deployment's launcher started."""
|
|
325
|
-
|
|
325
|
+
entries: list[tuple[int, int, str, str]] = []
|
|
326
|
+
users: dict[int, str] = {}
|
|
326
327
|
for line in text.splitlines():
|
|
327
328
|
cols = line.split(None, 3)
|
|
328
329
|
if len(cols) != 4 or not cols[0].isdigit() or not cols[1].isdigit():
|
|
329
330
|
continue
|
|
330
331
|
pid, rss, user, comm = int(cols[0]), int(cols[1]), cols[2], cols[3].strip()
|
|
331
|
-
|
|
332
|
+
entries.append((pid, rss, user, comm))
|
|
333
|
+
users[pid] = user
|
|
334
|
+
args_cache: dict[int, str] = {}
|
|
335
|
+
|
|
336
|
+
def cached_args(pid: int) -> str:
|
|
337
|
+
if pid not in args_cache:
|
|
338
|
+
args_cache[pid] = args(pid)
|
|
339
|
+
return args_cache[pid]
|
|
340
|
+
|
|
341
|
+
found: list[dict[str, object]] = []
|
|
342
|
+
for pid, rss, user, comm in entries:
|
|
343
|
+
name, argv = _darwin_engine(comm, pid, cached_args)
|
|
332
344
|
if name is None:
|
|
333
345
|
continue
|
|
334
|
-
owned = user == me and _beside_deployment(argv, pid, parent)
|
|
346
|
+
owned = user == me and _beside_deployment(argv, pid, parent, cached_args, users, me)
|
|
335
347
|
row: dict[str, object] = {
|
|
336
348
|
"gpu_uuid": METAL_UUID,
|
|
337
349
|
"pid": pid,
|
|
@@ -381,23 +393,57 @@ def _receipt_pids(directory: str) -> set[int]:
|
|
|
381
393
|
return held
|
|
382
394
|
|
|
383
395
|
|
|
384
|
-
def
|
|
385
|
-
argv: Sequence[str], pid: int, parent: Callable[[int], int | None] | None = None
|
|
386
|
-
) -> bool:
|
|
387
|
-
"""A deployment's receipt names this process, or names its parent: a launcher in front of
|
|
388
|
-
the server (slot_cache.py) is the recorded process and the server is its child, as the
|
|
389
|
-
Linux check follows a process's ancestors to the recorded command (_posix_owned)."""
|
|
396
|
+
def _held_from_argv(argv: Sequence[str]) -> set[int]:
|
|
390
397
|
values = (arg.split("=", 1)[-1] for arg in argv[:256])
|
|
391
398
|
held: set[int] = set()
|
|
392
399
|
for directory in {os.path.dirname(v) for v in values if v[:1] == "/"}:
|
|
393
400
|
if os.path.isfile(directory + "/deployment.json"):
|
|
394
401
|
held |= _receipt_pids(directory)
|
|
402
|
+
return held
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _split_args(pid: int, args: Callable[[int], str]) -> list[str]:
|
|
406
|
+
try:
|
|
407
|
+
return shlex.split(args(pid))
|
|
408
|
+
except ValueError:
|
|
409
|
+
return []
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _beside_deployment(
|
|
413
|
+
argv: Sequence[str],
|
|
414
|
+
pid: int,
|
|
415
|
+
parent: Callable[[int], int | None] | None = None,
|
|
416
|
+
args: Callable[[int], str] | None = None,
|
|
417
|
+
users: Mapping[int, str] | None = None,
|
|
418
|
+
me: str = "",
|
|
419
|
+
) -> bool:
|
|
420
|
+
"""A deployment's receipt names this process, or names a verified same-user ancestor: a
|
|
421
|
+
launcher in front of the server (slot_cache.py, strata_poly_server.py) is the recorded
|
|
422
|
+
process and its engine/vision children (such as ``strata-vision``, whose argv carries only
|
|
423
|
+
model paths) inherit ownership from that recorded ancestor, matching ``_posix_owned``."""
|
|
424
|
+
held = _held_from_argv(argv)
|
|
395
425
|
if pid in held:
|
|
396
426
|
return True
|
|
397
|
-
if
|
|
427
|
+
if parent is None:
|
|
398
428
|
return False
|
|
399
|
-
|
|
400
|
-
|
|
429
|
+
seen = {pid}
|
|
430
|
+
cur = pid
|
|
431
|
+
for _ in range(16):
|
|
432
|
+
above = parent(cur)
|
|
433
|
+
if above is None or above <= 1 or above in seen:
|
|
434
|
+
return False
|
|
435
|
+
seen.add(above)
|
|
436
|
+
if users is not None and me and users.get(above) not in (None, me):
|
|
437
|
+
return False
|
|
438
|
+
if above in held:
|
|
439
|
+
return True
|
|
440
|
+
if args is not None:
|
|
441
|
+
ancestor_held = _held_from_argv(_split_args(above, args))
|
|
442
|
+
if above in ancestor_held:
|
|
443
|
+
return True
|
|
444
|
+
held |= ancestor_held
|
|
445
|
+
cur = above
|
|
446
|
+
return False
|
|
401
447
|
|
|
402
448
|
|
|
403
449
|
LIBPROC = "/usr/lib/libproc.dylib"
|