Tool Library: Install Once, Bind Every Time

Design problem and decision

  • Design problem The app must come into existence once, then keep its data through every later release.
  • Viewer's decision What is created at install, what is rebuilt at every start, and what does a release that changes only rules have to do?
  • Outcome The viewer can separate the install path from the restore path, say which parts of a module survive an upgrade, and recognise a code-only release.
  • Starting point Lesson 3 left the full app on screen with shelves on keys 3 and 5.
  • Handoff Lesson 5 chooses what kind of storage sits in each vault.
  • Pacing Three and a half minutes.

Worked design

Tool Library is illustrative. This film first rewinds to an empty canister, then returns to the populated app.

Install, release 1. The root attaches four modules. Policy starts with loan days 14 and loan limit 3. Members, Branches and Loans start empty. No shelf exists yet.

Populated state before release 2, on day 120.

Module Saved state
Members 501: 3 active, 502: 2 active
Branches keys 3 and 5
Shelf 3 drill 4/1, ladder 1/0, saw 2/1
Loans (103, 3) and (108, 4): member 502. (105, 5), (110, 6), (114, 7): member 501.

Release 2 changes one rule in Desk: refuse to lend to a member who has an overdue loan. No version file changes.

Call on day 120 Release 1 Release 2
lend(502, 3, 30) Lent { loan 8, due 134 } Refused(OverdueLoan)

The story in one pass

Start from an empty canister. Build the owning tree from the root in one step. Draw the services over it. Jump forward to the populated app. Install release 2: the services dissolve, the memory stays, the new code arrives, and the services are drawn again. Check that the values and the branch shelves are as they were, and that the new rule answers.

Views and visual objects

Use the shared visual language. This film introduces ReleaseRail.

View Framing and anchor
tree The fixed app layout.
tree_and_files tree at right, AppTree at left with root/ expanded.
release tree with the ReleaseRail above it, showing build cards r1 and r2 and a socket for the installed build.

Scene install — The tree is built once

Already on screen The populated app from lesson 3.

Beat rewind — Before anything exists

View and focus tree.

Narration

Go back to the first moment. The canister is created, and its memory is empty. How does this tree come to exist?

Cue and animation On “Go back”, every capsule fades in reverse order until only the canister boundary remains.

Leaves with An empty canister boundary.

Beat one_root_install — From the root down, in one step

View and focus tree_and_files. Focus on the root, then each slot.

Show One snippet, tabbed root/memory/v1.rs — illustrative, modelled on Shop's root version file:

pub struct Children {
    pub(in crate::root) policy:   ChildSlot<crate::policy::memory::v1::Memory>,
    pub(in crate::root) members:  ChildSlot<crate::members::memory::v1::Memory>,
    pub(in crate::root) branches: ChildSlot<crate::branches::memory::v1::Memory>,
    pub(in crate::root) loans:    ChildSlot<crate::loans::memory::v1::Memory>,
}

Narration

The root does it, in its install function. First the root's own memory. It has four slots, and this file names them. Then the root asks each module for a new, empty memory and attaches it in its slot. Policy arrives with its starting rules. The root never sees inside any of them. It is all one step. A memory that was made and not attached would be discarded when the step ends.

Cue and animation On “install function”, root/mod.rs highlights in the tree and a write frame opens. On “four slots”, the root vault draws with four empty sockets and the four snippet lines highlight in turn. On “asks each module”, four sealed vaults appear one by one as small tickets, each sliding into its socket and growing into a capsule's vault. On “starting rules”, the Policy vault shows days 14, limit 3. On “never sees inside”, the root's key badge stays still while each child's seal mark shows. On “discarded”, a fifth ghost ticket appears, finds no socket, and fades as the frame closes.

Leaves with Root with four attached vaults. No service bands yet. No shelves.

Beat no_shelves_yet — Dynamic children come later

View and focus tree. Focus on Branches.

Narration

Notice what is missing. There are no shelves. A shelf is created later, by Branches, when an admin opens a branch. Install builds the fixed part of the tree. The rest grows with use.

Cue and animation On “no shelves”, the empty fan under Branches shows 0 / 32. On “grows with use”, two faint outlines appear on ribs 3 and 5 and fade again.

Leaves with The fixed tree, vaults only.

Scene bind — The services are drawn on top

Already on screen Root and four vaults, attached, with no service bands.

Beat bind_services — Wiring the call graph

View and focus tree_and_files.

Show One line from Shop, tabbed root/mod.rs — Shop, line 2:

#[cdk_rsx::root(state = App, init = install, restore = reopen)]

Narration

Memory alone does nothing. The root now binds a service to each module and builds Desk from them. This is the call graph from lesson two. Install builds the initial tree on a fresh installation. Restore opens the saved tree on upgrade. Both end with this same binding.

Cue and animation On “binds a service”, a dashed service band and a rim draw over each vault in turn. On “builds Desk”, Desk appears and the call lines draw. On “Install builds the initial tree”, highlight init = install. On “Restore opens the saved tree”, highlight restore = reopen. On “this same binding”, a small bracket labeled bind spans all the service bands.

Leaves with The complete app, empty of data. The bind bracket stays for the next scene.

Scene release_two — A release that changes only rules

Already on screen The complete app.

Beat populated — Jump forward

View and focus release.

Narration

Jump forward to day one-twenty. Two branches are open, five loans are out, and release one is installed. We want a new rule. A member with an overdue loan may not borrow again. That rule lives in Desk's code. No module saves anything new.

Cue and animation On “Jump forward”, the vault tables fill with the populated state and shelves 3 and 5 appear. On “release one is installed”, the card r1 sits in the socket on the rail. On “a new rule”, the card r2 appears on the rail with the note Desk: refuse if overdue. On “saves anything new”, the AppTree flashes briefly with no new file.

Leaves with Populated app, r1 installed, r2 waiting.

Beat services_go — What does not survive

View and focus release.

Narration

Install release two. The old program lets go of its services. Every service band, the call lines, Desk, all of it. Services do not survive an upgrade. Memory does.

Cue and animation On “lets go of its services”, every dashed band, rim and call line dissolves, and Desk with them. On “Memory does”, the vaults stay lit with their values and v1 tabs, and the owning edges stay solid, including ribs 3 and 5.

Leaves with Vaults and owning edges only. r1 leaving the socket.

Beat restore_and_bind — Found again, bound again

View and focus release.

Narration

The new program starts on the restore path. It creates nothing. It finds the root, finds each attached module, and binds the services again. The shelves that were opened last month are still on their keys.

Cue and animation On “new program”, r2 slides into the socket. On “creates nothing”, no ticket appears. On “finds the root”, a soft light travels from the root down each owning edge. On “binds the services again”, bands, rims, Desk and call lines redraw under the bind bracket. On “still on their keys”, ribs 3 and 5 pulse.

Leaves with The complete app on r2, every value as before.

Beat new_rule_answers — Same data, new answer

View and focus release. Focus on Desk and Loans.

Narration

Member five-oh-two asks for a saw. Two loans, under the limit, and a saw is on the shelf. Yesterday this was a yes. But both of their loans were due before today. Release two says no. The data did not change. The rule did.

Cue and animation On “asks for a saw”, lend(502, 3, 30) docks at Desk. On “under the limit”, the check row shows active 2 with a tick and available 1 with a tick. On “due before today”, the Loans rows (103, 3) and (108, 4) light and the check row adds overdue 2 with a cross. On “says no”, a neutral OutcomeCard Refused(OverdueLoan) leaves. On “The data did not change”, all vaults pulse once, closed.

Hold PauseAndExplain pointing at the bind bracket. The balloon reads:

Every start ends here
  install   create tree  ->  bind      once
  restore   find tree    ->  bind      every later start

Leaves with The app on r2, all values unchanged. Lesson 6 asks what the upgrade checked before it trusted that memory.

Brief to hand over

Illustrative.

Root. Attaches Policy, Members, Branches and Loans, and saves nothing else. Install creates and attaches all four in one step, with Policy at 14 days and limit 3. Restore creates nothing. Both paths finish in one shared binding function that wires Desk to the four services. No shelf is created at install.

Release 2. Change Desk only: refuse lend with OverdueLoan when the member has any loan due before today. No file under any memory/ folder changes.

Acceptance test, expected and not run

Step Expect
Fresh install, then policy() days 14, limit 3. No members, branches or loans.
Populate as in the table above on release 1 values as listed
Upgrade to release 2 accepted
Read every value again identical. Branch keys 3 and 5. Shelf 3 has three tools.
lend(502, 3, 30) on day 120 Refused(OverdueLoan), no value changed
give_back(3), give_back(4), then lend(502, 3, 30) Lent { loan 8, due 134 }
List the files that differ between the two releases none under any memory/ folder

Production and source notes

  • Tool Library and the children snippet are illustrative. Shop's root declares two slots in the same form. Shop root version file, lines 2 to 10.
  • The attribute line is real and is line 2 of Shop's root wiring. Shop's install creates the root, attaches Branches and Settings in one store.install call, and returns the root. Shop root wiring, lines 2 and 19 to 33.
  • Both paths call one bind. Shop root wiring, lines 34 to 59. The restore path reopens and binds, and creates nothing. Lines 69 to 76.
  • A created memory that is not attached is retired when the frame ends: Conventions, lines 252 to 254. Constructors create empty state unless configuration needs initial values: lines 261 to 264.
  • Services are transient and are rebuilt, and nothing transient is valid after an upgrade because its bytes were kept: Upgrades, lines 228 to 231. Store architecture, lines 32 to 35.
  • A changed-business-code build over populated memory keeps every value: the nested lifecycle test asserts equal state after such an upgrade. Shop's lifecycle check asserts branches, tax and stock after an upgrade. Both were read, not run. Nested lifecycle test, lines 103 to 106. SDK lifecycle test, lines 55 to 68.
  • Not shown, for the architect's notes: adding a fifth module under the root in a later release is not a code-only change. It changes the root's version file, so it is a migration as in lesson 7. This follows from the root's declaration being part of the contract. No example of adding a slot was located in the checkout.
  • Do not show teardown hooks, static reset or the startup guard. The dissolve is the whole picture at this level.
  • The balloon is the only place the words "install" and "restore" appear side by side. Keep its two rows aligned.