MPK contract
MPK is the inference contract embedded in a compiled model archive. It is a JSON
file named mpk.json or *_mpk.json that the route planner and downstream extractors
read. Model archives themselves are ordinary .tar.gz files loaded through Model.
This page separates the two concerns:
- The archive — a
.tar.gzdistribution unit containing binaries, configs, weights, and the MPK contract JSON. - The contract — the
*_mpk.jsonJSON document that is the source of truth for inference routing.
For byte-level contract and security rules, see MPK Contract (contributor reference).
Why a single .tar.gz archive
Models on Modalix have many moving parts (compiled MLA graph, CVU kernels, configs,
weights). Bundling them into one signed .tar.gz archive means:
- Atomicity — either the whole model loads or none of it does.
- Versioning — the MPK contract declares its schema version; incompatible contracts are rejected early.
- Provenance — one artifact to checksum, sign, and ship.
- Reproducibility — given the same archive and MPK contract, the framework's planner makes the same routing decisions.
The MPK contract is the only authoritative JSON
A model archive may contain other JSON files; the framework treats only mpk.json or
*_mpk.json as the inference contract. Don't infer model topology from other JSON in
the archive — the contract is "if it's not in the MPK contract, it doesn't exist."
This rule keeps the framework's planner deterministic.
Loading model archives
Applications do not call an archive-loader API directly. Construct Model with the
.tar.gz path; Model performs archive validation, extracts the safe contents into an
internal layout, parses the MPK contract, and runs route planning.
Only exact lowercase .tar.gz model archives are accepted. .mpk, .tgz, .tar, and
bare .gz files are rejected before archive inspection.
Security defenses
Because model archives come from outside the system, loading is fail-closed. Every accepted archive passes a strict matrix:
- Extension allowlist — only
.tar.gzis accepted. - Size caps — archive, entry, and total JSON byte limits.
- Entry-count caps — protects against zip-bomb-style packs.
- JSON depth cap — protects against parser-stack exhaustion.
- Path traversal protection — normalized paths reject absolutes and
..segments. - UTF-8 validation — entry paths must be valid UTF-8.
- Unicode confusable rejection — visually-confusable path characters are rejected.
- File-type allowlist — only known file types extract.
- JSON duplicate-key rejection — duplicate keys at any depth are rejected.
- Schema validation — contract and loader-side metadata must match supported schemas.
- Required-section validation — the inference contract and model binary must be present.
- Kernel allowlist — referenced kernels must be in the framework's known set.
Higher layers report failures as NeatError with structured io.* or mpk.* error
codes.
Related types
Model— the public entry point that loads.tar.gzmodel archives and exposes route fragments.MpkContractand related internal structs — the parsed inference contract frommpk.json/*_mpk.json.
Further reading
- MPK Contract (contributor reference) — byte-level rules and field semantics.
- "MPK contract" — §0.16, §15 of the design deep dive.
- "Model archive security matrix" — §91 of the design deep dive.