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.

refactor(serve): read the fallback counters through mcp.device.router_agent

umran6669dcd3077cea3
diff --git a/laya/serve.py b/laya/serve.py
index b05a9ab6..1c7b0da6 100644
--- a/laya/serve.py
+++ b/laya/serve.py
@@ -306,21 +306,26 @@ def create_app(router: Optional[Any] = None):
@app.get("/health")
def health() -> Dict[str, Any]:
- # Per-agent CPU-fallback counters. `_agents` is read the way laya.mcp.device
- # reads it -- the only side-effect-free handle on a resident agent -- and every
- # access is getattr-guarded so injected routers predating the counters (or
- # without a `_agents` mapping) stay health-compatible, like `revisions`.
- agents = getattr(router, "_agents", None) or {}
+ from .mcp.device import router_agent
+
+ # Per-agent CPU-fallback counters, read through the same side-effect-free
+ # accessor the MCP status tool uses -- never Router.load(), which reorders the
+ # LRU and rebuilds evicted checkpoints. Every access is getattr-guarded so
+ # injected routers predating the counters stay health-compatible, like `revisions`.
+ # This counts the *scoped* fallback in _infer (a request that demotes to CPU and
+ # restores the device); a checkpoint built on CPU because the GPU was never
+ # available is reported by `device`, not here -- see #574.
+ fallbacks = {}
+ for name in router.loaded or []:
+ agent = router_agent(router, name)
+ fallbacks[name] = {"count": getattr(agent, "cpu_fallback_count", 0),
+ "last_reason": getattr(agent, "last_fallback_reason", None)}
return {
"status": "ok",
"loaded": router.loaded,
"revisions": getattr(router, "loaded_revisions", {}),
"device": os.environ.get("LAYA_DEVICE") or "auto",
- "cpu_fallbacks": {
- name: {"count": getattr(agents.get(name), "cpu_fallback_count", 0),
- "last_reason": getattr(agents.get(name), "last_fallback_reason", None)}
- for name in router.loaded
- },
+ "cpu_fallbacks": fallbacks,
}
@app.post("/v1/systemone")