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.

fix(router): validate state is not None in route_batch before model load (#707)

Swatantra Yadav8d57836f83fd
diff --git a/laya-ts/src/router.ts b/laya-ts/src/router.ts
index 8ecc0c01..d067e1a5 100644
--- a/laya-ts/src/router.ts
+++ b/laya-ts/src/router.ts
@@ -711,6 +711,9 @@ export class Router extends HookRegistry {
if (!("state" in request)) {
throw new Error(`request ${i} is missing required key 'state'`);
}
+ if (request.state === null || request.state === undefined) {
+ throw new TypeError(`request ${i} 'state' must not be None; pass a string, dict, or list`);
+ }
if (!("questions" in request)) {
throw new Error(`request ${i} is missing required key 'questions'`);
}
diff --git a/laya-ts/tests/router-batch.test.ts b/laya-ts/tests/router-batch.test.ts
index 8407d0eb..580da4d4 100644
--- a/laya-ts/tests/router-batch.test.ts
+++ b/laya-ts/tests/router-batch.test.ts
@@ -86,6 +86,9 @@ describe("Router.routeBatch / predictBatch", () => {
expect(() => router.routeBatch([{ questions: Q }] as never)).toThrow(
/request 0 is missing required key 'state'/,
);
+ expect(() => router.routeBatch([{ state: null, questions: Q }] as never)).toThrow(
+ /request 0 'state' must not be None/,
+ );
expect(() => router.routeBatch([{ state: "x" }] as never)).toThrow(
/request 0 is missing required key 'questions'/,
);
diff --git a/laya/router.py b/laya/router.py
index 430ef9a6..7853ec9a 100644
--- a/laya/router.py
+++ b/laya/router.py
@@ -1561,6 +1561,8 @@ class Router(HookRegistry):
raise TypeError("request %d must be a dict, got %s" % (i, type(request).__name__))
if "state" not in request:
raise ValueError("request %d is missing required key 'state'" % i)
+ if request["state"] is None:
+ raise TypeError("request %d 'state' must not be None; pass a string, dict, or list" % i)
if "questions" not in request:
raise ValueError("request %d is missing required key 'questions'" % i)
diff --git a/tests/test_router_batch.py b/tests/test_router_batch.py
index 3cd9e208..a5b3c38a 100644
--- a/tests/test_router_batch.py
+++ b/tests/test_router_batch.py
@@ -82,6 +82,7 @@ def test_mixed_groups_keep_order_and_lru(fake_agent, capacity, expected):
("text", TypeError, "requests must be a sequence"),
([None], TypeError, "request 0"),
([{"questions": Q}], ValueError, "request 0 is missing required key 'state'"),
+ ([{"state": None, "questions": Q}], TypeError, "request 0 'state' must not be None"),
([{"state": "x"}], ValueError, "request 0 is missing required key 'questions'"),
([request("x"), {"state": "y", "questions": None}], TypeError, "request 1 'questions'"),
([request("x"), request("y", model="invalid")], ValueError, "unknown model"),