Repository navigation
fix(serve): refuse unhashable tournament choice labels with a 422, not a 500 - #1366
Conversation
…t a 500 When LAYA_TOURNAMENT_GROUP is on, _tournament_plan reads a large choice's criteria labels -- de-duplicating them through a set -- BEFORE router.predict runs, so core's Agent._check_question (which refuses a non-scalar label with a ValueError naming the question) has not seen the request yet. A criteria written as a list of JSON arrays/objects therefore raised a bare `TypeError: cannot use 'list' as a set element`, which fell through the endpoint's catch-all and answered 500 "inference failed" with a traceback per request. Wrap the label read and re-raise the TypeError as the same ValueError the sibling duplicate-/empty-label paths already raise, so an unhashable label is a 422 naming the question -- matching the no-tournament behaviour, where the same input already returns a clean 422. Tests: tests/test_serve.py tournament section, +2 (316 -> 318).
8 PRs. Rust and .NET batch prediction and router batch APIs (#1358, #1359), the min_confidence abstention gate and jev_confidence in both ports (#1362, #1363), and four inputs refused where they enter instead of failing later (#1365, #1366, #1367, #1368). Verified before tagging: all 92 suites pass, 612 tests. ruff clean on both lists. Java fixture, Unicode table and language table gates clean; three Go tables_gen.go match. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.16 only. Security audit of the merge diff, 180330 added lines over 349 files: zero dynamic exec, zero network calls, zero URLs, zero base64 or obfuscation, zero secrets in the diff or the tracked tree, zero laya-max boundary hits, no writes outside the test temp dir, the dependency surface untouched, no npm install hooks, no binaries, every new file 100644, and 20 of 20 actions SHA-pinned with codeql-action init, autobuild and analyze all on 4.39.1. Held from this release: #1364 (correct in Python but it moves a cross-port contract Decisions.java reproduces deliberately and structured.ts shares), #1324 (real table regression), and seven dependency and action bumps for a pass of their own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged, in 0.4.16. The ordering argument is what makes this correct. Converting it to the same
The positive control in |
What
With
LAYA_TOURNAMENT_GROUP >= 2(documented,docs/http-api.md), a large choice is narrowed by elimination.laya/serve.py::_tournament_planreads every oversized choice's criteria labels — and_criteria_itemsde-duplicates them through aset— beforerouter.predictruns. Acriteriawritten as a list of JSON arrays/objects gives an unhashable label:The tournament gate at
serve.py:432runs beforerouter.predict, so core'sAgent._check_questionnever sees it; theTypeErrorfell through the endpoint's catch-all and answered 500 "inference failed" with a traceback per request.Why
The endpoint documents a 422 that names the offending question, and every sibling refusal already produces exactly that. The same
create_app()withLAYA_TOURNAMENT_GROUPunset answers the identical request with a clean 422 namingqueue(core's_check_question); and inside_tournament_planthe duplicate-label and empty-listValueErrors from_criteria_itemsalready propagate to a 422. Only the unhashable-label case, which surfaces as aTypeError, reaches the 500 — the asymmetry is the bug. Fixing it in_tournament_planis the one site that touches a request body before core validation, so no core behaviour changes.How it was verified
Regression cases go into the already-registered
tests/test_serve.py, in theLAYA_TOURNAMENT_GROUPsection next totest_large_choice_is_refused_without_a_tournament.Checklist
docs/http-api.md, which previously only held on the non-tournament path)