Repository navigation
fix(calibrate): a falsy non-object temperature_by_options is a refused shape - #1109
Conversation
…d shape
`payload.get("temperature_by_options") or {}` hid JSON's `0`, `0.0`, `""`,
`false` and `[]` behind an empty bucket map, so a file this code cannot read
loaded and silently dropped every per-bucket temperature. The docstring names
that field as refused, and its sibling `binning_map` already refuses the same
values. `null` and an absent key stay tolerant -- that is the file-from-before
case -- so the guard is `is None`, matching `binning_map`'s policy.
35 pull requests from 11 contributors. Headline #1072: sdk/typescript's response validation rejected the x_jev_confidence that 0.4.2's #1066 started sending, so the TypeScript SDK lane has been red on main since that release. Also #1073 (LAYA_TOURNAMENT_GROUP), #1083 (laya.jev_confidence), #1105 (model: null across all four MCP tools), #1104, #1109, #1112, #1113, #1108 and #1117 (laya-ts), #1090 (Java floors remeasured on the merged tree), and 20 documentation and test-gate corrections. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged in 0.4.3. What I measured on the merged tree, calling
So all five previously-silent shapes are refused and the tolerant half is intact. Keeping A calibration file that loads "successfully" with an empty temperature map is the worst outcome of the three, because confidence then comes back uncalibrated with no signal that the file was misread. Verified: |
What
apply_calibration_payloadnow refuses atemperature_by_optionsthat is a falsy non-object.becomes
tests/test_calibrate.pygains seven checks: five refusals and two that pin the tolerant half(
nulland an absent key still install an empty map).Why
The
or {}swallows JSON's0,0.0,"",falseand[]before the type check ever sees them,so those payloads load "successfully" with
temperature_by_options == {}. The user-visible result isa calibration file whose per-bucket temperatures are gone — every bucket answers at the per-type
temperature — with no error and no warning.
Three things make this a defect rather than a policy:
apply_calibration_payload's own docstring lists it among the refused shapes: "atemperature_by_optionsthat is not an object, abinning_mapthat is not an object ... is afile this code cannot read." The two fields named in the same sentence behave oppositely —
binning_mapis tested withis not None, so it refuses all five of these values.length check and install its keys as temperatures."
test_calibrate.py:645-649refuses the scalar5and anon-empty list of pairs
[["choice:2", 1.5]]), so the check exists and works — it is only thefalsy values that slip through it. A file truncated or mis-edited into an empty container is the
case that most needs the error, and it is the case that currently produces none.
nullis deliberately not made a refused shape: a payload written before bucket temperaturesexisted simply has no key, and an explicit null means the same thing. Keeping that half is why the
guard is
is Nonerather than dropping the default.No tracked issue for this — it came out of a docstring-vs-behavior audit of
laya/calibrate.py, andI could not find it among the open PRs:
laya/calibrate.pyis touched by zero of them.How it was verified
ValueError-or-load result printed bycalling
apply_calibration_payloaddirectly):tbo=[] -> LOADED tbo={},tbo=0 -> LOADED tbo={},tbo='' -> LOADED tbo={},tbo=False -> LOADED tbo={}, whiletbo=5 -> ValueError: ... must be an object of bucket -> float, got int, and, for the siblingfield,
bm=[] -> ValueError: calibration JSON binning_map must be an object ...— the asymmetrybetween the two fields the same docstring sentence lists. (
0.0is covered by the new checksrather than by this probe; see the next bullet, where it fails on the unfixed code.)
python tests/test_calibrate.py: 240 passed, 0 failed on this branch (2.90 s), against233 passed, 0 failed on the pre-fix code (3.35 s) — the same file plus the seven new checks, so
the runtime is unchanged. The pre-fix arm ran in a tree whose
laya/calibrate.pyandtests/test_calibrate.pyare byte-identical toupstream/main(confirmed withgit diff --stat upstream/main -- laya/calibrate.py tests/test_calibrate.py, which prints nothing).laya/calibrate.py(fix reverted from the same tree, testskept): 235 passed, 5 failed, and the five failures are exactly the new
shape/falsy non-object by_options 0 / 0.0 / '' / False / []checks. No pre-existing checkchanged state.
nullis refused (while an absent key istolerated) dies at
tests/test_calibrate.py:668, the newshape/null by_options installs an empty mapcall — so that check is load-bearing, not decoration.ruff check laya/ ...→All checks passed!;python -m compileall -q laya/ tests/→ exit 0.python scripts/test_suites.py→ all 86 suites passed (469 passed, 1 skipped), identical tothe numbers on
main, so nothing that passes a bucket map through the loader broke.temperature_by_options(docs/finetune.md,README.md, the three integration pages); none of them states the falsy-tolerance, so no page goesstale with this change.
Checklist
main