Repository navigation
fix(hooks): refuse a bool hooks_timeout instead of reading it as 1.0 - #1203
Conversation
|
Not merged, because the branch does not carry the change this PR describes. The description is about the hooks So nothing here is lost, but nothing here is the timeout message either. If you still want that change, the quickest path is a fresh branch off One request for the next one: the checklist says "tests pass before opening" and "no PR overlap". Both were checked against a tree that holds someone else's change, so the boxes could not have been ticked from this branch. A |
`float(True) == 1.0`, so `hooks_timeout=True` -- which reads as "yes, time the hooks" -- silently installed a one-second deadline on every hook call. `False` raised, but as a non-positive number: the wrong reason for a wrong type. Core now refuses a bool where it is set, with a message that says `not a bool` so the two refusals stay distinguishable; a numeric int or string still bounds. `laya/mcp/tools.py` already refused bools at the MCP boundary, so its comment and the matching `tests/test_mcp.py` note are corrected to say the guard now also exists underneath them. `docs/hooks/errors.md` gains the bool to the list of values refused at the point the timeout is set. Python-only: a bool has no counterpart in the typed ports, so no Java/Go/TS fixture or parity surface moves.
5d04039 to
ae132f4
Compare
What
laya/hooks.py::validate_timeoutrefuses a bool.hooks_timeout=Trueused to answer1.0. It now raisesValueError: hooks_timeout must be a positive finite number or None, not a bool; got Trueat the point it is set — per call and at construction alike.
hooks_timeout=Falseused to raise... positive finite number or None; got False, i.e. it wasrefused as a number that is too small rather than as a wrong type. It now raises the bool refusal,
and the
not a boolin the message is the only thing that tells a caller which of the two they hit.0, a negative number,inf,nan, an int and a numeric string all behave exactly as before.Three surfaces describe or depend on that guard, so they move with it:
docs/hooks/errors.md— the paragraph listing what is refused at the point the timeout is set gainsthe bool and the reason it is refused for its own reason.
laya/mcp/tools.py— the comment above_validate_hooks_timeoutsaid bools are refused therebecause core's
float(True) == 1.0would silently turnTrueinto a one-second deadline. Thatasymmetry was the bug; the comment now says the boundary refuses first so the caller hears
invalid_hooks_timeout, and core refuses too.tests/test_mcp.py— the note above the batch-control arms made the same claim; corrected the same way.Nine arms in
tests/test_hooks.py(thetimeout/*block): both bools rejected, the message saysnot a boolfor both,0keeps the non-positive wording,Truerejected per call onpredict_batchand atRouterconstruction, and an int / numeric string still bound the wait.Python-only. A bool has no counterpart in the Java, Go or TypeScript ports — they are typed at the
parameter, so
hooks_timeout=trueis a compile error there — so no fixture, oracle or parity surface moves.Why
boolis a subclass ofint, andfloat(True)is1.0, sohooks_timeout=True— which reads as"yes, please time the hooks" — was read as "one second". Every hook call in that
request then got a one-second deadline the caller never asked for, and a hook that takes longer than
that turns a correct answer into a
LayaHookTimeoutError(or a silently skipped hook, depending onhooks_raise). The value is also inherited by every call on the instance when set at construction,so the mistake is not local to one request.
Measured at the base of this PR (
4ac226d5, upstreammain, release 0.4.8) in a clean worktree:Measured on this branch:
The MCP boundary already refused bools (
laya/mcp/tools.py::_validate_hooks_timeout, and_validate_batch_sizerefuses them the same way), so this closes a gap the repo had alreadyagreed is a bug — just one layer down, where the non-MCP callers are. Verified unchanged after the
guard lands:
_validate_hooks_timeout(True)still raisesToolErrorwith the boundary's own text,so no MCP caller sees a different error than before.
On this branch's history. #1203 previously carried a TypeScript
option_ordercommit built on thefork's
main, which sits at release 0.4.6 and is 187 commits behind upstream — so the PR showed achange upstream had already merged as
e894d167, and none of the change its title promised. Per thereview on this PR, the branch is now a fresh branch off upstream
main:HEAD^is4ac226d5 release: 0.4.8,git merge-base --is-ancestor refs/remotes/upstream/main HEADholds, and the diff is the fivefiles above (+57 / −10, 1 commit). Nothing from the old head was kept — that change is upstream already.
The branch name
fix-hooks-api-timeoutpredates that rebuild; the content is the guard above.Still unfixed at the base.
git show 4ac226d5:laya/hooks.pyhas no bool branch invalidate_timeout, and the probe above is run against that commit in a clean worktree. The onlybool-refusing guard in the tree is the MCP boundary, which is why merged #857 and #1118 are related but
not this: they validate at the boundary, this fixes the layer every non-MCP caller goes through.
How it was verified
What they showed:
4ac226d5(0.4.8, no change)tests/test_hooks.pytests/test_hooks_api.py(untouched; it executeserrors.md'shooks_timeoutsurface list)ci_gate(scripts/test_suites.py) invocationsci_gatepytest laneci_gateinvocations that failedtest_langchain_real_mode.py(nolangchain-core) and the pytest lane's threetest_compile.pyinductor cases (no CUDA)4ac226d5for want of the extra and a GPUtests/test_hooks.py285 → 294 passed, 0 failed both. All other 77 identical.tests/test_mcp.py(comment-only edits here)SKIP: mcp extra not installedSKIP: mcp extra not installed(same line, so the gate's answer is unchanged)ruff(both commands),compileallgen_fixtures.py --checklang_detect.json,python_json.jsonstaleRuntimeWarningzensical build --strict --cleanNo issues found, 1.68 s; the builtsite/hooks/errors/index.htmlcontains the renderednot a boolsentence, read back rather than assumedgit diff.env, no private keyMutation ledger (
laya-bench/mutate_hooks_bool.py, run againsttests/test_hooks.py;laya/hooks.pyrestored byte-for-byte after each mutant, sha256
74387e07bba7f1a1…verified equal at the end; baselinegreen at 294/0. Re-run after the rebase onto
4ac226d5— same 5/5, same restore hash, so the editedregion of
laya/hooks.pydid not move between the two bases):timeout/True is rejected,…/a bool is refused as a bool,…/False is refused as a bool too,…/True per call is rejected,…/True at construction is rejectednot a boolTypeErrortests/test_hooks.py:1779in_timeout_message: a wrong type escapes theexcept ValueErrorand the suite dies loudly rather than silentlytype(value) is boolinstead ofisinstanceboolin CPython, so this is the same guard written differently — reported as an equivalence, not a missing testtimeout/False is refused as a bool too—Falseis then refused as a number that is too small, so the ordering is pinned, not incidental5 mutants, 5 as predicted, 0 mismatched.
Deconfliction by hunk range (
gh pr diff,+-side ranges), because other open PRs share these files:feat(hooks): OptionStabilityHook, not mine — it toucheslaya/hooks.pyandtests/test_hooks.py):theirs
laya/hooks.py12-28, 548-1021 andtests/test_hooks.py20-27, 1697-1742; mine 250-268 and1767-1795 / 1800-1817. No overlap on either file.
tests/test_hooks_api.pyis touched by 7 open PRs (fix(lang): send undecided Latin text with evidence of another language to multilingual #286, feat(presets): add Swedish built-in question sets #729, feat(integrations): forward the two Router-only controls task and lang_guess #804, feat(hooks): add OptionStabilityHook for metamorphic reliability signal (#635) #908, feat(encoder): add opt-in residual bottleneck adapters #921, feat(numeric): add decimal digit features and token alignment #922, feat(comparison): add opt-in local numeric comparison specialist #923); it isuntouched here — the gate I needed from it already passes and is re-run above.
laya_predict_long) shareslaya/mcp/tools.pyandtests/test_mcp.py: theirs 834-960 and41-48/1451-1602/…; mine 1196-1206 and 1358-1367. No overlap.
hooks_timeoutat the MCPboundary, which is the layer this PR's comment updates, not the layer it changes.
Checklist
mainFixes #