Repository navigation
fix(calibrate): refuse a payload whose shape is not one this code can read - #764
Merged
NandhaKishorM merged 1 commit intoOct 1, 2026
Merged
Conversation
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
apply_calibration_payloadis the applier behindAgent.load_calibration,ONNXAgent.load_calibrationand thecalibration=constructor argument — every one of them reading a JSON file from disk, where a hand edit is one keystroke away from the shape checks in the code. The function's own message says what it wants ("calibration JSON must contain temperature: [3 floats]"), but the check only looked atlen()andpayload.get():JSON hands back
int,str,listanddictfor the mistakes just as happily as the right shapes. Measured onmain, each payload below does what the right-hand column says:["temperature", [1.0, 1.0, 1.0]](whole file is a list)AttributeError: 'list' object has no attribute 'get'{"temperature": 5}TypeError: object of type 'int' has no len(){"temperature": "abc"}list("abc")installs its characters as temperatures{"temperature": {"a": 1, "b": 2, "c": 3}}len3 passes, the dict's keys are installed{"temperature": [1.0] * 3, "version": "x"}ValueError: invalid literal for int()— no field named{"temperature": [1.0] * 3, "version": true}int(True)is 1{"temperature": [1.0] * 3, "version": {"v": 2}}TypeError: int() argument must be ... not 'dict'{"temperature": [1.0] * 3, "temperature_by_options": 5}TypeError: 'int' object is not iterable{"temperature": [1.0] * 3, "temperature_by_options": [["choice:2", 1.5]]}dict()converts the pair listThe accepted cases are the bad ones: a payload whose shape says nothing about temperatures loads with all-1.0 temperatures plus a warning that points at "invalid values" instead of "your file is the wrong shape", and the caller has no way to tell a loaded map from a refused one.
Fix
The shape is asserted before the tolerance that forgives values (which is unchanged — a non-numeric or out-of-range entry still clamps with the existing warning, and that is deliberate per the docstring):
payloadmust be an objectversionmust be an integer; a numeric string ("1") still parses exactly as before,true/{}are refused by nametemperaturemust be a list (or tuple) ofN_QTYPES, so"abc"and a 3-key dict no longer pass a length check that never asked their typetemperature_by_optionsmust be an object; a pair list is no longer silently convertedEvery refusal is the
ValueErrorthe function already promises, naming the field.Conflict check
laya/calibrate.pyis untouched by all 67 open PRs.tests/test_calibrate.pyis touched only by my own open #731 (docstring pins), whose hunks sit at the import line and the constructor-wiring section — the new block sits ~11 lines above the nearest of them, non-overlapping.Verification
Reverting only
laya/calibrate.pyfails the nine new refusal checks — with the exactAttributeError/TypeErrors and silent accepts in the table above — so they are real regression guards; the tenth new check pins that a numeric-string version still loads, and the wrong-length refusal (already caught before this change) stays as a pin.