PeaBox Lab › PeaLang › Learn › Chapter 11 › Lesson 2

Part II — Intermediate Development · Chapter 11 · Lesson 2 of 6 · 9 min read

Lesson 2: Deterministic Locks and Reproducible Builds

Lesson level: Intermediate

Purpose: Turn version constraints into one recorded set of concrete versions, so that every developer, build server, and release produces the same result from the same inputs.

Release note: lock-file names, field names, and commands in this lesson are illustrative. Verify them against the installed v0.63 release before relying on them.

Learning objectives

By the end of this lesson, you should be able to:

2.1 The problem a lock solves

Lesson 1 let the order_rules package accept input_checks ^1.2.0. That constraint admits many versions. If a developer resolves it today and a build server resolves it next month, they may receive different versions. The code is identical, the manifest is identical, and the behavior still differs.

A lock removes that freedom. It records the exact version chosen for every dependency, including dependencies of dependencies, so later resolutions reuse the recorded choice instead of choosing again.

2.2 Constraint versus lock

AspectManifest constraintLock entry
Written byA personThe tool
DescribesA set of acceptable versionsOne chosen version
Changes whenThe author decides to widen or narrow the rangeA resolution or update is run
Reviewed asA statement of intentA record of fact
Exampleinput_checks "^1.2.0"input_checks 1.2.4

The manifest says what you are willing to accept. The lock says what you actually used. Both are needed, and neither replaces the other.

2.3 What a lock records

A useful lock records, for every package in the resolved graph:

# pea.lock (illustrative; generated by the tool)
[[package]]
name = "input_checks"
version = "1.2.4"
source = "registry"
checksum = "sha256:<recorded-by-tool>"
dependencies = []

The layout above is a teaching sketch. Do not copy it into a real project. Let the installed tool generate the real file.

2.4 Why a lock is generated, not written

2.5 Determinism and reproducibility

Determinism means the same inputs always produce the same output. Reproducibility means someone else, on another machine at another time, can rebuild and obtain the same result. Determinism is a property of a process. Reproducibility is a property of the whole setup, including its inputs and environment.

ConceptQuestion it answersTypical failure
DeterminismDoes the same input give the same output here?Hidden randomness or clock reads
ReproducibilityCan another party obtain the same output?An unrecorded input, such as a floating version

2.6 Inputs a reproducible build must fix

If any input is allowed to float, the build is reproducible only by luck.

2.7 The lock lifecycle

2.8 Illustrative commands

pea lock
pea install --locked
pea update input_checks
pea lock resolves the manifest and writes or refreshes the lock.
pea install --locked installs from the lock and fails if the lock is missing or does not match the manifest.
pea update input_checks re-resolves one dependency and leaves the others alone.

These command names and options are illustrative. Verify the real names with the help output of your installed release.

2.9 Frozen mode for automation

A build server should never silently change its inputs. Use the strictest installation mode available: it should refuse to run when the lock is absent, stale, or inconsistent with the manifest. A failure here is a gift. It tells you that someone changed the manifest without regenerating the lock.

2.10 Updating deliberately

GoalApproachRisk
Take a security fix for one packageUpdate only that package, then run the full suiteLow
Refresh everythingUpdate all packages in a separate changeHigher; review the full diff
Move to a new major versionEdit the constraint, resolve, fix callers, testHighest; plan the work

Keep dependency updates in their own changes. A single change that mixes feature work with a lock refresh makes failures hard to attribute.

2.11 Reading a lock diff

A lock diff is long but regular. Review it with these questions:

2.12 Libraries and applications

An application is a finished product, so it should commit its lock and install strictly from it. A library is consumed by other packages, whose own locks decide the final versions. A library may still keep a lock for its own tests and continuous integration, but consumers will not use it. Make this choice explicit in the project documentation.

2.13 Worked example: a surprise upgrade

The order_rules suite passes on a developer laptop. On the build server it fails in the boundary layer. The manifest and source are identical. The lock file is absent from version control, so the build server resolved input_checks ^1.2.0 afresh and received 1.3.0, which changed how a negative quantity is reported.

StepFinding
Compare manifestsIdentical
Compare installed versionsLaptop 1.2.4; build server 1.3.0
Root causeNo lock committed; the range admitted a newer release
FixCommit the lock; install in locked mode; open a separate change to evaluate 1.3.0
PreventionFail the build when the lock is missing

2.14 Reproducibility beyond dependencies

2.15 Verifying reproducibility

Record the hash and the inputs used. That record becomes release evidence in later chapters.

2.16 Common mistakes

MistakeWhy it hurtsBetter practice
Not committing the lockEach machine resolves independentlyCommit it with the manifest
Editing the lock by handCreates states the resolver would not chooseRegenerate with the tool
Ignoring a lock mismatch failureHides an unrecorded changeFix the cause and regenerate
Updating everything at onceA failure cannot be attributedUpdate one package or one group per change
Treating a lock as a security control by itselfA lock records choices but does not prove trustAdd checksums and signature checks
Embedding timestamps in artifactsEvery build differsUse a fixed value from the source revision
Leaving the toolchain version unrecordedBehavior may change with the toolRecord the exact PeaLang version

2.17 Guided practice

2.18 Hands-on lab: Make order_rules reproducible

Goal: Prove that the order_rules package builds the same way twice and on a second environment.

Deliverable: The manifest, the lock, the command transcript, the two artifact hashes from the same machine, the hash from the second environment, the defect note, and the lock-diff review. Use only synthetic package names, and do not include registry credentials.

2.19 Review questions

2.20 Applied challenge

Write a one-page reproducibility policy for a team that maintains several PeaLang packages. State which files are committed, which installation mode automation uses, how updates are proposed and reviewed, how artifact hashes are recorded, and who may approve an exception. Include a short checklist that a reviewer can apply to any pull request that touches the manifest or the lock.

Lesson summary

A lock converts the flexible constraints in a manifest into one recorded set of exact versions, sources, and integrity values. Deterministic resolution and strict installation keep later builds from silently drifting, while a reproducible build also fixes the source revision, toolchain, build options, and any embedded data. Deliberate, separate updates and careful review of lock diffs keep change visible, and recorded artifact hashes provide evidence that a build can be repeated.

Transition to Lesson 3

A lock records where each package came from, but so far every example used one registry. The next lesson covers local, Git, and registry sources, showing how each source type is declared, what it can and cannot guarantee, and when each one is appropriate.

Lesson status: Ready for review.

← Previous Next →