Repository navigation
test(structured): decide_batch does not forward model= to predict_batch, and now says what it does - #1125
Merged
NandhaKishorM merged 2 commits intoOct 12, 2026
Conversation
…onvention The suite asserted that decide_batch forwards model= to predict_batch, against a fake whose **kwargs absorbs anything. No predict_batch in the library declares model=, so that call cannot work on a real runner. Bind the claim to the real signatures instead, and add the user-facing half: an Agent-shaped runner (named keywords, no **kwargs) raises TypeError naming 'model' while keeping batch_size= and lang= as keywords. The Router half already had a check on main -- "batch/router model= reaches a registered checkpoint" -- because decide_batch copies model= onto every request there rather than passing it as a keyword, which is the asymmetry the docstring now names. tests/ test_structured.py goes 156 -> 163 checks.
…redict_batch keyword The docstring listed model= among the keywords forwarded to runner.predict_batch. It is not: Router.predict_batch declares none of the routing pins or budget keys, so decide_batch copies them onto each request, and an Agent-like runner -- whose predict_batch declares lang= but no model= -- raises TypeError on it.
4 tasks done
Owner
|
Merged. Replacing an assertion made against a fake whose
|
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
decide_batchtold callers thatmodel=is one of the keywords forwarded torunner.predict_batch. Itisn't: no
predict_batchin the library declares it. The suite used to assert that forwarding anyway,against a fake whose
**kwargsabsorbs anything. This corrects the prose and rebinds the claim to thereal signatures and to a runner shape that cannot absorb it.
laya/structured.py: 8 added / 3 removed lines of docstring, no code change.tests/test_structured.py: +51 / -3.Why
Router.predict_batch(laya/router.py:1590-1602),Agent.predict_batch(laya/agent.py:1409-1417) andONNXAgent.predict_batch(laya/onnx_agent.py:293-300) declare nomodelparameter and none of themtakes
**kwargs, so a keyword callpredict_batch(..., model=...)is aTypeErroron all three. Whatdecide_batchactually does withmodel=depends on which convention the runner follows(
laya/structured.py:420-431):Router-like runner (one withroute_batch) gets the routing pins and the token budget --model,task,lang,lang_guess,max_len,head_max_len(_ROUTER_REQUEST_KEYS,laya/structured.py:369) -- copied onto every request dict, because that is whereRouter.predict_batchreads them. Sodecide_batch(router, states, schema=..., model="...")works andpins a registered checkpoint.
mainalready pins that path asbatch/router model= reaches a registered checkpoint; this PR does not touch it.Agent-like runner gets**predict_kwargspassed straight through, somodel=raisesTypeErrorwhile
lang=-- whichAgent.predict_batchandONNXAgent.predict_batchboth declare(
laya/agent.py:1410,laya/onnx_agent.py:294) -- does not.The old test asserted the forwarding of
model=againstFakeBatchRunner.predict_batch(self, states, questions, **kwargs), i.e. against an object that accepts any keyword. The replacement forwardslang=,which is meaningful under both conventions, and the
model=claim is checked three ways:inspect. signature(...).bind(..., model=...)on the three real classes,_ROUTER_REQUEST_KEYSmembership, and anew
StrictAgentRunner(named keywords, no**kwargs) thatdecide_batchmeets the way a realAgentwould --
TypeErrornaming'model', andbatch_size=/lang=arriving as keywords. No checkpoint isloaded by any of these; they are signature and dispatch checks.
How it was verified
tests/test_structured.pyonmainatc4a805b5: 156 passed, 0 failed. On this branch:163 passed, 0 failed.
scripts/test_suites.py: 497 passed, 1 skipped -- all 87 suites passed, rc=0.ruff:All checks passed!, rc=0.compileall: rc=0.Mutation witnesses. Four mutants, each file restored between runs, everything committed first:
Agent.predict_batchgiven amodel: Optional[str] = Noneparameter: 159 passed, 1 failed,FAIL batch/Agent.predict_batch rejects model=: did not raise <class 'TypeError'>."model"dropped from_ROUTER_REQUEST_KEYS: 155 passed, 5 failed -- mybatch/model is one of the router's per-request keysplus fourbatch/router ...cases already onmain, all failing withTypeError("Router.predict_batch() got an unexpected keyword argument 'model'").predict_kwargs.pop("model", None)inserted indecide_batch's Agent branch, i.e. the silent-dropversion of the bug: 162 passed, 1 failed,
FAIL batch/agent-like decide_batch rejects model=: got False, want True.**predict_kwargsremoved from that same branch: 160 passed, 3 failed --batch/forwards predict kwargs(main's own, now keyed onlang=),batch/and the declared keywords reach predict_batch as keywords, and themodel=rejection above.The docstring is prose and no mutant can test it; the checks are what keep the claim honest if a runner
signature changes.
Deconfliction. All 48 open pull requests were scanned for the two files this PR touches: none has a
hunk in
laya/structured.pyortests/test_structured.py. Rebased onc4a805b5(0.4.3); neither filechanged between
68804629and it. The diff was scanned for credentials and absolute local paths -- onehit, the phrase "token budget" in the new docstring line -- no credential and no local path.
Deliberately not in this diff:
docs/structured.md:145repeats the same claim for the same function("Keyword arguments reach
predict_batch, sobatch_size=,model=and hooks work as they do fordecide"). Adocs/change owes the strict build (zensical build --strict --clean) and that tool is notinstalled in the environment I verified this in, so I kept it out rather than hand you an unverified docs
diff. Say the word and it comes as its own PR.
Checklist
mainFixes: no open issue. Found while auditing the integration surfaces for controls that are documented but
not forwarded. The public API does not change -- this removes a promise the code never kept.