Repository navigation
fix(serve): refuse an unpaired surrogate on /v1/systemone/batch too - #814
Merged
NandhaKishorM merged 3 commits intoOct 1, 2026
Merged
Conversation
06462bf turned a lone `\udXXX` escape into a 400 on /v1/systemone and recorded the limit as "only /v1/systemone is checked". The batch route tokenizes the same body, so on it the caller's own string still came back as a 500 inference failed. The detail message moves to a module constant both handlers raise with, so the two routes cannot drift on what they answer.
Three slots per route, each asserted for the 400, the shared message and the router never seeing the body, plus a paired-surrogate arm so the guard cannot be widened into rejecting every emoji.
…e batch route The page said there was no batch endpoint while /v1/systemone/batch had shipped for releases; it now names the route and states which of the checks above it shares.
4 tasks done
Owner
|
Merged for 0.3.24. Lifting the message into The Verified on the integrated branch: Thank you. |
This was referenced Nov 3, 2026
NandhaKishorM
pushed a commit
that referenced
this pull request
Nov 3, 2026
stateText sliced its 4000-character budget with String.slice, which counts UTF-16 units, so a state whose 4000th unit was the high half of a surrogate pair returned text ending in an orphaned surrogate -- malformed text Python's state_text never produces, and the same lone-surrogate shape laya-serve already refuses as a request (#454, #814). The segment scan and the 4000-character leaf samples cut the same way. cutCodePoints mirrors the email port's helper, added there when a budget cut an emoji in half. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
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/batchhad no lone-surrogate guard while/v1/systemonehas had one since 06462bf,even though it tokenizes the same body. This puts the same check on the batch route, lifts the
400message into a module constant both handlers raise with so the two cannot drift, and pinsboth routes against the same strings in
tests/test_serve.py.Three files:
laya/serve.py(the guard in_systemone_batch_inner, the shared_LONE_SURROGATE_DETAIL, and the module docstring, which named only one of the two routes),tests/test_serve.py(8 new cases),docs/http-api.md(the400row and a paragraph on why thatstatus looks unusual, plus the page's "Not (yet) here" section, which still denied a batch endpoint
that has shipped for releases).
Why
06462bf turned a lone
\udXXXescape into a400on the single route and recorded what it had notcovered -- "only
/v1/systemoneis checked". The batch route went on walking no guard. Measured on4185647with the cachedenglishcheckpoint on CPU:The
TypeErrorisTextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]], raised fromlaya/agent.py:1028 _encode_state()throughlaya/common.py:35 encode_text(). The HTTP columns were measured with a stub router that does not tokenize -- with areal one all three batch bodies are
500 inference failed, because this route maps everyexcept Exceptionto that string and writes a_log.exceptiontraceback per request. So amalformed string in the caller's own body was reported as a server fault to the caller and as an
operator-facing traceback to the log, which is exactly the shape 06462bf exists to stop; the
difference is only that on this route a batch carries several states, so an escape in the second
one was enough to get there.
The guard walks the whole parsed body, not
states, becausepredict_batchtokenizes every stateand every question -- the
instructionsand criteria-label slots are the same bug through theother field. It is ordered as on the single route: after
_check_batch_limitsand_refuse_body_refusals, soMAX_BATCH_STATES,MAX_STATE_CHARSandMAX_QUESTIONSbound whatthe walk can reach. A paired surrogate is one ordinary astral character by the time
json.loadsisdone, so an emoji keeps reaching the router -- asserted for both routes, since a check keyed on
surrogate code points rather than unpairedness would reject those too.
How it was verified
The 8 new cases are 3 slots x 2 routes for the refusal, plus the paired-surrogate arm per route.
Each refusal asserts the
400, the message read fromlaya.serverather than retyped in the test,and that the router recorded neither a
predictnor apredict_batchcall -- so a guard placedafter the forward pass fails even though it still returns a
400.Mutating the branch is what shows the tests bite, and which one shows each half is load-bearing. 14
arms, each a fresh copy of the tree, run against the whole serve suite; an arm passes only when the
failing test ids are exactly the set it should break:
0 of 14 arms misbehaving. The three B arms are the point of this PR: the batch route's guard hadno test at all, so every one of those drifts is invisible to the suite as it stands on
main.No public API changed: both routes accept exactly the bodies they accepted before, and the only
response that differs is that three batch bodies which used to reach inference now answer
400.tests/test_hooks_api.pyis the hook API contract; this touches neither hooks nor that contract.Related work I can see: #716 and #667 both edit
tests/test_serve.py, and #667 edits thecreate_appbody next to this guard (GET /v1/models); neither adds a surrogate check -- I readtheir diffs for
surrogateandhas_lone_surrogateand both come back empty. #774 merged whilethis branch was being built, so it is rebased on top of it: the batch route now shares the single
route's control validation and hook refusals, which is why the docs paragraph here says every
check above applies to both routes rather than carving an exception out for the
422row.Checklist
mainFixes # (no open issue: the gap is the limit 06462bf wrote down for itself -- "only
/v1/systemoneis checked" -- and no issue proposes carrying it to the batch route)