Repository navigation
test(java): follow #1315's English words in two stale router tests - #1323
NandhaKishorM merged 1 commit into
Conversation
…er assertions main is red on `93dcdf9d` carried the 82 English function words into `LanguageTables.java` and regenerated the fixtures, but left two hand-written assertions asking for the answer a plain English state used to get: - `RouterLifecycleTest.closeFreesAndSeals` expected MULTILINGUAL for "plain english text here now". The port answers english -- measured, not inferred: running the suite with the base assertion prints `expected: <multilingual> but was: <english>`. - `RouterTest.abstainingHintFallsThrough` accepted any reason starting with "Latin script", which is also the prefix of the reason detection gives when it cannot identify a language. Once the state is identified the assertion is not the test's point any more, so it now compares detection's recorded reason exactly -- the same pair the `lang-agnostic-C-falls-through` row of router.json records -- and pins the model and the presence of a detection too. `laya/` and the fixtures are untouched: this is the Java test catching up with the reference, not a change to it.
`AgentConfig` kept the `double[]` and the two `Map`s its parser passed in, and `temperatureByOptions()`/`langTemperatures()` handed the internal maps straight back out. A caller that built the config from its own collections — or that kept a config it was given — could retune a loaded checkpoint after the fact, and every later prediction would quietly use the edited temperature. `temperature()` already cloned, so this was an inconsistency rather than a policy. Copied at the boundary instead: `clone()` for the array, `Map.copyOf` for the maps, and a compact constructor on the `LangTemperatures` record because its `double[]` is a mutable component. Both parsers already pass immutable maps and `Map.copyOf` returns such a map unchanged, so the load path pays nothing new. Verified: ./gradlew test (JDK 17, -Xlint:all -Werror) 1182 tests, only the two inherited RouterTest/RouterLifecycleTest failures of NandhaKishorM#1323; jcheck's EscapingMutableInternal (J0603) drops from 16 to 11 with all five AgentConfig hits gone.
`open()` never closed its `OrtSession.SessionOptions`: they are an input to `createSession`, not something a live session keeps, so every load leaked one native options structure for the life of the process. That is invisible until a caller reloads checkpoints and native memory keeps climbing. While there: in the split form (`encoder.onnx` + `head.onnx`), a failure creating the head session closed nothing. `close()` is only reachable through a `LayaSession`, and that path never constructs one, so the encoder outlived the failed load. It is closed now, with its own failure attached as suppressed, the way `close()` itself reports a second failure. `OrtEnvironment` is deliberately untouched: it is ONNX Runtime's process-wide singleton, and closing it would break every other session in the process. Verified: ./gradlew test (JDK 17) 1182 tests, only the two inherited failures of NandhaKishorM#1323; the sample programs still compile and jcheck reports 0 diagnostics for them against the rebuilt classes.
… and releasing it In `predict`, the `languageFor(...)` call sat between the lease acquisition and the `try (Lease held = lease)` that releases it; in `predictBatch`, the `contexts`/`indexOf` allocations did. Neither throws today, but an `OutOfMemoryError` from either would leave the lease held with no owner able to release it — the same shape as the unreleased lock CodeQL found in `Router.build`. `languageFor` now runs inside the try; the two collections are built before the acquisition. The statement after taking a lease is the one that releases it. Verified: ./gradlew test (JDK 17) 1182 tests, only the two inherited failures of NandhaKishorM#1323 (which is the language-detection expectations, not this path).
|
Merged as c7eb30a. Thank you, this was the only red lane on main and your diagnosis matches what the logs show exactly. I had reached the same two assertions independently before I found this PR, and yours is the better change, so I dropped mine. Two reasons. You also assert Confirming the chain independently, for the record:
All four previously red jobs are green on your branch, and the lane is rebuilding on main now. Two things this exposed that are on me, not on you:
|
`AgentConfig` kept the `double[]` and the two `Map`s its parser passed in, and `temperatureByOptions()`/`langTemperatures()` handed the internal maps straight back out. A caller that built the config from its own collections — or that kept a config it was given — could retune a loaded checkpoint after the fact, and every later prediction would quietly use the edited temperature. `temperature()` already cloned, so this was an inconsistency rather than a policy. Copied at the boundary instead: `clone()` for the array, `Map.copyOf` for the maps, and a compact constructor on the `LangTemperatures` record because its `double[]` is a mutable component. Both parsers already pass immutable maps and `Map.copyOf` returns such a map unchanged, so the load path pays nothing new. Verified: ./gradlew test (JDK 17, -Xlint:all -Werror) 1182 tests, only the two inherited RouterTest/RouterLifecycleTest failures of #1323; jcheck's EscapingMutableInternal (J0603) drops from 16 to 11 with all five AgentConfig hits gone.
`open()` never closed its `OrtSession.SessionOptions`: they are an input to `createSession`, not something a live session keeps, so every load leaked one native options structure for the life of the process. That is invisible until a caller reloads checkpoints and native memory keeps climbing. While there: in the split form (`encoder.onnx` + `head.onnx`), a failure creating the head session closed nothing. `close()` is only reachable through a `LayaSession`, and that path never constructs one, so the encoder outlived the failed load. It is closed now, with its own failure attached as suppressed, the way `close()` itself reports a second failure. `OrtEnvironment` is deliberately untouched: it is ONNX Runtime's process-wide singleton, and closing it would break every other session in the process. Verified: ./gradlew test (JDK 17) 1182 tests, only the two inherited failures of #1323; the sample programs still compile and jcheck reports 0 diagnostics for them against the rebuilt classes.
… and releasing it In `predict`, the `languageFor(...)` call sat between the lease acquisition and the `try (Lease held = lease)` that releases it; in `predictBatch`, the `contexts`/`indexOf` allocations did. Neither throws today, but an `OutOfMemoryError` from either would leave the lease held with no owner able to release it — the same shape as the unreleased lock CodeQL found in `Router.build`. `languageFor` now runs inside the try; the two collections are built before the acquisition. The statement after taking a lease is the one that releases it. Verified: ./gradlew test (JDK 17) 1182 tests, only the two inherited failures of #1323 (which is the language-detection expectations, not this path).
33 PRs. Server hardening (#1331, #1332, #1333), TypeScript parity (#1330, #1336, #1337, #1338, #1339, #1340, #1341, #1342, #1343), fail-closed input handling in evals and the integrations (#1317, #1318, #1319, #1320, #1321, #1322, #1326, #1335), exact and faster script detection (#1334, #1349), JVM and .NET resource handling (#1327, #1328, #1329, #1346), port goldens and clipping (#1324 excluded, #1325, #1344, #1345), CI (#1323, #1347, #1348). Verified before tagging: all 92 suites pass, 610 tests. ruff clean on both lists. laya-ts 1247 tests across 44 files, tsc --noEmit clean. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.15 only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
Two hand-written assertions in
laya-java's model-free suite still ask for the answer a plainEnglish state gave before #1315's English function words were carried into this port. Both now
fail, on
mainat0a05a450(release 0.4.14), in every JDK cell:laya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterLifecycleTest.java::closeFreesAndSealsCheckpoint.MULTILINGUALfor"plain english text here now"Checkpoint.ENGLISHlaya-java/laya-java/src/test/java/com/convaiinnovations/laya/RouterTest.java::abstainingHintFallsThroughreason().startsWith("Latin script")"English Latin text", exactly, plus the model and the presence of a detectionlaya/, the fixtures and the port's production code are untouched. This is the Java test catchingup with the reference, not a change to it.
Why
93dcdf9d("SDKs: carry #1315's 82 English function words into all four ports") added the words toLanguageTables.java, regeneratedlang_tables.json/lang_detect.json/router.json, andupdated the reference's own tests (
tests/test_router.pygainedcheck("route/english question words …", Router().route(text).model, "english")). Two assertionsthat hard-code the old detection answer were left behind, so the lane has been red since 12:45Z:
The workflow itself still reports success because the two jobs that went red,
buildandjdk-matrix, setcontinue-on-error: true-- the file's own header says why: "ADVISORY, notblocking … When this lane goes red the fix is a follow-up port, not a revert of the Python change."
That follow-up port is this PR.
ci.yml,go.yml,rust.ymlanddotnet.ymlare green on the samecommit, so this is Java-only: the other three ports had their recorded probes updated in
93dcdf9dand assert nothing about the old answer.
The port answers correctly; the assertions are what is stale — three independent witnesses:
AssertionFailedError: expected: <multilingual> but was: <english>.RouterTest::every recorded route matches, model and reason-- the fixture-driven replay of all 47recorded
routesrows -- passes at base, including the rowlang-agnostic-C-falls-through, samestate string and same code that names no language, which records
"model": "english", "reason": "English Latin text".0a05a450:Router().route("plain english text here now")→
english,"English Latin text";analyse(...)["language"] == "en", so the removed comment"Undecided, not identified English (analyse gives language=null)" is now a false statement.
The prefix form was worth replacing rather than re-pointing, because
"Latin script"is also theprefix of the reason detection gives when it cannot identify a language (
laya/router.py::route:"Latin script, language not identified and no non-English letters; …"). It proved the hint stayedout of the decision only while plain English stayed undecided. Exact comparison to the recorded
reason is what the same file already does for its other detection case (
routingIsPureasserts"English Latin text").How it was verified
Gradle could not run here: the pinned wrapper is 8.10.2, which refuses to start on the only JVM this
Mac has (26.0.1), and the build's JDK 17 toolchain is not provisioned. So the suite was compiled and
launched directly —
javac --release 17(which is what the build pinsoptions.releaseto) with theonnxruntime jar the module declares, then the JUnit Platform launcher, with
-Djunit.jupiter.extensions.autodetection.enabled=trueandsrc/test/resourceson the classpathexactly as the build configures the
Testtask. Reproduced inlaya-bench/java_model_free.sh <worktree>(outside the repo).1166 + 2 → 1168 + 0: the two failures clear and nothing else moves.
found,startedandabortedare unchanged at 1182 / 1181 / 13, so no test was added, renamed or lost — which matters because the
lane asserts
check_test_results.py --min-tests 1168and this run meets that floor exactly, the samefigure the workflow's own comment records.
The four new or changed assertions were each mutated to check they carry weight; every arm failed:
RouterTest:ENGLISH→MULTILINGUALon the new model assertionRouterTest: reason literal"English Latin text"→"Latin script"RouterTest:assertTrue(fallback.detection() != nullflippedRouterLifecycleTest:ENGLISH→MULTILINGUALCompile hygiene, since
build.gradle.ktsapplies-Xlint:all -Werrorto test compilation too:(the run does print
dangling-doc-commentswarnings in four untouchedsrc/mainfiles — that is alint category JDK 26 added, not one JDK 17's
-Xlint:allhas, so it is an artifact of the localcompiler rather than something CI sees.)
Fixture contract, which is the gate a Python-side change has to pass and this is not: no
laya/filechanged, and
gen_fixtures.py --checkon this branch is byte-identical to the same command on apristine
0a05a450worktree (stdout empty, rc=1 both, stderr identical after normalising the treepath). The two families it calls stale locally —
lang_detect.json,python_json.json— are thismachine's environment noise, recorded before this change and reported by the pristine tree too; CI's
own run of that step on
mainprints20 family/families match laya (9 unverified).Out of scope, deliberately
ShoutedAcronymBarTest's anddefaultCheckpointDecidesUndecided's claims about undecided textwere re-checked against the reference rather than assumed:
"Quero cancelar"still analyses tolanguage=None, so those tests still say what they claim. Only the two above were stale.laya/lang.py,LanguageTables.javaor any fixture: the wordlist change is thereference's, this branch only follows it.
continue-on-errorpolicy injava.ymlis a maintainer decision, not something thisPR should reopen.
Checklist
main