Skip to content

armgit / laya

Public Imported from GitHub
0

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.

test(compose): gate the server variables per service and retire the deferral

Aashish7ccfeca611ae
diff --git a/tests/test_compose_env.py b/tests/test_compose_env.py
index 19993fe7..4a18008d 100644
--- a/tests/test_compose_env.py
+++ b/tests/test_compose_env.py
@@ -82,6 +82,45 @@ def dtype_names() -> List[str]:
return sorted(set(out))
+# The three idioms that make an empty environment value mean "not asked for". A Compose
+# passthrough with an empty default -- `"${NAME:-}"` -- hands the container `""`, not an absent
+# variable, so a reader that supplies a real default would take a decision away from an operator
+# who set nothing. These are the only shapes that keep the empty string meaning "as before", and
+# they are all in `laya/`: `os.environ.get("NAME", "")`, a falsy test on the same line, and the
+# `raw = os.environ.get("NAME")` / `if not raw: return DEFAULT` resolver in the server module.
+EMPTY_GET = 'os.environ.get("{name}", "")'
+EMPTY_OR = 'os.environ.get("{name}") or '
+# A resolver that returns its own default from the empty string: the read, then a falsy test on
+# the next line, then the value it hands back. Only the first two lines are looked at, so a
+# reader that ignores an empty value and keeps going is still reported.
+EMPTY_RESOLVER = (r'os\.environ\.get\("{name}"(,\s*""\s*)?\)\s*\n\s*if not \w+\b')
+
+
+def empty_unsafe_reads(name: str) -> List[str]:
+ """Every read of ``name`` in the package an empty value would not survive."""
+ out: List[str] = []
+ for _dirpath, _dirs, _files in os.walk(os.path.join(ROOT, "laya")):
+ for _filename in _files:
+ if not _filename.endswith(".py"):
+ continue
+ _rel = os.path.relpath(os.path.join(_dirpath, _filename), ROOT)
+ _text = read(_rel)
+ for _match in ENVIRON_GET.finditer(_text):
+ if _match.group(1) != name:
+ continue
+ _line_start = _text.rfind("\n", 0, _match.start()) + 1
+ _site = _text[_line_start:_match.end() + 60]
+ _first = _site.split("\n")[0]
+ if (EMPTY_GET.format(name=name) in _first
+ or EMPTY_OR.format(name=name) in _first):
+ continue
+ if re.search(EMPTY_RESOLVER.format(name=name), _site):
+ continue
+ out.append("%s:%d: %s" % (_rel, _text[:_match.start()].count("\n") + 1,
+ _first.strip()))
+ return out
+
+
def env_blocks(text: str) -> Dict[str, Dict[str, str]]:
"""service name -> its `environment` mapping, as (key, raw value) pairs.
@@ -160,16 +199,20 @@ for rel in COMPOSE_FILES:
"%s: %r -- hardcoding or requiring a dtype here would pin it for "
"every user" % (name, value))
-# 3. an empty default has to mean "the checkpoint's own dtype", which is what these images shipped
-# before this change. Parsed out of the core so the claim is checked, not assumed.
+# 3. an empty host default has to mean "not asked for", which is what these images shipped before
+# any of this. Widened from the two dtype names to every name any Compose file forwards in the
+# `"${NAME:-}"` form, because the form is the deployment's promise and the promise is only kept
+# by the reader: an unset `LAYA_REVISION` has to leave the download on the Hub's default branch
+# the way `laya/revisions.py` says it does, and an unset `LAYA_MAX_CONCURRENT` has to leave the
+# server on 16. A reader that swaps in its own non-empty default when the container hands it
+# `""` silently outranks an operator who set nothing, so each read site is parsed, not trusted.
for rel in COMPOSE_FILES:
for service, env in sorted(env_blocks(read(rel)).items()):
for name, value in env.items():
- if name in names and re.match(r'^"\$\{%s:-\}"$' % name, value):
+ if NAME.fullmatch(name) and re.match(r'^"\$\{%s:-\}"$' % name, value):
+ _unsafe = empty_unsafe_reads(name)
check_true("compose/%s/%s/%s empty default is safe" % (rel, service, name),
- 'os.environ.get("%s", "")' % name
- in read(os.path.join("laya", "agent.py")),
- "the core must treat an unset value as no override")
+ not _unsafe, _unsafe)
# 4. the page that documents Compose variables carries a row per derived name.
docker_md = read(os.path.join("docs", "docker.md"))
@@ -225,24 +268,24 @@ for _row in re.findall(r"^\|.*$", docker_md, re.M):
_mps_doc = re.search(r"`LAYA_MPS_AMP_MIN_ROWS`[^.]*\.", docker_md, re.S)
excluded = set(NAME.findall(_mps_doc.group(0))) if _mps_doc else set()
-# `LAYA_MAX_CONCURRENT` and `LAYA_MAX_TOKEN_BUDGET` are the same defect -- documented in the
-# laya-serve table, read by `laya/serve.py`, forwarded by no file -- and are deliberately NOT
-# fixed here. `compose.http.yaml` is the only place they could be forwarded and three open PRs
-# conflict on it: #528 and #656 insert at the environment block, and #528 is itself adding
-# `LAYA_SHA256_DIGESTS` to that block, so the serve-side forwarding belongs with whoever lands
-# that cluster. Pinned as a literal and re-asserted below, the way check 5 pins the MPS
-# exclusion, so the day those PRs close this file fails and the decision gets made again rather
-# than the two names quietly staying missing.
-DEFERRED = ("LAYA_MAX_CONCURRENT", "LAYA_MAX_TOKEN_BUDGET")
+# `LAYA_MAX_CONCURRENT` and `LAYA_MAX_TOKEN_BUDGET` sat in this exclusion for one reason, and the
+# reason was dated: `compose.http.yaml` is the only file that can forward them, and three PRs were
+# inserting into that service's `environment:` block at the same time, so the names were left for
+# whoever landed the cluster. The cluster landed -- #528 and #656 both merged 2026-09-29, and
+# #528's `LAYA_SHA256_DIGESTS` is in the block this file now demands -- so the exclusion is empty
+# and the two knobs are forwarded by `compose.http.yaml` with the rest of them.
+#
+# The tuple stays rather than disappearing, because an empty exclusion is the shape most likely to
+# be re-filled by the next person who hits a conflict on that block. Re-deferring a name now costs
+# a named check below, not a quiet pass.
+DEFERRED = ()
required = sorted((package_read & documented_rows) - excluded - set(DEFERRED))
check_true("core/the widened set is not empty", len(required) >= 10, required)
check_true("core/the widened set includes the name this change forwards",
"LAYA_REVISION" in required, sorted(required))
-check_true("core/the deferred set is exactly the two serve knobs",
- tuple(sorted(DEFERRED)) == DEFERRED, DEFERRED)
-check_true("core/the deferred names are still read and still documented, not quietly renamed",
- all(n in package_read and n in documented_rows for n in DEFERRED), sorted(DEFERRED))
+check_true("core/nothing is deferred out of the widened set", DEFERRED == (),
+ "a deferred name is a documented knob that no shipped deployment can set")
forwarded_anywhere: set = set()
for _rel in COMPOSE_FILES:
@@ -270,6 +313,119 @@ for _name in sorted(forwarded_anywhere - set(required)):
_name in documented_rows,
"the deployment sets it and the page never mentions it")
+# 6b. "Forwarded by at least one file" is the right ceiling for a name two services share, and
+# the wrong floor for one they do not. `LAYA_MAX_CONCURRENT` is read by `laya/serve.py` during
+# request admission, so a file that never starts a server forwarding it satisfies check 6
+# while the server that needs it still cannot be configured -- which is exactly how these two
+# knobs survived a merged gate. `compose.yaml`'s `laya` service runs a one-shot quickstart, and
+# `compose.http.yaml`'s own header says why that is not the same container: "`laya-serve` is a
+# separate service and overrides for `laya` never reach it".
+#
+# The service a variable belongs to is taken from the page rather than from a literal here,
+# because the page is the artifact that says which name belongs where: the table under
+# "Server configuration" opens with "These apply to the `laya-serve` service only."
+server_doc = re.search(r"^### Server configuration\n(.*?)(?=^#{2,3} )", docker_md, re.M | re.S)
+check_true("docs/docker.md has a Server configuration section", server_doc is not None,
+ "the derivation below needs the page to own the server variables")
+if server_doc:
+ _body = server_doc.group(1)
+ _owner = re.search(r"These apply to the `([a-z0-9-]+)` service only\.", _body)
+ check_true("docs/docker.md names the service the server table applies to", _owner is not None,
+ _body.splitlines()[:3])
+ server_names = sorted(set(re.findall(r"^\| `(LAYA_[A-Z0-9_]+)` \|", _body, re.M)) & package_read)
+ check_true("core/the server table is not empty", len(server_names) >= 8, server_names)
+ if _owner:
+ _service = _owner.group(1)
+ # Compose merges the `environment` of every file named on one command line, so the unit
+ # that has to be complete is the pairing, and `compose.cuda.yaml` / `compose.spark.yaml`
+ # legitimately name the service with three device keys and nothing else. The pairings are
+ # the commands this page tells an operator to run, taken from the lines that name the
+ # service -- so the demand is on what a reader boots, not on a file list invented here.
+ _pairings = sorted({tuple(re.findall(r"-f ([a-z0-9._-]+\.ya?ml)", _line))
+ for _line in docker_md.splitlines()
+ if _service in _line and "-f " in _line})
+ check_true("docs/docker.md shows a Compose command for the %s service" % _service,
+ bool(_pairings), _pairings)
+ for _pair in _pairings:
+ # A command on the page that names a file the tree does not have is the same class of
+ # drift as a variable the page names and the deployment drops, so it is checked here
+ # rather than crashing the suite on a FileNotFoundError.
+ _missing = [rel for rel in _pair if not os.path.exists(os.path.join(ROOT, rel))]
+ check_true("compose/%s names files that exist" % "+".join(_pair), not _missing, _missing)
+ _merged: Dict[str, str] = {}
+ for _rel in _pair:
+ if _rel not in _missing:
+ _merged.update(env_blocks(read(_rel)).get(_service, {}))
+ for _name in server_names:
+ check_true("compose/%s forwards %s to %s" % ("+".join(_pair), _name, _service),
+ _name in _merged,
+ "the table applies to `%s` only and this command boots it, so an "
+ "operator's value is interpolated and dropped" % _service)
+ if _name in _merged:
+ # The same loose tail check 6 uses, so `LAYA_THREADS`'s nested
+ # `"${LAYA_THREADS:-${OMP_NUM_THREADS:-4}}"` stays a host passthrough.
+ check_true("compose/%s/%s is a host passthrough" % ("+".join(_pair), _name),
+ _merged[_name].startswith('"${%s:-' % _name)
+ and _merged[_name].endswith('}"'),
+ "%s: %r" % (_name, _merged[_name]))
+ # The names this change forwards, pinned as literals the way check 5 pins the MPS
+ # exclusion: the pairing above would pass if another file started carrying them, and
+ # `server_names` would pass if the page stopped documenting them. `compose.http.yaml` is
+ # the file that owns this service's environment block, so it is the file that has to lose
+ # one for this check to go red.
+ _env = env_blocks(read("compose.http.yaml")).get(_service, {})
+ check_true("compose/compose.http.yaml defines the %s service" % _service,
+ _service in env_blocks(read("compose.http.yaml")), sorted(_env))
+ for _name in ("LAYA_MAX_CONCURRENT", "LAYA_MAX_TOKEN_BUDGET", "LAYA_REVISION"):
+ check_true("compose/compose.http.yaml/%s forwards the %s this change adds"
+ % (_service, _name), _name in _env,
+ "it is documented and read by the runtime, and the service that needs it "
+ "is the one that never named it")
+
+ # 6c. The default half of a passthrough is the part that can lie. `"${NAME:-}"` hands the
+ # container the empty string, `"${NAME:-8}"` hands it 8, and a plain `"8"` hands it a
+ # value nobody can move -- three different promises, and the page prints one of them.
+ # So each forwarded name is checked against its own row, and an empty default has to
+ # be a value the reader treats as "not asked for": the property check 3 pins for the
+ # dtype names, widened to the server table, where the empty form is the norm.
+ _serve_src = read(os.path.join("laya", "serve.py"))
+ _defaults = dict(re.findall(r"^(DEFAULT_[A-Z0-9_]+) = (\S+)$", _serve_src, re.M))
+ _const_pinned = 0
+ for _name, _cell in re.findall(r"^\| `(LAYA_[A-Z0-9_]+)` \| ([^|]+) \|", _body, re.M):
+ _value = _env.get(_name)
+ if not _value or not _value.startswith('"${%s:-' % _name) or not _value.endswith('}"'):
+ continue
+ _tail = _value[len('"${%s:-' % _name):-2]
+ _cell = _cell.strip()
+ if _tail.startswith("${"):
+ _inner = re.match(r"^\$\{([A-Z0-9_]+)", _tail)
+ check_true("compose/compose.http.yaml/%s nests a default its row names" % _name,
+ _inner is not None and _inner.group(1) in _cell,
+ "%s: row prints %r" % (_name, _cell))
+ elif _tail:
+ check_true("compose/compose.http.yaml/%s default is the documented %s"
+ % (_name, _cell),
+ _cell.startswith("`") and _cell.strip("`") == _tail,
+ "an unset %s gets a value the page does not print, so the row and the "
+ "deployment disagree about the container an operator gets for free"
+ % _name)
+ else:
+ _unsafe = empty_unsafe_reads(_name)
+ check_true("compose/compose.http.yaml/%s empty default is safe" % _name,
+ not _unsafe, _unsafe)
+ _const = "DEFAULT_%s" % _name[len("LAYA_"):]
+ if _cell.startswith("`") and _const in _defaults:
+ _const_pinned += 1
+ check("docs/docker.md prints the same %s default as laya/serve.py" % _name,
+ _cell.strip("`"), _defaults[_const])
+ check_true("core/both knobs this change forwards have a module default to pin",
+ _const_pinned == 2, _const_pinned)
+ for _name in ("LAYA_MAX_CONCURRENT", "LAYA_MAX_TOKEN_BUDGET"):
+ check_true("docs/docker.md keeps the %s row in the server table" % _name,
+ re.search(r"^\| `%s` \|" % _name, _body, re.M) is not None,
+ "the two sections above derive their demand from this table, so a row "
+ "deleted by accident retires the gate instead of reopening the question")
+
# 7. the real renderer, when this machine has one: the rendered environment must carry the value.
if shutil.which("docker"):
env = dict(os.environ, LAYA_CUDA_AMP="fp16")
@@ -288,8 +444,30 @@ if shutil.which("docker"):
else:
NOTES.append("docker compose config exited %d: %s" % (proc.returncode,
proc.stderr.strip()[:200]))
+
+ # The HTTP file is what this change edits, and an interpolated name that never reaches the
+ # container is the failure the textual checks above are reasoning about. Both arms: set, and
+ # left alone. The unset arm is the one an operator actually boots, and it must show the empty
+ # default arriving as empty rather than as the literal `${LAYA_MAX_CONCURRENT:-}`.
+ _KN = ("LAYA_MAX_CONCURRENT", "LAYA_MAX_TOKEN_BUDGET", "LAYA_REVISION")
+ _arms = [(dict(zip(_KN, ("4", "16384", "reviewed"))), dict(zip(_KN, ("4", "16384", "reviewed")))),
+ ({}, dict.fromkeys(_KN, ""))]
+ for _set, _expect in _arms:
+ proc = subprocess.run(["docker", "compose", "-f", "compose.yaml", "-f", "compose.http.yaml",
+ "config"], cwd=ROOT, env=dict(os.environ, **_set),
+ capture_output=True, text=True)
+ if proc.returncode != 0:
+ NOTES.append("docker compose -f compose.http.yaml config exited %d: %s"
+ % (proc.returncode, proc.stderr.strip()[:200]))
+ continue
+ _rendered = env_blocks(proc.stdout).get("laya-serve", {})
+ for _name, _want in sorted(_expect.items()):
+ # The renderer re-quotes: `4` comes back as `'4'` and an empty default as `""`.
+ # Stripping one layer of quotes is what the container actually receives as a string.
+ check("render/%s reaches the server as %r" % (_name, _want),
+ str(_rendered.get(_name, "<absent>")).strip("'\""), _want)
else:
- NOTES.append("docker not installed: checks 1-5 still hold; the render check did not run")
+ NOTES.append("docker not installed: checks 1-6 still hold; the render check did not run")
print("\n%d passed, %d failed" % (len(PASS), len(FAIL)))
for note in NOTES: