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(evidence): a too-deep JSON artifact names the file it came from

Aashish454f0dcb627d
diff --git a/laya/evidence.py b/laya/evidence.py
index 5d609c0a..11888787 100644
--- a/laya/evidence.py
+++ b/laya/evidence.py
@@ -181,6 +181,11 @@ def _read_json_object(path: str) -> Dict[str, Any]:
from two different arguments, so a refusal that omits the path cannot say which artifact is
broken -- the only thing the caller can act on. Same reason `laya/evals.py:155` prefixes its
dataset rows with the path.
+
+ A `RecursionError` belongs with them for the same reason and by the same argument: `json` reports
+ a nesting depth it will not walk as a stack overflow, which is neither of the two classes above,
+ so a too-deep artifact escaped as a traceback with exit 1 -- the code `laya-evals` keeps for a
+ quality failure -- naming no file at all, exactly the thing this docstring refuses to allow.
"""
try:
with open(path, "r", encoding="utf-8") as handle:
@@ -189,6 +194,8 @@ def _read_json_object(path: str) -> Dict[str, Any]:
raise ValueError("%s is not valid JSON: %s" % (path, exc)) from exc
except UnicodeDecodeError as exc:
raise ValueError("%s is not UTF-8 text: %s" % (path, exc)) from exc
+ except RecursionError as exc:
+ raise ValueError("%s is JSON nested deeper than it can be read: %s" % (path, exc)) from exc
if not isinstance(document, dict):
raise ValueError("%s is not a JSON object" % path)
return document
diff --git a/tests/test_evidence.py b/tests/test_evidence.py
index 11fc65b3..f7000a01 100644
--- a/tests/test_evidence.py
+++ b/tests/test_evidence.py
@@ -310,12 +310,18 @@ with open(_not_json, "w", encoding="utf-8") as f:
_not_text = os.path.join(tmp, "not-text.json")
with open(_not_text, "wb") as f:
f.write(b"\xff\xfe\x00\x01binary")
+# `json` reports unclosable depth as a `RecursionError`, which is neither a `ValueError` decode
+# failure nor an `OSError`, so it is the one shape of unreadable artifact that used to reach the
+# caller as a traceback.
+_deep_report = os.path.join(tmp, "deep.json")
+with open(_deep_report, "w", encoding="utf-8") as f:
+ f.write("[" * 100000 + "]" * 100000)
_bad_config_ckpt = os.path.join(tmp, "ckpt-bad-config")
os.makedirs(_bad_config_ckpt)
with open(os.path.join(_bad_config_ckpt, "rl_agent_config.json"), "w", encoding="utf-8") as f:
f.write("{nope")
-# The last tuple element is the string the refusal must contain. For four rows that is the whole
+# The last tuple element is the string the refusal must contain. For five rows that is the whole
# path, because `laya/evidence.py` builds those messages from the argument the caller passed. The
# directory row is the exception: its refusal is the operating system's own `OSError` text, and the
# Windows CI runner reports that path in 8.3 form (`C:\Users\RUNNER~1\...` where the test holds
@@ -331,6 +337,8 @@ for _label, _argv, _expect in (
_not_json),
("--report is not UTF-8 text", ["evidence", "--checkpoint", ckpt, "--report", _not_text],
_not_text),
+ ("--report is JSON nested too deep to read",
+ ["evidence", "--checkpoint", ckpt, "--report", _deep_report], _deep_report),
("the checkpoint's own config is not JSON",
["evidence", "--checkpoint", _bad_config_ckpt],
os.path.join(_bad_config_ckpt, "rl_agent_config.json"))):