Repository navigation
fix(batch): refuse a batch_size the chunker cannot spend - #1458
Merged
Merged
Conversation
`predict_batch` spends `batch_size` as a `range()` step, so a value `range()`
cannot spend leaked the interpreter's own error from the middle of the batch
loop. Measured at 0.4.22: 2.5 raised TypeError ('float' object cannot be
interpreted as an integer) and "2" raised TypeError ('>' not supported between
instances of 'str' and 'int'), while True silently capped every pass at one
state and switched sort_by_length off. laya/mcp/tools.py and laya/serve.py
already refused those shapes at their own entry, so only the Python route met
the raw TypeError. common.check_batch_size refuses them by name at the entry of
Agent.predict_batch, ONNXAgent.predict_batch and window_batch_cap, following the
Integral precedent ece_score sets for `bins`.
The sign is untouched: None, 0 and -1 still mean "no cap", which is what
laya-java/fixtures/window_plan.json's batch_cap grid pins -- recomputing all 810
committed rows with the patched function moves none of them.
test_batch 89 -> 105, test_predict_long 384 -> 391, test_onnx_batch 67 -> 83;
the repo's full CI list (scripts/test_suites.py, 93 suites) passes.
Merged
4 tasks done
NandhaKishorM
added a commit
that referenced
this pull request
Nov 6, 2026
… import check_batch_size joined the laya.common import block in laya/agent.py, so every line number below it moved by one and tests/test_doc_citations.py caught the one citation that names a symbol beside it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Owner
|
Merged, thank you. Verified here: on unpatched main One side effect worth knowing for future PRs: adding |
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
Adds
laya.common.check_batch_size, a named validator for the per-callbatch_sizecap, and calls it at the entry of the three places that spend that value:Agent.predict_batch,ONNXAgent.predict_batchandwindow_batch_cap. Afloat, astr, abool, a list, a dict,nanorinfis now refused withinstead of crashing later or quietly doing something else.
None,0and negative integers keep meaning "no cap", andnumpy.int64and any othernumbers.Integralare still spent as a cap.Both
predict_batchdocstrings now name the refusal and the no-cap rule, andwindow_batch_cap's "an explicitbatch_sizeis always honoured" says who decides what counts as explicit.Why
batch_sizeis spent as arange()step, so a valuerange()cannot spend leaked the interpreter's own error from the middle of the batch loop. Measured at 0.4.22, on the weight-free fakes the two suites already build:batch_size2.5TypeError: 'float' object cannot be interpreted as an integerValueError, named, before any state is encoded"2"TypeError: '>' not supported between instances of 'str' and 'int'ValueError, namedTrue[2, 2, 2, 2, 2, 2]on the six-state length fake — six one-state passes, andsort_by_lengthsilently inert because its own gate is1 < chunkValueError, namedFalsebatch_size > 0ValueError, namedwindow_batch_cap(413, 23, 312, 2.5)2.5, whichpredict_longthen handed topredict_batchValueError, namedlaya/mcp/tools.py::_validate_batch_sizeandlaya/serve.py::_validate_budget_paramalready refused both shapes at their own entry, so the rawTypeErrorreached only the Python route — the documented one, and the one with no schema in front of it. The MCP and HTTP surfaces keep their own validators and their own error codes untouched: their contract also refusesbatch_size < 1, which is deliberately stricter than core, where0and-1mean "no cap".The shape is guarded, the sign is not.
laya-java/fixtures/window_plan.json'sbatch_capgrid replays(None, 0, -1, 1, 8)through the Java, Go, C#, C++ and TS ports, whose typedinttreats zero and negative as "unset", so every one of those rows must keep its recorded cap.Integralrather thanintis the test becauseece_scorein the same module makes that argument forbins, and a caller who derives the cap from an array shape is the common case.How it was verified
The three suites are the ones carrying the new rows:
test_batch.pyrefuses the ten bad shapes onAgentand pins the exact message, then assertsNone/0/-1/10**400still go out as one pass andnumpy.int64(3)still chunks[6, 6];test_predict_long.pyadds the same refusals towindow_batch_capand pins its no-cap spellings at the measured un-capped pass width (30);test_onnx_batch.pydoes all of it over the stub session, so the ONNX route's guard line is covered by rows that assert the refusal runs no session at all.gen_fixtures.py --checkexits 1 onlang_detect.json is staleandpython_json.json is stale. Both are stale at 462c264 with the same two lines and the same exit code — they need a checkpoint this run cannot reach, and neither family readsbatch_size.No committed golden moves. The generator skips the
window_plan.jsonfamily without a checkpoint, so the rows were recomputed directly with the patched function: 810 committedbatch_caprows, 0 whose recorded cap changes, over the spellings[-1, 0, 1, 8, None]the grid actually contains.Five mutation arms, each restored from a copy outside the tree, and the three suites re-run from disk afterwards:
Agent.predict_batch—test_batch.pydies with the baseTypeError: 'float' object cannot be interpreted as an integeratagent.py:1587, i.e. the leak itself.ONNXAgent.predict_batch—test_onnx_batch.pydies with the sameTypeErroratonnx_agent.py:832.window_batch_cap— 4 named failures intest_predict_long.py.Integralforint— both batch suites die onValueError: ... got np.int64(3)/np.int64(2), so the numpy rows are load-bearing.boolclause — 2 named failures (chunk/batch_size True is refused by name,... False ...).Mergeability was checked against the current upstream head,
462c2644(release 0.4.22):git merge-tree --write-treereturns rc=0 with no conflict. The nearest open PR, #687 (perf(agent)), edits the same twopredict_batchbodies at overlapping context lines but never validatesbatch_size, so nothing here duplicates it; if it lands first, this rebases by hand.Checklist
mainFixes #