Tool Library: The Contract an Upgrade Starts From
Design problem and decision
- Design problem A new build is about to run on memory written by an older build. It must not misread a single field.
- Viewer's decision What makes a build compatible with the data in place, what does that check leave unproven, and when is the app ready to be upgraded at all?
- Outcome The viewer can say what the memory contract covers, why a shipped version file is frozen, what admission proves and does not prove, and that readiness is a rule the app writes and the old release enforces.
- Starting point Lesson 5 left the app on release 2 with a
v1tab on every vault. - Handoff Lesson 7 changes the contract on purpose.
- Pacing Four minutes.
Worked design
Tool Library is illustrative. The app runs release 2 on day 120 with the state from lesson 4. Three builds arrive in turn.
| Incoming build | What differs from release 2 | Result |
|---|---|---|
r2-fix |
Desk code only: a clearer refusal reason | Admitted. Every value unchanged. |
r2-tidy |
Someone renamed a field in the shipped shelf/memory/v1.rs |
Refused. Release 2 keeps running. Every value unchanged. |
r2-fix again, while loan 3 is charging |
Nothing new | Refused by release 2's own readiness check. Admitted once the charge has an answer. |
Values watched before and after each attempt: drill 4/1, member 501 active 3, five loans, branch keys 3 and 5.
The story in one pass
Put a seal on every vault and fold the seals up the tree into one. The canister remembers that one. Send a code-only build to the gate: it passes. Send a build with one edited version file: it is turned away and nothing changes. Say what the gate proves and what it does not. Then show a charge in flight, and the old release itself refusing to be upgraded.
Views and visual objects
Use the shared visual language. This film introduces ContractSeal and Gate.
| View | Framing and anchor |
|---|---|
seals |
The fixed app layout with service bands dimmed, so vaults and owning edges lead. AppTree small at left. |
gate |
The app below, the ReleaseRail above, the Gate between rail and socket. Each build card carries its own seal. A value strip at the bottom shows the four watched values. |
Scene the_contract — One seal for the whole tree
Already on screen The app on release 2. Every vault shows its v1 tab.
Beat one_seal_each — What a version file fixes
View and focus seals. Focus on Shelf 3, then the AppTree.
Show The real selector, tabbed root/memory/mod.rs — Shop, lines 1 to 2:
pub mod v1;
pub use v1 as current;
Narration
Every module's memory was declared in a version file. That file fixes what is saved and how it is read. Think of it as a seal on the vault. The file that selects the current version is two lines. Once a version has shipped, its file is locked. It is never edited again.
Cue and animation On “a version file”, shelf/memory/v1.rs highlights in the tree. On “a seal on the vault”, a small round ContractSeal stamps onto the Shelf 3 vault beside its v1 tab. On “two lines”, the selector shows. On “locked”, a small lock appears on every v1.rs in the tree.
Leaves with One seal on Shelf 3. Locks on all v1.rs files.
Beat folded_up — Parents include their children
View and focus seals. Focus travels up the owning edges.
Narration
A parent's seal includes the child versions its declaration allows. Shelf folds into Branches once. Both branches use that same Shelf version. Branches, Members, Loans and Policy fold into the root. The S D K and compiler the app was built with also join the root seal.
Cue and animation On “Shelf folds into Branches”, the Shelf v1 declaration sends one seal into the Branches declaration. On “Both branches use that same Shelf version”, point from that one declaration to the two saved Shelf instances. On “fold into the root”, seals from the four child declarations converge into one seal on the root. On “S D K and compiler”, a small toolchain mark joins it.
Leaves with One root seal, visibly made of the others.
Beat remembered — The canister keeps it
View and focus seals. Focus on the root seal.
Hold PauseAndExplain pointing at the root seal. The balloon reads:
In the seal Checked by the app and its tests
each version file, as written Desk's rules, endpoint code
which child versions are held the values themselves
how each collection is ordered work in progress
declared interpretation rules
the SDK and compiler
Narration
The canister remembers this seal as its saved-memory contract. It covers the shape of those types and the rules they declare for reading that data. Our tests still have to check the lending rules and the actual values.
Cue and animation All motion holds. The left column appears on “the shape of those types”, the right on “Our tests”.
Leaves with Root seal in place.
Scene at_the_gate — Admitted or turned away
Already on screen seals view with the root seal.
Beat code_only_passes — Same contract
View and focus gate.
Narration
A new build arrives. It changes one refusal message in Desk. The build carries the seal it was compiled to expect. The gate compares it with the seal the canister holds. They match. The build is admitted, the services are bound again, and every value is where it was.
Cue and animation On “A new build arrives”, the card r2-fix slides along the rail with its own seal. On “compares”, the two seals move to the gate and overlay. On “They match”, a green tick shows and the gate opens. On “bound again”, the bands redraw as in lesson 4. On “every value”, the value strip shows drill 4/1 · 501: 3 · loans 5 · branches 3, 5 with four small equals signs.
Leaves with r2-fix in the socket. Values unchanged.
Beat edited_file_refused — One renamed field
View and focus gate. Focus on the AppTree, then the gate.
Narration
Another build. Someone tidied up and renamed a field in Shelf's version one file. It looks harmless. But that file is part of the contract, so this build expects a different seal. The gate turns it away, before any saved data is opened. The old release keeps running. Nothing was touched.
Cue and animation On “renamed a field”, the lock on shelf/memory/v1.rs in the tree shakes and one line in a tiny file preview changes. On “expects a different seal”, the card r2-tidy shows a seal with a different pattern. On “turns it away”, a red bar crosses the gate and the card slides back. On “before any saved data is opened”, every vault stays closed with its key badge still. On “Nothing was touched”, the value strip shows four equals signs again.
Leaves with r2-fix still in the socket. r2-tidy set aside with a red mark.
Beat what_the_gate_proves — A starting point, nothing more
View and focus gate. PauseAndExplain pointing at the gate.
Hold The balloon reads:
Admission proves
this build was compiled to read exactly the memory that is here
Admission does not prove
the new rules are right
the saved values make sense
a conversion, if there is one, is correct
the app was ready
Narration
The gate matches the build's declared starting contract to the saved one. We still test what the build does with that data. A different S D K or compiler can change the seal even when the app files stay the same.
Cue and animation All motion holds. Balloon sections appear in step. On “different S D K or compiler”, the toolchain mark on the root seal pulses.
Leaves with Balloon closed.
Scene ready_or_not — The app decides when
Already on screen gate view, r2-fix installed.
Beat charge_in_flight — The old release says no
View and focus gate. Focus on Loans, then the socket.
Narration
A late fee for loan three is being charged. The payment canister still owes us an answer. Tool Library's readiness rule forbids an upgrade while any loan is charging. Try it now. The installed release refuses the upgrade before it reaches the gate.
Cue and animation On “being charged”, the Loans row (103, 3) shows the mark charging and a dashed arrow with a clock hangs outside the canister. On “readiness rule”, a small shield labeled ready? appears on the socket, under the installed card. On “Try it now”, a build card approaches. On “refuses the upgrade”, the shield shows 1 charging and the incoming card stops short of the gate. The value strip shows four equals signs.
Leaves with The incoming card held before the gate. Loan 3 charging.
Beat pause_fee_intake — Stop adding work while waiting
View and focus gate. Focus on the fee entry and the outstanding reply.
Narration
The operator pauses new fee requests. The payment that already left can finish. If the reply leaves the outcome unclear, keep that loan on the pending list until you can establish what happened. That is the release condition the app needs.
Cue and animation On “pauses new fee requests”, a fresh fee pill stops at the public method and returns Maintenance. On “already left”, the dashed reply path stays open. On “outcome unclear”, hold on the one charging row and its ready? shield.
Leaves with Fee entry paused and loan 3 still charging.
Beat drain_then_upgrade — Wait, then go
View and focus gate.
Narration
The answer arrives. Loan three is charged. The readiness rule is satisfied, and the same build goes through. Two design points. Readiness is your rule, about your work. And it runs in the release already installed, so it must ship before the upgrade that needs it.
Cue and animation On “The answer arrives”, the dashed arrow returns and the mark changes to charged. On “satisfied”, the shield shows 0 charging and a tick. On “goes through”, the card passes the gate with a green tick. On “the release already installed”, the shield pulses on the old card as it leaves the socket.
Leaves with The app running, all values unchanged, loan 3 charged. Every v1.rs locked. Lesson 7 opens on the locked shelf/memory/v1.rs.
Brief to hand over
Illustrative.
Frozen files. After release 1 ships, no file named
v1.rsunder anymemory/folder is edited, for any reason, including comments.Readiness. Ship the root readiness check in release 1. Operators pause new late-fee charges and allow replies to settle. Keep unclear outcomes pending until there is evidence of the result. Attempt the upgrade when the count reaches zero and resume fee entry once the release checks pass.
Same toolchain. Builds
r1,r2andr2-fixuse the same SDK revision and compiler, and the canonical builder.
Acceptance test, expected and not run
| Step | Expect |
|---|---|
| Install release 2 and populate. Record the four watched values. | recorded |
Upgrade to r2-fix |
accepted. Values identical. join(503) then lend(503, 3, 30) succeeds. |
Upgrade to r2-tidy |
rejected with a contract mismatch. r2-fix still answers. Values identical. |
Start charge_late_fee(3) and hold the Payments reply. Upgrade to r2-fix. |
the running release refuses before admission. Values identical. Loan 3 charging. |
| Pause fee entry and request another charge while the first is unresolved. | Maintenance for the new request. Existing loan stays charging. |
| Release the reply. Upgrade again. | accepted. Loan 3 charged. |
| In a separate run, finish the call with an unclear outcome and attempt the upgrade. | the app check refuses while the saved loan is still charging. |
Compare memory/ folders of r2 and r2-fix |
no difference |
Production and source notes
- Tool Library, the three builds and the readiness rule are illustrative. The selector is real. Shop root selector, lines 1 to 2.
- "Seal" is this course's word for the compiled root catalog. Do not use "catalog", "digest" or "hash" in narration. What it covers: Upgrades, lines 57 to 63. It follows declared types from the root and does not scan instances: Store architecture, lines 281 to 285. Full account: mental-model review, claim 7.
- The version file is captured as text, so any edit changes the contract. Upgrades, lines 65 to 76 and 118 to 123. Shipped versions are frozen: Conventions, lines 42 to 47.
- Admission happens before saved pointers are opened, and only the current contract or a declared predecessor passes: Upgrades, lines 141 to 146.
- A refused build leaves old values live: the root authoring lifecycle test asserts the old values after a changed policy and after an undeclared source. Read, not run. Root authoring lifecycle test, lines 67 to 74. A changed layout is refused the same way in the nested lifecycle test. Nested lifecycle test, lines 115 to 117.
- A code-only build is admitted over populated memory: Nested lifecycle test, lines 103 to 106.
- The toolchain is part of the contract, the list of approved equivalent builds is currently empty, and there is no conversion for the Store kernel or allocators. Compatibility, line 9. Upgrades, lines 155 to 172. On screen this is only the
toolchainmark. - Readiness is an app-written
checkcallback on the root. "The SDK does not infer application quiescence." It runs in the installed old program. Upgrades, lines 222 to 244. Heavy16's check reads its own modules and refuses while counts are non-zero. Heavy16 root, line 330. The async scope probe declarescheck = drained. Async probe root, lines 2 and 62 to 65. - The SDK checks for live callbacks and tasks before running the app's
check. Thechargingrule also covers an unresolved outcome after the call ends. In the held-reply example the shield represents readiness of the installed build. Use the separate unclear-outcome exercise to isolate the app check. Root check order - Draw the seal as a pattern. Never print hex.
- The readiness shield belongs to the installed card. Draw it under that card and let it leave with the card.