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.

docs(hooks): the RuntimeWarning arrives once per distinct message, not per failure

Aashish585d44248c13
diff --git a/docs/hooks/errors.md b/docs/hooks/errors.md
index d19be396..97a8387b 100644
--- a/docs/hooks/errors.md
+++ b/docs/hooks/errors.md
@@ -121,15 +121,26 @@ from `predict`/`system_one` rather than at construction.
## Warnings
-With `hooks_raise=False`, each failing hook emits one `RuntimeWarning` naming the hook type and
+With `hooks_raise=False`, a failing hook emits one `RuntimeWarning` naming the hook type and
event:
```
laya: hook Metrics.on_predict_end failed: connection reset
```
-The warning is emitted once per failure, not once per hook definition, so a flaky hook under
-load can be noisy. Aggregate or rate-limit inside the hook if that matters.
+How many of those lines an operator actually sees is Python's warning filter, not Laya's. The emit is
+a plain `warnings.warn` and its text carries nothing unique to the call, so under the default filter
+for `RuntimeWarning` Python prints the first occurrence of each distinct message per call site and
+suppresses the identical repeats for the rest of the process. A hook that fails the same way on every
+one of a thousand calls prints one line. A hook whose error text varies with the call -- a request id,
+a retry counter, a timestamp -- prints one line per distinct text, and that is the case that can be
+noisy under load. Two hooks failing, or one hook failing from two different call sites, are two lines
+each.
+
+So the warning stream is not a failure counter. If the rate matters, count inside the hook, or set
+`hooks_raise=True` and handle the exception. To make the repeats print, a caller has to widen the
+filter itself (`warnings.simplefilter("always")`, which is what the test suite does in order to see
+each one).
## Timeouts
diff --git a/docs/hooks/patterns.md b/docs/hooks/patterns.md
index 6e4b5035..6a0d3c26 100644
--- a/docs/hooks/patterns.md
+++ b/docs/hooks/patterns.md
@@ -376,8 +376,9 @@ class Count:
### Silent failure
-`hooks_raise=False` warns once per failure, but a hook that catches everything itself hides
-real problems.
+`hooks_raise=False` warns when a hook fails -- one line per distinct message and call site under
+Python's default filter, so a hook that fails the same way repeatedly prints once, not once per
+failure ([Errors](errors.md)). A hook that catches everything itself hides real problems.
```python
# bad: no one will ever know the audit trail stopped
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
index 40745dcd..91dbc45d 100644
--- a/tests/test_hooks.py
+++ b/tests/test_hooks.py
@@ -213,6 +213,20 @@ check("hooks_raise=False/continues", len(res), 1)
check_true("hooks_raise=False/warns",
any(issubclass(w.category, RuntimeWarning) for w in caught))
+# ... but it arrives once per distinct message, not once per failure. The emit site is a plain
+# `warnings.warn` inside `laya/hooks.py::dispatch` (line 550) whose text names the hook, the event and
+# the exception, so a hook that fails the same way repeats the same string, and Python's default
+# `RuntimeWarning` filter dedups by (message, category, caller line) for the rest of the process.
+# Every arm above calls `simplefilter("always")`, which is why the suite never contradicted the page.
+f = make_fake()
+with warnings.catch_warnings(record=True) as dedup:
+ warnings.simplefilter("default")
+ for _ in range(3):
+ f.predict_batch(["s0"], QUESTIONS, on_predict_start=boom, hooks_raise=False)
+check("warnings/identical repeats dedup to one line under the default filter", len(dedup), 1)
+check("warnings/and that line is the hook failure",
+ [str(w.message) for w in dedup], ["laya: hook _StartAdapter.on_predict_start failed: hook boom"])
+
class ErrHook:
def __init__(self):