Part IV — Expert Production Engineering · Chapter 20 · Lesson 1 of 7 · 5 min read
Lesson 1: Integrity-Checked Model Bundles and Registries
Lesson level: Expert
Purpose: Package a trained pipeline as a self-describing, tamper-evident bundle and record it in a registry so that every model in use can be identified, verified, and traced to its origins.
Learning objectives
By the end of this lesson you will be able to:
- describe the contents of a model bundle and why each part is needed
- compute and verify content hashes for every file in a bundle
- write a bundle manifest that ties artifacts, metadata, and evidence together
- explain what a model registry stores and why entries are immutable
- register, look up, and verify a model version
- trace a prediction back to its bundle, training data, and code
1.1 From a file to a bundle
A single serialized pipeline file answers only "what are the weights?". A bundle is a directory or archive that answers the governance questions as well:
| Bundle part | Contents | Purpose |
|---|---|---|
| Pipeline artifact | Serialized fitted pipeline (Chapter 19, Lesson 6) | Makes predictions |
| Input schema | Field names, types, ranges, unknown-value policy | Validates requests |
| Metadata | Name, version, creation time, seeds, hyperparameters, decision policy | Identifies and configures |
| Lineage | Data snapshot hash, extraction query, code commit, environment lock | Enables rebuild and audit |
| Evaluation evidence | Metrics, intervals, segment results, calibration summary | Justifies approval |
| Model card | Intended use, limits, owners (Lesson 5) | Communicates responsibly |
| Manifest | List of every file with its hash and size | Detects tampering and loss |
1.2 Content hashes
A cryptographic hash such as SHA-256 maps a file to a short fingerprint. Changing a single byte changes the fingerprint completely, so comparing a stored hash with a freshly computed one detects accidental corruption and deliberate modification.
A hash detects change but does not prove who created the content: an attacker who can replace a file can also replace its hash. Hashes therefore provide integrity; Lesson 6 adds signatures for authenticity. Store hashes in the manifest, and protect the manifest itself with a signature.
1.3 The manifest
A bundle manifest identifies the stored model and its integrity metadata. The shipped bundle loader and the separate Ed25519 signature verifier perform different checks; invoking one does not imply the other ran. For production, verify the trusted signature and referenced hashes before loading, and add an explicit file-inventory check if your policy rejects unlisted files. Do not assume that the illustrative manifest layout or automatic rejection of every extra file is a shipped guarantee.
Illustrative listing.
{
"bundle_format": 1,
"model": {"name": "churn", "version": "1.0.0"},
"created_at": "2026-11-01T10:15:00Z",
"files": [
{"path": "pipeline.bin", "size": 48211, "sha256": "9f2c…"},
{"path": "schema.json", "size": 1840, "sha256": "41ab…"},
{"path": "metadata.json", "size": 2205, "sha256": "c07e…"},
{"path": "evaluation.json","size": 5120, "sha256": "7d19…"},
{"path": "model_card.md", "size": 6730, "sha256": "e5a0…"}
],
"lineage": {"data_sha256": "b81d…", "code_commit": "4e2f9a1",
"pealang_version": "0.63.0rc2"}
}
Hash values in this listing are truncated placeholders. Real manifests store the full digest.
1.4 What a registry is for
A model registry is the system of record for models. It answers "which models exist, which version is where, and why?" At minimum each entry records the model name and version, the bundle location and manifest hash, the lineage summary, the evaluation summary, the owner, the current lifecycle state (Lesson 2), and an append-only history of every state change with who made it and when.
Two rules make a registry trustworthy. First, versions are immutable: once version 1.0.0 is registered, its bundle and hash never change. A fix is version 1.0.1. Second, the registry stores references and evidence, not opinions: approval is a recorded event linked to evidence, not a flag someone toggles without trace.
Illustrative listing.
from pealang.ml.registry import Registry
reg = Registry("registry/") # local file-backed registry
entry = reg.register(
bundle="bundles/churn-1.0.0",
owner="retention-analytics",
description="Weekly churn propensity, calibrated, cost threshold 0.09")
print(entry.name, entry.version, entry.state, entry.manifest_sha256)
verified = reg.verify("churn", "1.0.0") # recomputes every hash
assert verified.ok, verified.problems
1.5 Tracing a prediction to its origins
Every prediction the service returns should carry, or be logged with, the model name, version, and manifest hash (Lesson 3). From that triple, an investigator can follow a chain: registry entry → bundle → metadata and lineage → data snapshot hash and code commit → evaluation evidence and approval history. If any link is missing, the chain breaks and the prediction cannot be explained. Test the chain end-to-end before the first release, not during the first incident.
1.6 Storage and retention
- Store bundles in versioned, access-controlled storage; restrict write access to the release pipeline.
- Keep every bundle that ever served traffic for at least the audit-retention period your organization requires, even after retirement.
- Back up the registry itself; it is as important as the bundles it describes.
- Never edit a bundle in place. Re-bundle, re-hash, and register a new version.
Common mistakes
- Shipping a bare model file: without schema, lineage, and evidence it cannot be validated or audited.
- Trusting a hash stored next to the file it protects: sign the manifest (Lesson 6).
- Mutable versions: overwriting "1.0.0" destroys traceability.
- Registry as a spreadsheet: manual records drift from reality; register through the pipeline.
- Loading before verifying: verify every hash before deserializing anything.
- Deleting retired bundles: past predictions become unexplainable.
Guided practice
- Bundle the Chapter 19 churn pipeline and write its manifest.
- Change one byte in the schema file and confirm verification fails with a clear message.
- Register two versions and list the registry history.
Hands-on lab: A verifiable bundle and registry
- Create a bundle for the Chapter 19 pipeline with all seven parts from Section 1.1.
- Write a verification function that rejects missing, extra, or modified files.
- Register the bundle in a file-backed registry with owner and description.
- Simulate a prediction log entry and trace it back to the data hash and code commit using only registry and bundle contents.
- Document the trace as a one-page audit walkthrough.
Review questions
- What does a bundle contain that a bare model file does not?
- What does a content hash prove, and what does it not prove?
- Why must the manifest list every file, including evaluation evidence?
- Why are registry versions immutable?
- What three identifiers let you trace a prediction to its origins?
Applied challenge
An auditor asks which model produced a credit decision eight months ago and what data it was trained on. Design the bundle, registry, and logging conventions that would let you answer within one hour, and list the retention periods each artifact needs.
Lesson summary
A bundle packages the pipeline with its schema, metadata, lineage, evidence, and model card, and a manifest of hashes makes tampering and loss detectable. A registry is the immutable, evidence-based system of record for every version. Together they let any prediction be traced back to its data, code, and approval.
Lesson status: Ready for review.