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): read a blank LAYA_PORT as unset like the rest of the family
Aashish677b06390336
diff --git a/laya/serve.py b/laya/serve.pyindex 392c999a..905181bf 100644--- a/laya/serve.py+++ b/laya/serve.py@@ -136,6 +136,10 @@ MAX_TOTAL_OPTIONS = 512# the worker even though every request is individually valid (#330).DEFAULT_MAX_CONCURRENT = 16+# The bind port a `LAYA_PORT` with no value in it asks for -- the default `README.md`,+# `docs/http-api.md` and this module's own environment table all print as `8000`.+DEFAULT_PORT = 8000+# 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@@ -738,8 +742,21 @@ def _default_model_option(extra_models: Optional[Dict[str, Any]] = None) -> Dictdef _resolve_port() -> int:- """Port from LAYA_PORT, validated. Exits with a message instead of a traceback."""- raw = os.environ.get("LAYA_PORT", "8000")+ """Port from LAYA_PORT, validated. Exits with a message instead of a traceback.++ Unset and blank both mean the documented default. `LAYA_PORT=` is what a `.env` line with the+ value left for the operator to fill in reads as, and a value that carries no number cannot be+ contradicted by falling back -- unlike `LAYA_PORT=99999`, where answering 8000 would bind the+ server somewhere its operator did not ask for. The rest of this family already reads blank as+ unset: `_env_bool`, `_default_model_option`, `_resolve_max_concurrent` and the other numeric+ resolvers here, and `laya.mcp.server`'s base URL, whose documentation says "Blank or unset means+ the default." `int()` ignores the whitespace around `" 8000 "`, so a value made of nothing+ *but* that whitespace was fatal while its content was not. A port that names a number and the+ wrong one still exits loudly, because a server bound to the wrong port is simply unreachable.+ """+ raw = os.environ.get("LAYA_PORT")+ if raw is None or not raw.strip():+ return DEFAULT_PORTtry:port = int(str(raw).strip())except (TypeError, ValueError):diff --git a/tests/test_serve.py b/tests/test_serve.pyindex 8cbfac52..c820263c 100644--- a/tests/test_serve.py+++ b/tests/test_serve.py@@ -28,6 +28,7 @@ from laya.serve import ( # noqa: E402BODY_CONTROLS,BODY_REFUSALS,DEFAULT_MAX_TOKEN_BUDGET,+ DEFAULT_PORT,MAX_BODY_BYTES,MAX_STATE_CHARS,_add_jev_confidence,@@ -39,6 +40,7 @@ from laya.serve import ( # noqa: E402_resolve_idle_unload_seconds,_resolve_max_loaded,_resolve_model,+ _resolve_port,_resolve_tournament_group,create_app,)@@ -848,6 +850,50 @@ def test_env_bool_reads_a_blank_value_as_unset(monkeypatch):assert _env_bool("LAYA_PRELOAD", True) is False+def test_resolve_port_reads_a_blank_value_as_unset(monkeypatch):+ """`LAYA_PORT=` is the same "not set" as an absent variable, and only that.++ `_resolve_port` was the last reader in this module that treated a blank as a value. Every other+ one answers "unset": `_env_bool` above, `_default_model_option`, `_resolve_max_concurrent`,+ `_resolve_max_loaded`, `_resolve_max_batch_tokens`, `_resolve_max_token_budget`,+ `_resolve_tournament_group` and `_resolve_idle_unload_seconds` -- and outside the server,+ `laya.mcp.server._remote_base_url`, whose own documentation says "Blank or unset means the+ default." On the base commit the startup path answered the same `SystemExit` it gives a bad+ port, so a declared-but-unfilled `.env` line stopped the server from starting and the message+ blamed the operator for a value they never wrote. Blank carries no number for a fallback to+ contradict, so the documented default is the only honest answer -- and `int()` ignores the+ whitespace around `" 8000 "`, so a value of nothing *but* that whitespace was fatal while its+ content was not.++ A value that does name a port is still refused loudly, because binding somewhere other than+ the requested place leaves the server unreachable rather than merely wrong.+ """+ assert DEFAULT_PORT == 8000, "the default the README and docs/http-api.md tables print"++ for blank in ("", " ", " \t ", "\n"):+ monkeypatch.setenv("LAYA_PORT", blank)+ assert _resolve_port() == DEFAULT_PORT, repr(blank)++ monkeypatch.delenv("LAYA_PORT", raising=False)+ assert _resolve_port() == DEFAULT_PORT++ # The leniency the blank case was dying on, unchanged: whitespace around a number is noise.+ for text, expected in (("8000", 8000), (" 9000 ", 9000), ("+8080", 8080),+ ("1", 1), ("65535", 65535)):+ monkeypatch.setenv("LAYA_PORT", text)+ assert _resolve_port() == expected, repr(text)++ # Every non-blank misvalue still exits, naming the value as written rather than as stripped.+ for bad in ("0", "-1", "70000", "http", "8000.0", "8000px"):+ monkeypatch.setenv("LAYA_PORT", bad)+ try:+ port = _resolve_port()+ except SystemExit as exc:+ assert str(exc) == "invalid LAYA_PORT %r: must be an integer 1-65535" % bad, str(exc)+ else:+ raise AssertionError("%r was accepted as port %r" % (bad, port))++def test_resolve_model_follows_the_router_registry(monkeypatch):"""A checkpoint added to laya.router must become pinnable over HTTP with no edit here.