Skip to content

feat(rust): revision pinning and SHA-256 digest checks - #1390

Open
kevin-gatimu wants to merge 7 commits into
NandhaKishorM:mainfrom
kevin-gatimu:feat/rust-revision-digests
Open

kevin-gatimu wants to merge 7 commits into
NandhaKishorM:mainfrom
kevin-gatimu:feat/rust-revision-digests

Conversation

@kevin-gatimu

@kevin-gatimu kevin-gatimu commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Merge order: last in the Rust chain; depends on #1388, only the last commit is new (see #1439).

Ports laya/revisions.py (0.4.16):

  • LayaOptions::revision / expected_sha256, LAYA_REVISION, LAYA_SHA256_DIGESTS, "reviewed" pins
  • Pinned downloads use resolve/<revision>/ and are cached under <cache>/<revision>/<checkpoint>; unpinned is unchanged
  • Digests are verified before anything loads, local directories included
  • Router: revisions, sha256_digests (flat or nested env), loaded_revisions
  • The "onnx" key means the fused model.onnx; it is refused on split checkpoints
  • Adds the sha2 crate

Tests: a model-free probe recorded from Python's own functions (shared with the .NET PR) and a local fake-Hub server. 427 passed with all checkpoints, 0 failed, 0 skipped.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 00:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@NandhaKishorM

Copy link
Copy Markdown
Owner

Held for integration, not on merit. This is one of nine PRs in the same chain that were each opened against main independently, so they conflict with each other as soon as any one lands. I merged #1370, #1371, #1373, #1374, #1375, #1379 and #1384 clean, and then the rest of the stack collided.

The full conflict map and what I need is on #1377, so I am not repeating it here: short version, pick an order, rebase each onto the one before it, and regenerate golden/*/index.json rather than hand-merging the appended case lists.

For this one specifically, the conflicting paths against the integration branch were:

CHANGELOG.md, src/laya_engine.rs, src/laya_options.rs

NandhaKishorM added a commit that referenced this pull request Oct 28, 2026
24 PRs. Vietnamese kept off the English checkpoint (#1392), deciding-window
attribution preserved through end hooks (#1369), RemoteRouter identifying
itself with a configurable User-Agent (#1396), ten more inputs refused where
they enter (#1372, #1394, #1397, #1398, #1400, #1401, #1402, #1403, #1404,
#1405, #1406), per-language temperatures and per-call budgets in .NET and
Rust (#1370, #1371), .NET calibration files (#1384), the Go router lifecycle,
SHA-256 pins and routed inference (#1374, #1379, #1395), a C++ foundation
(#1399, #1407), and parity-lane sharding that replaces the budget headroom
added for 0.4.16 (#1373, #1375).

Verified before tagging: all 92 suites pass, 640 tests, up from 612. ruff
clean on both lists. laya-ts 1251 tests across 44 files, tsc --noEmit clean.
Every generated-artifact gate clean on CPython 3.12 / unicodedata 15.0.0:
Java 20 families match laya (9 unverified), UnicodeTables matches CPython
15.0.0, LanguageTables matches laya/lang.py, three Go tables_gen.go match,
both laya-cpp .inc files match. Version agrees across pyproject.toml,
laya.__version__ and nix/package.nix. README carries 0.4.17 only.

Security audit of the merge diff, 362766 added lines over 480 files: zero
obfuscation, zero secrets, zero boundary hits, zero binaries, no mode or
symlink changes, 20 of 20 actions SHA-pinned including the new cpp.yml, npm
install hooks unchanged, and no third-party host in any added line
(example.com 90, github.com 2, download.pytorch.org 1, docs.rs 1). The 12
dynamic-exec hits are the C++ test harness invoking its own checker through
sys.executable, the Go sample generator reading laya's own example by AST at
development time, and one comment in rust.yml.

Held: #1364 (unchanged, it moves a cross-port contract), #1381 (a #[doc(hidden)]
but pub Rust hook that would ship as public API able to replace the forward
pass), #1386 (route_batch switched from self.route to self._route, silently
bypassing subclass overrides the docstring promises), and nine stacked port
PRs that conflict with each other and need linearizing (#1377, #1378, #1380,
#1382, #1383, #1385, #1387, #1388, #1389, #1390).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kevin-gatimu
kevin-gatimu force-pushed the feat/rust-revision-digests branch from 8475290 to 35e3c56 Compare October 30, 2026 19:39
@kevin-gatimu

Copy link
Copy Markdown
Contributor Author

Rebased onto #1388 (now on 0.4.17) with goldens regenerated; conflicts resolved. Last in the Rust chain. The secret scan flags the SHA-256 digest of the 10-byte fixture tokenizer.json in revision_probe.json; it is not a secret.

LayaOptions::calibration names a calibration JSON that the engine loads
last, after its tokenizer, sessions, checkpoint temperatures and language
table, as ONNXAgent.load_calibration does: the payload is validated with
laya/calibrate.py's texts, its temperatures replace the checkpoint's and
are clamped with Python's warning, and its binning_map recalibrates
answer_confidence (unrounded, then rounded to 4 places) per option-count
bucket, skipped under a language override. The confidence gate and the
predict_long window choice read the binned value. The router passes the
file to every engine it builds. The identity warning for a version-2 file
is not emitted: the SDK has no equivalent of Python's model_id_or_path.

Goldens and the calibration probe come from tools/regen_golden.py with
a fixture Python's own load_calibration reads; the case lists are shared
verbatim with the .NET SDK.
…o 1.0 like Python 0.4.20

`clamp_temperature` and `temperature_rejected` catch the OverflowError of a JSON integer too
wide for a double, so a calibration file's temperature or bucket written as one is the neutral
1.0 and the clamp warning names it digit for digit. A bin value still refuses it, as
`apply_binning_map` does. The routing goldens are regenerated on Python 0.4.20.
Questions gain with_option_order and option_order (a permutation of the
option slots). Options are encoded and marked in slot order, the softmax
runs in slot order and Calibration::unpermute_probs maps the
probabilities back to option order before the answer is built, as
laya/common.py and Agent do. The order is validated with Python's text
where Python validates it, joins the router's batch grouping key, and is
dropped with Python's warning when the shortlist narrows the labels.
Existing constructors are unchanged.

Goldens come from tools/regen_golden.py; the case lists are shared
verbatim with the .NET SDK.
Questions gain with_labels, with_noul_labels and labels: the false and
true option labels Python's noul questions accept. They are validated
and stripped as laya/common.py _resolve_noul_labels does, with Python's
text, at prediction as Agent._check_question does; rendered as
"<label>: <criterion or default text>"; part of the router's batch
grouping key. The answer is unchanged (P(true)). Question::noul is
unchanged.

Goldens come from tools/regen_golden.py; the case lists are shared
verbatim with the .NET SDK.
Python's shortlist copies the question dict and replaces only its criteria (laya/shortlist.py:129-131), so a labels entry on a choice survives narrowing and Agent._check_question still refuses it. The rebuilt choice now carries the labels; the stale option_order is still dropped.
LayaShortlist::predict_tournament narrows each large choice in rounds of
contiguous groups of group_size labels, one predict call per round with
the group winners kept in order, then answers the full request once with
each choice cut to its finalists, as laya/shortlist.py predict_tournament
does: same group slicing, round ids, errors and option_order warning; the
result is the final call's with tournament metadata {labels, n, rounds}.
predict_tournament_with takes a predict closure so per-call options reach every
round, as Python's **predict_kwargs.

CachedEmbed ports cached_embed_fn: an LRU of float32 rows keyed
on the exact text, misses embedded in one de-duplicated call, non-finite
values cached as 0.0, the dimension guard, cache_info and cache_clear.

Goldens, a tournament probe and a cache probe come from
tools/regen_golden.py and Python's own functions; the case lists are
shared verbatim with the .NET SDK.
Port laya/revisions.py: LayaOptions revision and expected_sha256,
LAYA_REVISION and LAYA_SHA256_DIGESTS, the reviewed pins, per-revision
download cache, digest verification before load, and router
revisions/sha256_digests with loaded_revisions. Adds the sha2 crate.
@kevin-gatimu
kevin-gatimu force-pushed the feat/rust-revision-digests branch from 56729dc to f63252b Compare November 1, 2026 16:35

This branch has not been deployed

No deployments
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.

3 participants