Skip to content

feat(ts): per-checkpoint SHA-256 artifact verification in Router - #723

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
Swatantra-66:feat/ts-router-sha256-digests
Sep 29, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
Swatantra-66:feat/ts-router-sha256-digests

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Why

In laya-ts, artifact digest verification (expectedSha256) was previously only supported at the individual bundle/provider level (loadNodeBundle, loadWebBundle, createNodeProvider). When using Router to manage multiple resident checkpoints:

  1. RouterOptions had no sha256Digests / sha256_digests option to verify weights and models per checkpoint.
  2. A single flat LAYA_SHA256_DIGESTS environment variable ({ "model.safetensors": "..." }) could only ever match a single checkpoint, because each model ships distinct weights and ONNX files. Loading a second resident model would fail with a digest mismatch or file not found error.
  3. Services configuring resident routers via environment had no way to supply per-model digests ({ [model]: { [artifact]: digest } }), preventing multi-model servers from pinning artifacts safely.

This brings laya-ts into complete parity with Python PR #572.


What

  1. RouterOptions & Router Properties:

    • Added sha256Digests?: Record<string, Record<string, string> | null> | null and snake_case alias sha256_digests.
    • Seeded this.sha256Digests from process.env["LAYA_SHA256_DIGESTS"] via digestsFromEnv(this.models).
    • Normalized model keys via normaliseName(), allowing aliases (en, ml, typed) and failing immediately on typos or unknown models at construction time.
  2. Environment Variable Parsing (digestsFromEnv / _digestsFromEnv):

    • Flat { artifact: digest } maps return {} so the underlying provider/bundle loader handles single-checkpoint verification as before.
    • Nested { model: { artifact: digest } } maps are parsed per checkpoint, normalizing model keys and defaulting unlisted resident models to {} (deliberately unpinned, preventing accidental fallback to environment model-keyed maps).
    • Validates that values are uniform (rejecting mixed artifact/model maps).
  3. Model Loader Integration (Router.load):

    • Forwards expectedSha256 to the model loader when a model is listed in this.sha256Digests.
    • Explicit null or {} entries pass {} to mask environment defaults for that specific model.
  4. Exports:

    • Exported digestsFromEnv and parity alias _digestsFromEnv, along with RouterOptions and RouteOptions types in laya-ts/src/index.ts.
  5. Unit Tests:

    • Added 13 new unit tests to laya-ts/tests/revision-pinning.test.ts verifying key normalization, snake_case alias acceptance, typo refusal, per-checkpoint expectedSha256 forwarding upon load, and flat/nested/mixed/unparseable environment shapes.

Checklist

  • All 470 tests passing in laya-ts (npm test -- --run)
  • TypeScript clean compilation with zero diagnostics (npm run build)
  • Python CI checks (ruff check laya/, python -m compileall -q laya/ tests/) pass cleanly
  • Conventional commit format matching repository history (feat(ts): ...)

@NandhaKishorM
NandhaKishorM merged commit e3e0dee into NandhaKishorM:main Sep 29, 2026
20 of 21 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Passed checks and merged. Thank you @Swatantra-66! It ships in 0.3.22.

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