Repository navigation
feat(serve): forward the per-call controls /v1/systemone already forwards on /v1/systemone/batch - #774
Merged
NandhaKishorM merged 1 commit intoOct 1, 2026
Conversation
…ards on /v1/systemone/batch
`Router.predict_batch` reads six controls off each request item
(max_len, head_max_len, task, lang, lang_guess, model) and three as call
kwargs (batch_size, min_confidence, sort_by_length). The batch endpoint
at laya/serve.py:851+ was synthesizing {state, questions, model} and
calling predict_batch bare, silently dropping every per-call control the
single /v1/systemone handler already honours (NandhaKishorM#724) plus the two
batch-only knobs.
Split BATCH_BODY_CALL_CONTROLS / BATCH_BODY_ITEM_CONTROLS pin the same
two-side contract against Router.predict_batch's signature and against
the single endpoint's BODY_CONTROLS, so a new core kwarg cannot be
ignored on the HTTP batch path. Refusal policy for hooks and the two
hook-execution knobs is now shared between the endpoints: predict_batch
*does* take hooks_timeout, so a batch body without the refusal would
silently shorten the operator's own hook deadline.
The predict() fallback path (an attached Router without predict_batch)
gets the same treatment so a caller that sends min_confidence on a
batch body still sees the abstention gate apply per state.
4 tasks done
Owner
|
Merged for 0.3.23. Verified on the integrated branch, not on the PR in isolation: every suite in the Thank you. |
4 tasks done
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
/v1/systemone/batchnow reads and forwards the same per-call controls/v1/systemonealready forwards (max_len,head_max_len,task,lang,lang_guess,min_confidence), plus the two batch-only knobsRouter.predict_batchtakes (batch_size,sort_by_length). It alsohonours the same
BODY_REFUSALSpolicy, so a batch body cannot silentlyshorten the operator's own hook deadline.
Concretely:
laya/serve.pygrowsBATCH_BODY_CALL_CONTROLSandBATCH_BODY_ITEM_CONTROLS, soRouter.predict_batch's split(call-level kwargs vs. per-request keys it lifts off each item) is
declared rather than implicit.
reads, using the same validators
(
_validate_budget_param,_validate_language_param,_validate_min_confidence), and adds_validate_batch_size_paramand
_validate_sort_by_length_paramfor the two batch-only knobs._systemone_inner's rule that an absent argument means "inheritwhat the Router was built with".
_refuse_body_refusalsnow guards the batch path too, which mattersspecifically because
predict_batchdoes takehooks_timeout--without the refusal a caller could hand itself a shorter deadline on
which the deployment's hooks execute.
predict()fallback (an attached Router withoutpredict_batch)gets the same kwargs so a
min_confidenceon a batch body stillengages the abstention gate per state instead of silently
disappearing on the older-Router path.
Why
Router.predict_batchreads two kinds of control: call-level keywordarguments that apply to the whole batch (chunking, padding, abstention)
and per-request keys it lifts off each item of
requests(checkpoint,task, language, token budget). The HTTP batch endpoint at
laya/serve.pywas synthesizing
[{"state": s, "questions": questions, "model": model} for s in states]and callingrouter.predict_batch(reqs)bare. Aclient that sent
min_confidence,max_len,task,lang,lang_guessor
head_max_lenat the top level -- which is what #724 taught/v1/systemoneto accept -- got a 200 as though the control had beenhonoured and none of it applied.
batch_sizeandsort_by_length,which
predict_batchtakes as call kwargs andpredictdoes not, werenot read at all.
The refusal gap is more than cosmetic.
predict_batchacceptshooks_timeoutas a call argument, and today the batch endpoint dropsit silently rather than refusing it, so a caller asking for a shorter
hook deadline on a batch body got the same non-answer the pre-#724
single endpoint gave for the same key. That is exactly the failure mode
#724 documented and closed on
/v1/systemone, left open here.The concrete use case is a caller that wants a batch of abstention-gated
decisions --
min_confidence: 0.9on a heterogeneous set of states --without paying for N single-predict HTTP round-trips. Right now that
caller either sends N singles (defeating the batch endpoint) or sends a
batch and gets back an unhedged answer they had asked to be hedged.
How it was verified
tests/test_serve.pywas at 131/131 onupstream/main; this PR adds49 tests. Two of them are pins, not behaviour:
test_batch_call_controls_are_exactly_predict_batch_kwargs_or_refusalcompares
BATCH_BODY_CALL_CONTROLS ∪ {hooks_timeout}againstinspect.signature(Router.predict_batch).parameters - {self, requests}.A new call-level kwarg on
predict_batchcannot be silently ignoredon the HTTP path; it has to be placed on one side of the
forwarded/refused line first.
test_batch_controls_cover_the_single_endpoints_set_plus_batch_onlypins
BATCH_BODY_ITEM_CONTROLS ∪ BATCH_BODY_CALL_CONTROLSagainst(BODY_CONTROLS ∪ {batch_size, sort_by_length}) - {model}, so acontrol the single endpoint forwards cannot drift out of the batch
path without a named test failure.
Mutation check
7 mutants, each a faithful single-line break to
laya/serve.py, eachproducing a NAMED FAIL on the restored tree (harness in
/tmp/mutate_serve_batch_controls.py; every mutant resets the tree andclears the
serve.*.pyccache before running so a stale bytecode filecannot hide a survivor).
_refuse_body_refusals(body)on the batch handlertest_batch_hook_control_is_refused_not_dropped[hooks_raise],[hooks_timeout], + 3 more (5 failed)batch_size=Nonetopredict_batchtest_batch_strict_predict_batch_router_answers_a_quiet_body(1 failed)**item_overridesinto the request dictstest_each_batch_item_control_reaches_every_request[max_len],[task], + 3 more (5 failed)min_confidence(if min_confidence:)test_batch_min_confidence_zero_is_still_a_threshold(1 failed)sort_by_lengtheven whenFalsetest_batch_sort_by_length_false_is_not_forwarded(1 failed)predict()fallback ignores kwargstest_batch_predict_fallback_forwards_every_control(1 failed)batch_sizevalidator usesval < 0instead ofval < 1test_bad_control_on_batch_is_refused_before_inference[batch_size-0](1 failed)StrictBatchRouter(predict_batch takes onlyrequests) is the witnessbehind M2. The endpoint's "send kwargs only when the caller asked" rule
is what keeps an attached Router that predates #766 answering on a
quiet body -- M2 breaks that guarantee and the strict-router test names
it.
Design notes
Router.predict_batchreads
max_len/head_max_len/task/lang/lang_guessoffeach item of
requestsso different requests in a batch can carrydifferent budgets -- the endpoint's HTTP body has one control set,
so every synthesized item receives the same override.
min_confidence,batch_sizeandsort_by_lengthapply to the call as a whole andgo on the kwargs.
_validate_batch_size_paramrejects aboolexplicitly.boolisan
intsubclass, soisinstance(val, int)would letTruethrough; the MCP tool at
laya/mcp/tools.py:_validate_batch_sizerefuses the same shape, so the two surfaces agree on what "typo"
looks like.
sort_by_length=Falseis accepted (aFalsevalue is not a422) but not forwarded.
predict_batch's own default isFalse, andforwarding
Falseexplicitly to an agent whosepredict_batchpredates the knob (feat(agent): group batch inputs by encoded length #294) would silently disappear -- which is the
same reason the MCP tool makes the same choice at
laya/mcp/tools.py:947-948.predict()fallback path uses a "no kwargs when body is quiet"shape (
elif predict_kwargs: …thenelse: … predict(s, questions, model=model)) so an attachedFakeRouter-shape Router whosepredict(self, state, questions, model=None)takes nothing elsestill answers on a bare batch body.
Not in this PR
docs/http-api.mdstill says "no batch endpoint" at line 194. Thatis a pre-existing lie about the shipped HTTP surface --
serve.pyhashad
/v1/systemone/batchsince before this PR -- and it is unrelatedto the controls gap closed here. The follow-up belongs in a docs PR
that adds the batch table and extends the existing
test_http_api_page_documents_exactly_the_forwarded_controlspin toread both tables.
_has_lone_surrogateis still not applied on the batch body. Thesame "unpaired surrogate escape becomes a 500 rather than a 400" bug
that
laya/serve.py:716fixes on the single path is present on thebatch path. That is a different bug class (HTTP status mapping, not
control forwarding) and belongs in its own PR.
Checklist
Focused on one change (split unrelated work into another PR)
Rebased on the latest
mainTests pass locally
Docs or examples updated when the public API changed
(No new documented API changed; the batch endpoint's controls
surface is being brought to parity with the already-documented single
endpoint. Batch-endpoint documentation is called out above as
out-of-scope.)
Fixes #