Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(serve): GET /health answered deployment internals without the bearer (#812)
Nandakishor2391478bdc4c
diff --git a/docs/http-api.md b/docs/http-api.mdindex c3fa6bf0..a010fd1b 100644--- a/docs/http-api.md+++ b/docs/http-api.md@@ -44,8 +44,13 @@ For containers, including CUDA and ARM64 images, see [Docker quickstart](docker.### `GET /health`-Always open (no auth), and stays responsive during inference because the CPU-bound forward pass-runs on its own worker, not the event loop.+Liveness is always open (no auth), and stays responsive during inference because the CPU-bound+forward pass runs on its own worker, not the event loop. The fields below liveness are not open on+a deployment that set `LAYA_API_KEY`: without the bearer, `/health` answers `{"status": "ok"}` and+nothing else, because the rest names resident checkpoints, their exact revision SHAs, the device+state and each checkpoint's last fallback reason, which quotes host hardware. A probe needs only+the 200, so a healthcheck is unaffected and a wrong bearer is still a 200 rather than a 401. With+no `LAYA_API_KEY` set, every caller gets the full payload shown here.```json{"status": "ok", "loaded": ["english", "multilingual"], "revisions": {"english": "...", "multilingual": "..."},diff --git a/laya/serve.py b/laya/serve.pyindex 799d78f1..e2175651 100644--- a/laya/serve.py+++ b/laya/serve.py@@ -76,6 +76,14 @@ MAX_TOTAL_OPTIONS = 512# before inference, so without a bound many concurrent near-cap requests OOM# the worker even though every request is individually valid (#330).DEFAULT_MAX_CONCURRENT = 16++# What `GET /health` answers an unauthenticated caller when `LAYA_API_KEY` is set. Liveness is+# the half of that endpoint a container probe needs and the half the page promises is always+# open; the rest of the payload names checkpoints, revision SHAs and host device state, so it+# is for a caller who can authenticate. A deployment with no key set gets the full payload, as+# it always has. Kept a module constant rather than a dict literal in the handler so the field+# contract in tests/test_serve.py still reads the full payload off `health()`'s own `return`.+LIVENESS_ONLY = {"status": "ok"}# Server-side ceiling on per-request max_len/head_max_len token budget overrides.DEFAULT_MAX_TOKEN_BUDGET = 8192@@ -728,20 +736,33 @@ def create_app(router: Optional[Any] = None):# client can send now answers 401.expected_auth = ("Bearer " + api_key).encode("utf-8", "surrogateescape") if api_key else b""- def _check_auth(authorization: Optional[str]) -> None:+ def _authorized(authorization: Optional[str]) -> bool:+ """Whether this request carries the configured bearer. True when no key is set."""if api_key is None:- return+ return Truesupplied = (authorization or "").encode("utf-8", "surrogateescape")- if not hmac.compare_digest(supplied, expected_auth):+ return hmac.compare_digest(supplied, expected_auth)++ def _check_auth(authorization: Optional[str]) -> None:+ if not _authorized(authorization):raise HTTPException(status_code=401, detail="invalid or missing bearer token")@app.get("/health")- def health() -> Dict[str, Any]:+ def health(authorization: Optional[str] = Header(default=None)) -> Dict[str, Any]:# `device` is where a resident checkpoint really computes, not what was asked for:# `Agent.device` reflects the silent GPU -> CPU fallback, so a container that asked# for a GPU it did not get says so. With nothing resident it is the configured# preference, and `device_is_preference` tells the reader which of the two it is# looking at. Same convention, and the same three keys, as `laya_status` over MCP.+ # Liveness stays open, because every shipped probe reads it without a credential+ # (compose.http.yaml's healthcheck, the Docker HEALTHCHECK, a k8s liveness probe) and+ # the page promises as much. What is not open on a locked-down deployment is the detail+ # below it: resident checkpoint names, their exact revision SHAs, the device state and+ # each checkpoint's last fallback reason, which quotes host hardware. An unauthenticated+ # caller gets the status and nothing else (#812).+ if not _authorized(authorization):+ return LIVENESS_ONLY+checkpoint_devices: Dict[str, str] = {}for name in (router.loaded or []):device = agent_device(router_agent(router, name))diff --git a/tests/test_serve.py b/tests/test_serve.pyindex 6184d290..89bcbf8f 100644--- a/tests/test_serve.py+++ b/tests/test_serve.py@@ -2169,6 +2169,54 @@ def test_batch_controls_combine_on_one_call(monkeypatch):for item in requests:assert item["task"] == "typed-decisions"assert item["max_len"] == 128+def test_health_liveness_is_open_but_the_detail_needs_the_bearer(monkeypatch):+ """#812: `/health` answered deployment internals to an unauthenticated caller.++ `POST /v1/systemone` was gated and `GET /health` was not, so on a server the operator had+ locked down with `LAYA_API_KEY` anyone could read the resident checkpoint names, each one's+ exact Hugging Face revision SHA, the device state, and `last_fallback_reason`, which quotes+ host hardware ("GPU 0 total 8.00 GiB"). Reconnaissance rather than a data path, but it is+ exactly the inventory you would want before targeting a revision.++ Requiring the bearer outright was not the fix: `compose.http.yaml`'s healthcheck, the Docker+ HEALTHCHECK and any k8s liveness probe all read this endpoint with no credential, and+ docs/http-api.md promises it is always open. So liveness stays open and the detail does not.+ """+ from fastapi.testclient import TestClient++ monkeypatch.setenv("LAYA_API_KEY", "s3cret")+ client = TestClient(create_app(router=FakeRouter()))++ # a probe with no credential still gets its 200, which is all a healthcheck reads+ anonymous = client.get("/health")+ assert anonymous.status_code == 200+ assert anonymous.json() == {"status": "ok"}++ # and the same for a wrong bearer: still live, still no detail, and not a 401, because a+ # probe that starts failing on a bad credential is a worse outage than the disclosure+ wrong = client.get("/health", headers={"Authorization": "Bearer nope"})+ assert wrong.status_code == 200+ assert wrong.json() == {"status": "ok"}++ # the detail is the authorized caller's+ full = client.get("/health", headers={"Authorization": "Bearer s3cret"})+ assert full.status_code == 200+ _, returned = _health_return_keys()+ assert sorted(full.json()) == sorted(returned)+ for leaked in ("loaded", "revisions", "cpu_fallbacks", "checkpoint_devices"):+ assert leaked in full.json()+ assert leaked not in anonymous.json()+++def test_health_without_an_api_key_is_unchanged():+ """A deployment that set no key never asked to be gated, so it gets the whole payload."""+ from fastapi.testclient import TestClient++ client = TestClient(create_app(router=FakeRouter()))+ _, returned = _health_return_keys()+ assert sorted(client.get("/health").json()) == sorted(returned)++def _health_return_keys():"""The keys `health()` hands back, read out of its own `return` statement."""path = os.path.join(ROOT, "laya", "serve.py")