Repository navigation
fix(mcp): a door collapses only a numeric 0, never a boolean control - #1257
Merged
NandhaKishorM merged 3 commits intoOct 17, 2026
Merged
Conversation
route_batch_tool declares hooks_timeout as a number, so an eager JSON client may send the default as 0.0 rather than 0. The collapse uses == for exactly that reason; this arm pins it and would fail against an `is 0` rewrite.
An `is 0` rewrite of either collapse is invisible while every arm passes the interned literal 0: the floats have to be probed. 0.0 is the shape a JSON client sends for a declared number, and JSON has no integer type for batch_size.
This was referenced Oct 15, 2026
Owner
|
Merged in 0.4.9.
Applying the same boolean-aware collapse in all three places, rather than only where a report came from, is the right scope. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two of the four MCP tool doors that take an eager-default
0still folded their numeric default withor None, which in Python also folds a boolean. Both now use the boolean-aware collapse the same filealready uses at
laya/mcp/server.py:364:4ac226d5laya_predict_batch_toolbatch_size=batch_size or Noneatlaya/mcp/server.py:369:369, plain forward at:374laya_route_batch_toolhooks_timeout=hooks_timeout or Noneatlaya/mcp/server.py:400:404, plain forward at:409laya/mcp/tools.pyis untouched: it already validates both controls by name(
_validate_batch_sizelaya/mcp/tools.py:1185, called at:1234, and_validate_hooks_timeoutlaya/mcp/tools.py:1193, called at:1240inlaya_predict_batchand at:1312inlaya_route_batch).This PR only stops the doors from swallowing the value before it gets there. 101 added / 3 removed in two
files:
laya/mcp/server.py+12/-3 -- two collapses, both comments explaining why only a numeric0folds.tests/test_mcp.py+89/-0 -- 17 new named arms, one new test function(
test_route_batch_tool_hooks_timeout_forwarding, defined at:1547, registered in the runner list at:3250), and two float-zero arms pinned into the existingtest_batch_tool_control_forwarding.No public signature changes, no new dependency, no docs claim moves:
docs/cli-mcp.md:168-169listsbatch_size/hooks_timeoutfor these two tools and says nothing about0orfalse, so theuser-facing text was already correct about the parameters and silent about the fold.
Why
False == 0in Python, sox or Noneanswers a caller'sfalsewith "unset". The tools layer refusesbooleans by contract --
_validate_hooks_timeoutraises for a bool with the comment that core'sfloat(True) == 1.0"would silently turn True into a one-second deadline" -- and the door that alreadycarries the collapse says so in its own comment (
laya/mcp/server.py:357-363): a numeric0means unsetbecause MCP clients send defaults eagerly, and deliberately only a numeric 0.
Measured at the door, with
_wrapreplaced by a recorder (laya-bench/probe_mcp_false_fold.py, both logskept; the whole before/after difference is two lines):
4ac226d5forwardslaya_predict_batch_tool(batch_size=false)None(unset)FalseToolError(invalid_batch_size) batch_size must be a positive integer, got Falselaya_predict_batch_tool(batch_size=true)TrueTrueToolError(invalid_batch_size) ... got True-- already reached, unchangedlaya_predict_batch_tool(batch_size=0)/0.0/ absentNoneNonelaya_predict_batch_tool(batch_size=16)1616laya_route_batch_tool(hooks_timeout=false)None(unset)FalseToolError(invalid_hooks_timeout) hooks_timeout must be a positive number or None, got Falselaya_route_batch_tool(hooks_timeout=true)TrueTruelaya_route_batch_tool(hooks_timeout=0)/1.5/ absentNone/1.5/NoneSo on
4ac226d5the same JSON value spelledtrueshouted and spelledfalsewas silent: a caller thatasked for a gate it was not entitled to got an error naming it, and a caller that asked for the boolean
version of the same mistake got a clean batch of answers with the control dropped.
falseis the shapea client sends when it serialises a Python
Falseor a JSfalsefor an optional knob, so the silent armis the common one.
Nothing else in the repo treats these two doors differently:
laya_predict_batch_tool's ownhooks_timeoutalready used the boolean-aware form, and the test that pins it(
tests/test_mcp.py:1444) states the rule -- "A bool is never an unset marker:False == 0in Python, soa plain equality or
or Nonefold would hide the tools layer's explicit refusal of booleans". The twolines this PR fixes are the same door with the fix missing, not a new convention.
Cross-port check (a Python-only guard can delete a parity contract, so every generator was grepped, not
just one): 50 hits for
batch_size|hooks_timeoutacrosslaya-java/scripts,laya-go/scripts,laya-dotnet/tools,laya-ts/scriptsandlaya-rust-- all of them drivepredict_batch/_infer_batchat the Router-or-agent level with literal integers,Noneor a booleansort(
laya-go/scripts/gen_go_fixtures.py:845recordsbatch_size=0as "zero chunk means all", andlaya-java/scripts/gen_fixtures.py:2105enumerates(None, False), (2, False), (3, True)). Zero of themspell either control as
true/false, and zero port files referencelaya.mcpat all. The numeric-zerosemantics those fixtures pin are the ones this PR keeps byte-for-byte:
0and0.0still collapse tounset, which is why the float-zero arms exist.
How it was verified
Gate
laya-bench/gate_mcp_false_fold_head58e4a981.log(18:21Z): 78 invocations,all 88 suites passed,exit 0, and it prints
laya_from=/Users/aashish/github contribution /GIT/laya-mcp-false-fold/laya/__init__.py--the venv's editable install points at a different checkout, so every run above pins the tree and asserts
which
layaanswered before trusting a count.Gate diff (
laya-bench/gate_mcp_doordiff_head58e4a981.txt, 18:53Z) against the pristine4ac226d5control(
laya-bench/gate_evalrows_ctrl4ac2.log, 17:57Z,tree=/laya_from=pointing at the untouchedlaya-base-4ac2checkout, same 78 invocations,all 88 suites passed):invocations: branch=78 control=78,identical: 76, differing: 2. Exactly two blocks move:
tests/test_mcp.py: 17PASSlines added and none removed. Counting the arm names themselves rather thantrusting the diff --
sort -uof thePASSlabels gives 1135 on the branch vs 1118 on the control, andcomm -23gives the 17 expected names (batch_tool/batch_size_{zero_is_unset, float_zero_is_unset, default_is_unset, forwarded, True_reaches_tools, False_reaches_tools, false_rejected_downstream},batch_tool/hooks_timeout_float_zero_is_unset, and the 9route_batch_tool/hooks_timeout_*counterparts)while
comm -13is empty. No pre-existing arm changed.-qbatch: the control log carries a second trailingci_gate exit=0line that thebranch log does not -- a capture artifact, since both blocks end
all 88 suites passed.Nothing else in 78 invocations moved.
tests/test_hooks_api.pyruns here because it is the suite that pins the door defaults as visibleparameters (
check_param("laya_predict_batch_tool", ..., "batch_size", 0)) -- the collapse it protects isunchanged, and it stays green: 638 passed, 0 failed.
Before-witness:
laya/mcp/server.pyreplaced by the4ac226d5blob (sha256 64351cdf32f2...) whilethis branch's tests run, then restored byte-verified (
sha256 95da9c6b306d...,git statusclean). The18:55Z re-run is kept as
laya-bench/revert_arm_mcp_head58e4a981.log:1167 passed, 2 failed, and the two failures name exactly the two arms this PR is about --FAIL batch_tool/batch_size_False_reaches_tools NoneandFAIL route_batch_tool/hooks_timeout_False_reaches_tools None. Every other arm, including the fournumeric-zero arms, passes on base: no pre-existing test depends on the old fold, and the new arms do not
restate behaviour base already had.
Mutation ledger (
laya-bench/mutate_mcp_door_folds_head58e4a981.log, 18:19Z, baseline 1169 passed /0 failed, one file restored from the HEAD blob between mutants):
batch_sizeback toif not batch_size:(main's fold)batch_size_False_reaches_toolshooks_timeoutback toif not hooks_timeout:hooks_timeout_False_reaches_toolshooks_timeoutback toif not hooks_timeout:hooks_timeout_False_reaches_toolsbatch_size == 0->is 0batch_size_float_zero_is_unsethooks_timeout == 0->is 0hooks_timeout_float_zero_is_unsethooks_timeout == 0->is 0hooks_timeout_float_zero_is_unsethooks_timeoutdropsnot isinstance(..., bool)hooks_timeout_False_reaches_toolsbatch_sizedrops the same guardbatch_size_False_reaches_toolshooks_timeout_False_reaches_toolsisinstance(...) or == 0)hooks_timeout_True_reaches_tools+False12 mutants, 12 killed, 0 survivors, file restored byte-verified
(
sha256 95da9c6b306d == 95da9c6b306d). The first run of this harness had a survivor and it was real: anis 0rewrite of thepredict_batchdoor was invisible, because every arm then passed the internedliteral
0, for which0 is 0is True. Two0.0arms were added (batch_sizeand thehooks_timeoutof both doors -- a JSON client is free to send a declared number's default as0.0, and0.0 == 0while0.0 is 0is False) and the harness re-run to the table above.ruff on the two files:
All checks passed!at 18:55Z (a repo-wide sweep prints 13 pre-existing findingsunrelated to this branch, so the claim is scoped to the touched files).
compileallrc=0. Diff scanned forcredentials: 0 matches over all 101 added lines (
grep -icEof the^+lines, rc=1 = no match).Pre-open re-checks on the same
58e4a981with a clean tree, at 21:13-21:18Z (laya_from=printed first andpointing at this tree):
tests/test_mcp.pyagain1169 passed, 0 failed(21:18Z),tests/test_hooks_api.pyagain
638 passed, 0 failed(21:18Z), ruff againAll checks passed!,compileallrc=0, the secret re-scanagain 0 matches with rc=1, and
git diff --numstat 4ac226d5 HEADunchanged at12 3 laya/mcp/server.py/89 0 tests/test_mcp.py.Overlap, scanned against all open PRs at 18:23-18:33Z, re-scanned at 19:35Z and again immediately before the
push at 20:54Z (
gh pr list --state open --json files --limit 200: 60, then 61, then 64 -- three unrelatedPRs opened in between, none touching these three files;
mainstill4ac226d5on all three passes, confirmedagainst the API, and every head SHA, hunk range and tree id below reproduced on the later two): three open PRs
touch
laya/mcp/server.py,laya/mcp/tools.pyortests/test_mcp.py, and all three are mine -- #1242(
fix-device-index-rewrite,6f0a3556), #1203 (fix-hooks-api-timeout,ae132f47) and #738(
feat-mcp-predict-long,46e32d25, alreadyCONFLICTINGagainst main). None of them adds this collapse:their
laya/mcp/server.pyhunks are at old lines 9-16 (#1242) and 52-57 / 506-511 (#738, a newlaya_predict_long_tool), while mine are at 363-372 and 393-403, and #1203's onlytests/test_mcp.pyhunkis at 1358-1365 against my 1406-1560.
git merge-tree --write-treein both orders exits 0 with the sametree each way against #1242 (
5e3ef30c2220) and #1203 (c7a50e4783d2). Against #738 the merge reports theidentical four conflict regions whether or not my branch is on the other side:
main+#738markstests/test_mcp.pyconflicts at merged lines 2267/2289/3077/3291 and58e4a981+#738marks four at2355/2377/3165/3379, shifted by exactly +88 at all four positions -- the same four regions carried down past
my additions, not a fifth created by them. The nearest, 3379, is the
docs-mcp/args_rowtool tuple about 16lines above my nearest edit there, and its
58e4a981side is byte-for-byte main's seven-name tuple, so thisbranch does not touch that line at all.
laya/mcp/server.pyauto-merges in that pair with zero conflictmarkers, and the merged file keeps both my collapses at
:370and:405with main's two falsy folds(
batch_size=batch_size or Noneat:369andhooks_timeout=hooks_timeout or Noneat:400) gone from it-- the only
or Nonestrings left in that file are the unrelatedapi_key=argument and my own commentnaming the pattern. That includes #738's stale copy of the route-batch call site
(
hooks_timeout if hooks_timeout > 0 else None), which is their base's text, unchanged by them against it,so the merge takes main's line and then mine. So #738's conflicts are its own stale base, not an edit
collision with this PR, and this branch neither causes nor inherits one.
Checklist
maindocs/cli-mcp.mdneverdescribed the fold, so nothing there went stale -- see What)
Fixes #