Tool Library: Each Owner Converts Its Own
Design problem and decision
- Design problem Release 3 records the condition of every tool. Shelf's saved shape must change while five loans are out and two branches are open.
- Viewer's decision Which modules get a new version, who converts what, what happens if the upgrade fails, and can the app ever go back?
- Outcome The viewer can list the version files a memory change requires, describe conversion as each owner converting its own memory and passing children down, and state the two release rules: a failed upgrade leaves the old release running, and a finished migration cannot be undone by installing the old build.
- Starting point Lesson 6 left every
v1.rslocked and one root seal on the tree. - Handoff Lesson 8 turns this film's attempts into a rehearsal the team runs.
- Pacing Four and a half minutes.
Worked design
Tool Library is illustrative. Release 2 is installed, day 120, nothing charging.
The change. Each tool on a shelf gains condition: good, worn or repair. Existing tools become good.
Version files after the change.
| Owner | memory/ folder |
Why |
|---|---|---|
| Shelf | v1.rs, v2.rs |
Its saved shape changes. |
| Branches | v1.rs, v2.rs |
It names the exact Shelf version it holds. |
| Root | v1.rs, v2.rs |
It names the exact Branches version it holds. |
| Members, Loans, Policy | v1.rs |
Unchanged. They keep version 1. |
Values before and after.
| Value | On release 2 | On release 3 |
|---|---|---|
| Shelf 3, drill | owned 4, available 1 | owned 4, available 1, good |
| Shelf 3, ladder | 1, 0 | 1, 0, good |
| Shelf 3, saw | 2, 1 | 2, 1, good |
| Shelf 5 | empty | empty |
| Member 501 | 3 active | 3 active |
| Loans | five rows | the same five rows |
| Policy | 14 days, limit 3 | 14 days, limit 3 |
Upgrade attempts shown.
| Attempt | Result |
|---|---|
r3-late-fail, a build whose startup fails after converting |
Rolled back. Release 2 runs. All values as before. |
r3 |
Converted. Release 3 runs. |
r2 installed over release 3 |
Refused. Release 3 keeps running. |
The story in one pass
Open the locked Shelf version file and leave it locked. Add v2.rs to Shelf, then to Branches, then to the root, and to nothing else. Name the predecessor. Run the upgrade: the root passes three children across unopened and hands Branches down. Branches hands each shelf down. Each shelf adds the new column. A new seal is published. Then replay with a late failure and watch everything return. Then try the old build and watch it stop at the gate.
Views and visual objects
Use the shared visual language. No new drawing. Conversion is shown with the existing capsules: a vault gains a second tab, and a child capsule travels down an owning edge and back.
| View | Framing and anchor |
|---|---|
files |
AppTree large at left with every memory/ folder expanded. The app small at right. |
convert |
The fixed app layout, service bands absent, vaults large. ReleaseRail and Gate above. The value strip from lesson 6 below, now with a condition cell. |
Scene three_new_files — What has to be written
Already on screen The app on release 2. AppTree with locks on every v1.rs.
Beat the_change — A new fact about every tool
View and focus files. Focus on shelf/memory/.
Narration
Release three records each tool's condition. That is a new saved fact, in Shelf. Shelf's version one file is locked, so we do not touch it. We write version two beside it: the same two counts, plus condition. And version two says how to get there from version one. Every existing tool becomes good.
Cue and animation On “a new saved fact”, the request note tool: + condition appears by the Shelf capsule. On “locked”, the lock on shelf/memory/v1.rs pulses. On “version two beside it”, v2.rs slides into shelf/memory/. On “how to get there”, a short arrow labeled convert draws from v1.rs to v2.rs inside the folder. On “becomes good”, a tiny before and after row shows 4, 1 then 4, 1, good.
Leaves with shelf/memory/ holds v1.rs (locked) and v2.rs.
Beat ripple_up — Every owner above it, and no one beside it
View and focus files. Focus moves up the tree.
Narration
Remember that a parent names the exact version of its children. Branches holds Shelf version one, by name. To hold version two, Branches needs a version two of its own. And the root holds Branches, so the root needs one as well. The change travels up the owning path to the root. It does not travel sideways. Members, Loans and Policy stay on version one.
Cue and animation On “Branches needs a version two”, v2.rs slides into branches/memory/ with its own convert arrow. On “the root needs one as well”, v2.rs slides into root/memory/. On “up the owning path”, on the small app at right the edges root → Branches → Shelf glow. On “does not travel sideways”, the members/, loans/ and policy/ folders dim, each still holding only v1.rs.
Leaves with Three folders with v2.rs. Three without.
Beat declare_predecessor — Name where you come from
View and focus files. Focus on root/mod.rs.
Show The upgrade guide's sample, tabbed root/mod.rs — from the upgrade guide:
#[cdk_rsx::root(
state = App,
init = install,
restore = reopen,
previous = [memory::v1::Memory]
)]
pub mod memory;
Narration
One line completes it. The root names the version it is willing to start from. Now this build carries two seals: the one it wants to end on, and the one it accepts as its predecessor. Without this line, the gate would turn it away, exactly as in the last lesson.
Cue and animation On “names the version”, the line previous = [memory::v1::Memory] highlights. On “two seals”, the build card r3 on the rail shows a large seal and a smaller one behind it. On “turn it away”, a ghost of the card without the small seal meets a red bar and fades.
Leaves with Build r3 on the rail with two seals.
Scene one_upgrade — The conversion, owner by owner
Already on screen convert view. Release 2 in the socket, r3 waiting.
Beat root_hands_down — Kept children cross unopened
View and focus convert. Focus on the root and its four children.
Narration
The upgrade starts. The gate sees the predecessor seal and admits the build. Now the root converts. It has no data of its own to change, only children to place. Policy, Members and Loans are unchanged, so the root moves each one across as it is. Their vaults are never opened. Branches is different. The root cannot convert it. It hands Branches to Branches' own converter.
Cue and animation On “admits the build”, the small seal overlays the canister's seal and a green tick shows. On “the root converts”, the root vault gains a second tab v2 beside v1. On “moves each one across”, the Policy, Members and Loans capsules lift, shift a few pixels from the v1 side of the root to the v2 side, and settle, key badges still. On “hands Branches”, the Branches capsule travels down a short path into a small convert bracket.
Leaves with Three children placed under root v2. Branches in its converter.
Beat each_shelf_converts — A parent passes its children down
View and focus convert. Focus on Branches and its shelves.
Narration
Branches does the same thing one level down. For each key, it takes the shelf, hands it to Shelf's converter, and attaches the result on the same key. Only Shelf opens a shelf. It rewrites each tool with the new field. Four, one becomes four, one, good. Branch five is empty, and converts to empty.
Cue and animation On “For each key”, rib 3 detaches and Shelf 3 enters its own convert bracket. On “Only Shelf opens a shelf”, Shelf's key badge turns and its vault opens. On “rewrites each tool”, a third column condition grows in the table and fills good, good, good in green. On “on the same key”, Shelf 3 returns to rib 3 with a v2 tab. On “Branch five”, Shelf 5 makes the same trip and returns empty with a v2 tab. Branches then returns to the root with its own v2 tab.
Leaves with Root, Branches and both shelves on v2. Members, Loans and Policy on v1. The value strip shows drill 4/1 good · 501: 3 · loans 5 · branches 3, 5.
Beat one_step — Inside a single upgrade
View and focus convert. PauseAndExplain pointing at the socket.
Hold The balloon reads:
All of this is one upgrade
no call ever sees a half-converted app
a converter reads only its own old memory: no clock, no calls,
no other module
it must all fit in one upgrade
your bounds decide that: 32 branches x 500 tools at most
Narration
All of that was one upgrade. No call runs in the middle. Then the services are bound, and only then does the canister remember the new seal. There is no second step and no background job, so the whole conversion has to fit in one upgrade. This is where the limits from lesson one pay off. Thirty-two branches of five hundred tools is a number you can test.
Cue and animation The balloon opens on “one upgrade”. On “services are bound”, the bands redraw. On “remember the new seal”, a new root seal stamps over the old one and r3 sits in the socket. On “Thirty-two branches”, the counters 2 / 32 and 3 / 500 show on the fan and on Shelf 3.
Leaves with The app on release 3.
Scene fail_and_back — Two release rules
Already on screen The app on release 3.
Beat late_failure — A failed upgrade leaves the old release
View and focus convert.
Narration
Run that again, with a build that goes wrong. Back on release two. The conversion completes, the new column is there, and then startup fails. The Internet Computer restores the old program and its memory together. Release two is running again with five loans and its original contract.
Cue and animation On “Run that again”, a rewind mark shows and the picture returns to release 2 with v1 tabs everywhere. On “The conversion completes”, the previous two beats replay at triple speed with the card r3-late-fail. On “startup fails”, a red mark shows on the card just before the bands redraw. On “restores the old program”, every v2 tab, the condition column and the new seal vanish in one cut, and the v1 picture returns. On “Release two is running”, r2 sits in the socket and the value strip shows four equals signs against the earlier values.
Leaves with The app on release 2, unchanged. Then a cut forward to release 3 installed.
Beat no_way_back — A finished migration is not undone by the old build
View and focus convert. Focus on the gate.
Narration
Now release three is in, and a week of conditions has been recorded. Someone wants release two back. The canister holds version two memory and release two expects version one. The gate refuses. Release three keeps running. To bring the old lending rules back, ship a new build that keeps version two memory and the recorded conditions. Plan that recovery path before the migration.
Cue and animation On “a week of conditions”, Shelf 3 shows drill 4/1 worn. On “wants release two back”, the card r2 approaches with its v1 seal. On “The gate refuses”, a red bar crosses the gate. On “keeps running”, the value strip shows equals signs. On “ship a new build”, a faint card r4 appears further along the rail with the installed v2 seal and the old lending rule.
Leaves with The app on release 3 with drill 4/1 worn. Lesson 8 opens on the three build cards used here.
Brief to hand over
Illustrative.
Release 3. Add
conditionto each tool in Shelf. Writeshelf/memory/v2.rswith its converter: keepownedandavailable, setconditiontogood. Writebranches/memory/v2.rsandroot/memory/v2.rs, whose converters only pass children to their own converters and re-attach them on the same key or slot. Leave everyv1.rsuntouched. Leave Members, Loans and Policy on version 1. Name root version 1 as the predecessor. Addset_condition(branch, tool, condition)to Shelf's public functions.Recovery plan. After release 3, a build that restores the old lending rules must support the installed V2 memory. Keep the new values in that build. If recovery also needs a schema change, define a successor that converts from V2.
Acceptance test, expected and not run
| Step | Expect |
|---|---|
| On release 2, populate and record the values in the table above | recorded |
| Upgrade to a release 3 build that does not name a predecessor | rejected with a contract mismatch. Release 2 answers. Values identical. |
Upgrade to r3-late-fail |
rejected after conversion. Release 2 answers. Values identical. |
Upgrade to r3 |
accepted |
| Read every value | as in the "release 3" column. Member, loan and policy values identical. |
join(503), lend(503, 3, 30), give_back(7), set_condition(3, 17, worn) |
all work. Drill reads worn. |
Install r2 |
rejected. Release 3 answers. Drill still worn. |
Upgrade to r3 again |
accepted. Values identical. |
Repeat the r3 upgrade from a canister filled to 32 branches of 500 tools |
accepted within the upgrade limit |
Production and source notes
- Tool Library, release 3 and the three attempts are illustrative. The
previoussnippet is the upgrade guide's sample, quoted in full. Upgrades, lines 131 to 138. - Version files, frozen predecessors, the converter in the target file, and unchanged children keeping their number: Conventions, lines 42 to 55.
- The ripple to every owner above follows from each parent naming exact child versions. The composition probe's root V2 names
payloads::memory::v2andrecords::memory::v2, takes each old child, calls that child's ownupgrade, and attaches the result. Composition probe root V2, lines 1 to 37. - A parent looping over keyed children, converting each and attaching it under the same key, is the nested Nyxus probe's root converter. Nested probe root, lines 113 to 124.
- A kept child moves across with the same identity and contents. The root authoring probe's native test asserts this for its Scores child. Root authoring probe wiring, lines 163 to 203. The converter that does it: Root authoring probe versions, lines 10 to 26.
- Converters read only their own source data and delegate children. No ancestor, sibling, service, call or clock. Upgrades, lines 180 to 185.
- One synchronous upgrade, no background migration, and the whole of it must fit the installation budget. Upgrades, lines 9 to 44. Keep budget arithmetic out of the film. The last acceptance row is how the architect asks for it.
- The new contract is published only after restore succeeds with the app installed. Upgrades, lines 141 to 146.
- Late failure and rollback, then success, then refused downgrade, then a same-contract upgrade with a fresh write: this is the order of the root authoring lifecycle test. Read, not run. Root authoring lifecycle test, lines 75 to 96. The nested lifecycle test asserts the same rollback for a trap inside a nested conversion. Nested lifecycle test, lines 118 to 129.
- The restore code chooses between converting and a plain open by asking which root contract is saved. Keep this off screen. Root authoring probe wiring, lines 57 to 70.
- In this design every tool row is rewritten, because the row gains a field. Where a collection's entries do not change, the collection moves across without its rows being rebuilt. Do not animate row copying for Members, Loans or Policy. Upgrades, lines 187 to 200.
- "Release four" in the last beat is a design consequence of the predecessor rule. No fixture in the checkout performs a reversing forward migration.
- The internal series film 8 animates a migration at storage level. Do not reuse its page or pointer drawings here.