Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
85 lines
2.8 KiB
Python
85 lines
2.8 KiB
Python
"""The line between serving and acquiring.
|
|
|
|
Starting a model and serving an API never install, download or compile anything. Everything that
|
|
reaches the network or runs pip, git, cmake or a package manager lives behind an explicit command:
|
|
SETUP, UPDATE or `strata install`. This module is that line, in one place:
|
|
|
|
* `forbidden()` marks a stretch of code (a start, a serve) in which acquiring is not allowed;
|
|
* `require(what, command)` is called by every acquiring primitive (a download, a pip install, a
|
|
network probe, a compile) and raises `AcquisitionRefused` inside such a stretch;
|
|
* `AcquisitionRefused` is the typed error: it says what is missing and names the explicit command.
|
|
|
|
The environment variable `STRATA_NO_ACQUIRE=1` forbids acquiring for a whole process. A process
|
|
that serves (`strata serve`, `strata runtime start`, the API server) never imports the installer, so
|
|
for it this is a second line of defence, not the first.
|
|
|
|
Nothing here imports anything outside the standard library.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import contextlib
|
|
import os
|
|
import sys
|
|
import threading
|
|
|
|
ENV = "STRATA_NO_ACQUIRE"
|
|
|
|
_lock = threading.Lock()
|
|
_depth = 0
|
|
|
|
|
|
class AcquisitionRefused(RuntimeError):
|
|
"""Something would have been downloaded or installed during a start or a serve."""
|
|
|
|
code = "acquisition_refused"
|
|
exit_code = 5
|
|
|
|
def __init__(self, what: str, command: str | None = None):
|
|
self.what = what
|
|
self.command = command or explicit_commands()
|
|
super().__init__(
|
|
f"{what} is missing or out of date. Starting and serving never install or download "
|
|
f"anything. Run: {self.command}")
|
|
|
|
|
|
def explicit_commands() -> str:
|
|
"""The commands that acquire, named for this platform."""
|
|
if os.name == "nt":
|
|
return "SETUP.bat (first-time setup), UPDATE.bat (update) or `strata install`"
|
|
return "./setup.sh (first-time setup), ./update.sh (update) or `strata install`"
|
|
|
|
|
|
def is_forbidden() -> bool:
|
|
return _depth > 0 or os.environ.get(ENV, "").strip().lower() in ("1", "true", "yes", "on")
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def forbidden():
|
|
"""No acquisition inside this block. Nests."""
|
|
global _depth
|
|
with _lock:
|
|
_depth += 1
|
|
try:
|
|
yield
|
|
finally:
|
|
with _lock:
|
|
_depth -= 1
|
|
|
|
|
|
def require(what: str, command: str | None = None) -> None:
|
|
"""Call before acquiring `what`; raises AcquisitionRefused where acquiring is forbidden."""
|
|
if is_forbidden():
|
|
raise AcquisitionRefused(what, command)
|
|
|
|
|
|
def main_guard(fn, *, fail=None):
|
|
"""Run `fn()`; a refused acquisition becomes `fail(message, hint)` (or an exit-5 message)."""
|
|
try:
|
|
return fn()
|
|
except AcquisitionRefused as exc:
|
|
if fail is not None:
|
|
return fail(str(exc), None)
|
|
print(f"strata: {exc}", file=sys.stderr)
|
|
return exc.exit_code
|