Skip to content

fix(ts): report a bool temperature a checkpoint shipped, not load it silently - #1191

Merged
NandhaKishorM merged 2 commits into
NandhaKishorM:mainfrom
aashish254:fix-ts-bool-temperature-diagnostic
Oct 14, 2026
Merged

NandhaKishorM merged 2 commits into
NandhaKishorM:mainfrom
aashish254:fix-ts-bool-temperature-diagnostic

Conversation

@aashish254

@aashish254 aashish254 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

laya-ts/src/agent.ts:450 now refuses to stay quiet when a checkpoint config ships a boolean where a
temperature belongs, and laya-ts/tests/temperature-loading.test.ts is added as the first test over
that load-time diagnostic.

// before
if (Number(rawV) === applied) continue;
// after
if (typeof rawV !== "boolean" && Number(rawV) === applied) continue;

One condition line plus the three comment lines that explain it, and one new test file. No public API
changed, no other behaviour touched.

This is the port of the Python fix that went up as #1190 (laya.common.temperature_rejected, used by
laya/agent.py, laya/onnx_agent.py and laya/calibrate.py). The two loaders carry the same
diagnostic and had the same hole, so both now ask the question the clamp itself asks.

Why

clampTemperature treats a bool as "not a number" and installs the neutral 1.0. The rejection test
then asked whether the raw value converts to the number it was turned into -- and Number(true) is
1.0, exactly the fallback. So the comparison matched, the entry was judged accepted, and a checkpoint
shipping "temperature": [true, 2, 3] loaded in silence with temperature[0] replaced by a value no
calibration ever fitted. false was reported, but only by accident: it floats to 0.0, mismatches the
1.0 fallback, and so looks like any other bad entry. Same input class, two opposite outcomes, which is
the tell that the test was re-deriving the clamp's answer instead of asking what the clamp did.

Confidence read off that silent entry is uncalibrated, and nothing told the user. The new path names
both the list entry and the bucket:

laya: this checkpoint ships invalid temperatures or values outside [0.5, 5]; using temperature[0]=true -> 1, choice:2=true -> 1. Treat confidence from the affected entries as uncalibrated.

Behaviour kept deliberately, and pinned by tests so the next edit cannot lose it: numeric strings that
equal the applied value ("2" -> 2.0) stay silent, out-of-range values are still named per entry, and
null / undefined / "" / {} / "invalid" are still named. The empty list is not "fixed" to
match Python: JS's Number([]) is 0, so the clamp bounds it to TEMP_MIN where Python's float([])
raises and falls back to 1.0. The test asserts the port's own [0.5, 2, 3] and says why in a comment.

How it was verified

Steps 1-4 run on npx --yes vitest run, i.e. the repo's own runner against the committed test file, so
the assertions are witnessed rather than assumed. Step 5 is a compiler cross-check. One command in
npm test could not run here at all and is called out at the end.

# 1. red at base: pristine upstream/main (c73908d9) in a throwaway worktree, with only the new test
#    file copied in -- the source is main's, unmodified
$ npx --yes vitest run tests/temperature-loading.test.ts
   × reports a true where a temperature belongs
     AssertionError: expected [] to have a length of 1 but got +0
   ✓ reports a false where a temperature belongs
   ✓ keeps reporting an out-of-range value on every entry
   ✓ does not report a number, or a numeric string that equals the applied value
   ✓ still reports a value that is not a number at all
 Tests  1 failed | 4 passed (5)
# `true` silent, `false` reported: that asymmetry *is* the bug, shown by the test that pins it.

# 2. the same file on this branch
$ npx --yes vitest run tests/temperature-loading.test.ts
 ✓ tests/temperature-loading.test.ts (5 tests) 4ms
 Tests  5 passed (5)

# 3. the whole TS suite, before and after, measured rather than computed
$ git worktree add --detach /tmp/base_ts_main c73908d9   # base, without my file
 Test Files  1 failed | 34 passed (35)
 Tests  1 failed | 885 passed (886)
$ npx --yes vitest run                                   # this branch
 Test Files  1 failed | 35 passed (36)
 Tests  1 failed | 890 passed (891)
# +5 tests, and the one failure is unchanged: tests/load-robustness.test.ts:70
# (`expect(encFetch?.signal).toBe(c.signal)`), red on pristine main in this environment too,
# untouched by this PR.

# 4. mutation harness, driven by vitest (each arm restores src/agent.ts from `git show HEAD:` bytes)
$ python3 -B /tmp/mut_ts_vitest.py
baseline (HEAD): green 
KILL     T1 revert to the base comparison -> defeated test(s): reports a true where a temperature belongs
KILL     T2 drop the numeric equality (report every non-bool) -> defeated test(s): keeps reporting an out-of-range value on every entry; still reports a value that is not a number at all
KILL     T3 skip a bool whose Number() matches the fallback -> defeated test(s): reports a true where a temperature belongs; does not report a number, or a numeric string that equals the applied value
restored (HEAD): green 

kills=3 survivors=0
git status --porcelain after restore:
?? laya-ts/node_modules
# the only leftover is the node_modules symlink the harness needs to resolve vitest; it is untracked
# and removed before pushing. src/agent.ts is byte-identical to HEAD after every arm.

# 5. cross-check with the compiler: src/agent.ts contributes no type error of its own
$ node .../typescript/lib/tsc.js -p <scratch config: types [], noEmitOnError false> | grep -c '^src/agent.ts'
0
# (24 errors overall -- src/providers.ts 17, src/router.ts 5, src/tokenizer.ts 2 -- all of them
#  `Cannot find name 'process'` or `Cannot find module 'node:*'`, from the absent @types/node)

T1 is the arm that matters: reverting only the condition makes exactly one test fail, and it is the
true one while false stays green. T2 and T3 break the silent-and-named guarantees in the other
directions, which is how the harness shows the tests guard the whole behaviour, not just the new line.

Numbers, before and after, for cfg.temperature = [true, 2, 3] with temperature_by_options = {"choice:2": true}:

before after
agent.temperature [1, 2, 3] [1, 2, 3] (unchanged)
agent.temperatureByOptions {"choice:2": 1} {"choice:2": 1} (unchanged)
console.warn calls 0 1, naming temperature[0]=true -> 1 and choice:2=true -> 1
systemOne probability at the neutral T 0.8808 0.8808 (unchanged; the test asserts it, so the fallback being used is proven by a forward pass, not by reading the field)

The applied values are identical on purpose: this changes only whether the substitution is reported.

What could not run here. npm test is test:types && vitest, and test:types
(tsc --noEmit -p tests/tsconfig.types.json) cannot run in this checkout: the vendored
laya-ts/node_modules has no .bin, so npm run test:types stops at sh: tsc: command not found,
and invoking the local compiler directly leaves one error, TS2688: Cannot find type definition file for 'node', because @types/node is not installed. Worth noting for reviewers: that gate includes
only types/**/*.ts, so it never compiles any test file, mine included. CI's typescript job does a
real npm ci on node 20 and 22 and runs npm test -- --run, so both halves will be exercised there.

Overlap with open work

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main (c73908d9 release: 0.4.6)
  • Tests pass locally -- vitest run is green on the new file (5/5) and the suite has no new
    failure; the test:types half of npm test cannot run in this checkout, for the reason stated
    under "What could not run here".
  • Docs or examples updated when the public API changed -- no public API changed, so nothing to update

…silently

The port carries the same load-time diagnostic as `laya/agent.py` and has the same hole:
`clampTemperature` refuses a bool and installs the neutral 1.0, and `Number(true)` is exactly
that 1.0, so `if (Number(rawV) === applied) continue;` read a JSON `true` as an accepted
temperature and said nothing. `false` was reported only because it floats to 0.0 and mismatches.

`laya-ts/tests/temperature-loading.test.ts` is the first test over this loop: both bools named
on the list and on a bucket, the neutral 1.0 proven to be what the answer is actually scaled by,
out-of-range still named per entry, numeric strings and exact numbers still silent, and the
non-number class still named. Python's loader got the matching change with the shared
`laya.common.temperature_rejected`; the empty-list case is called out rather than "fixed", since
`Number([])` is 0 where Python's `float([])` raises.
The assertion said which temperature clampTemperature installs for an empty list, and
that value is the one place the port and the reference disagree (Number([]) is 0 so the
port bounds it to TEMP_MIN, where Python's float([]) raises and falls back to the neutral
1.0). This test is about the loader naming the entry, not about which fallback it chose,
so keep the naming assertion and drop the value.
@NandhaKishorM
NandhaKishorM merged commit a651448 into NandhaKishorM:main Oct 14, 2026
42 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged in 0.4.7, alongside the Python side in #1190.

Same bug, same cause, in the port: Number(true) is the neutral 1.0 the clamp installs for a bool, so comparing the two numbers read a JSON true as an accepted temperature. typeof rawV !== "boolean" is the minimal honest guard.

The test is doing more than naming the warning. It checks the answer is actually scaled by the 1.0 that was installed (logits [2, 0] at T=1 publish 0.8808), which is the thing a caller is affected by, and the list case is correctly scoped: only the naming is asserted, because which number the clamp installs for [] was a separate question that #1192 settled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants