Mental-model review
This is an independent check of the author's stated mental model against the ../newstack checkout at commit 5af68e8a0c293b239b3f11eb0de749432f9f31f0 (clean tree, read on 2026-11-22). Nothing was built or run. Every finding rests on reading the guides, the example sources and the test sources linked below. Where a claim rests on a test, the text names the test and says the test was read, not run.
The model in the brief is right in its main lines. Five points need a correction or a qualifier before they go into narration. They are listed first, and the full claim-by-claim review follows.
The five corrections
| # | The brief says | What the source says | Wording to use |
|---|---|---|---|
| 1 | "We can even have a Map where the Value is another module." | A keyed set of child modules exists, and it is its own attachment type, ChildMap<K, M>, declared in the owner's Children group. It is not a collection Map inside Data. An attachment cannot be placed in Data, and a module identity cannot be saved as a value. |
"A module can own a keyed set of child modules. That is an attachment, declared beside the data, and it is separate from a map of rows." |
| 2 | "The system checks the hash of the types of everything attached." | The check is wider than types and narrower than "everything". It covers the layout and the declared meaning of every module type reachable from the root, plus the SDK kernel, allocator and compiler identity. It does not cover business code, saved values, or pending work. | "An upgrade is admitted only if the new build expects exactly the memory contract the canister last published, or names it as a predecessor." |
| 3 | "Nyxus, Hylix, Minima are using different allocators." | Nyxus and Hylix are engines chosen per memory declaration. Minima is not a third choice of that kind. It is an experimental collection library whose descriptors are Nyxus data. | "Each module memory picks Nyxus or Hylix. Minima collections are fields inside a Nyxus memory, with setup in the root." |
| 4 | "...made to keep things optimized and fast." | The guides refuse this as a general promise. They ask for measurement of the populated application. | "Choose storage by what it must hold and how it must behave. Measure speed on your own populated workload." |
| 5 | "Modules define their next version of types and write the migrate path." | The changed module writes its converter. Its parent's frozen declaration pins the old child version, so the new declaration travels up the owning path to the root. The root names the predecessor it accepts. | "When an attached module changes its declared memory version, update the parent declarations that pin it, up to the root. Each owner converts its own state." |
Claim-by-claim review
1. A module defines versioned memory types and the code that works on them
Verdict: correct.
Every stateful owner has a memory/ folder. memory/vN.rs holds the complete saved Data, any Children, and the opaque Memory marker. memory/mod.rs only lists versions and selects current. The service code beside it uses memory::current. Conventions, lines 8 to 62. The Shop example follows this in four owners. Shop inventory version file · Shop inventory selector
Two additions for the architect:
- One service can own several private memories, each with its own engine. "One module, one memory" is the common case and not a rule. Engines, lines 10 to 14.
- A module can have no memory at all. Shop's
Checkoutis stateless and only composes other services. Shop checkout, lines 12 to 18.
2. The memory is opaque and just a handle outside the module
Verdict: correct, with a precise scope.
What the opaque handle and the owner key guarantee:
- Outside the owner's folder, other code can name only the
Memorymarker type. The data fields are declaredpub(in crate::owner). TheKEYthat opens the data is visible only within the owner. Shop's root version file namesbranches::memory::v1::Memoryandsettings::memory::v1::Memoryand nothing inside them. Shop root version file, lines 2 to 10. - Reading or writing a module's data requires that module's
MemoryKey. Safe code cannot construct one.MemoryKey::newisunsafe, and the source carries a compile-fail example of an attempt to make one. Store library,MemoryKeyat line 102. - A parent holds its child as an attachment. It can attach, take or remove the child, and it can call the child's public methods. It cannot read the child's fields. Conventions, lines 252 to 257.
- A service holds a
ModuleRef, which is a non-owning binding. It does not keep the module alive. If the module is removed, the binding goes stale and later use is refused. Store architecture, lines 114 to 117.
What it does not guarantee:
- It is a compile-time privacy rule inside one crate. It is not a security boundary against
unsafecode, against a module that chooses to export its key, or against whoever controls the canister. - The owner key lets the service reach its own data. It does not prove the business rules in that service are right.
Wording for narration: "Outside the module, its memory is a sealed handle. Only the module's own code holds the key."
3. Other modules and the public canister functions work with modules
Verdict: correct.
A public canister method opens one frame on the root, root::read for a query or root::with for an update, and calls a service method inside it. Shop's checkout endpoint is one line. Shop endpoints, lines 30 to 33.
How collaborating services call each other:
- A composing service declares the services it depends on as
#[service]fields. Inside a method it callsself.branches()orself.settings(), which lend views in the caller's existing frame. No second frame opens. Shop checkout, lines 12 to 34. - Public business methods take domain arguments. They take no storage parameters. Conventions, lines 220 to 226.
- A read frame cannot write.
- Nothing borrowed from a frame may cross an
await. Carry owned values across the call and open a fresh frame in the continuation.
One rule changes how an architect specifies behavior. A frame is not a transaction. Returning an error does not undo writes already made. A trap does, because the Internet Computer rolls the whole message back. So every expected refusal must be decided before the first write. Store architecture, lines 148 to 152. Shop's buy shows the order: quote, compute tax, then sell. Shop checkout, lines 20 to 34.
4. Modules can be nested, and a map's value can be another module
Verdict: nesting is correct. The map wording needs correction 1.
There are two separate graphs, and the architecture guide states this as its first design boundary: "Persistent ownership and transient service composition are separate graphs." Store architecture, lines 17 to 20.
- The owning tree says which module's memory lives under which. It is declared in each owner's
Childrengroup. Each child has exactly one owner, and every path reaches the one root. It decides lifetime: removing a child removes everything under it. - The service dependency graph says which code calls which. It is built in
root/mod.rswhen services are bound. It can cross the tree freely. Shop'sCheckoutdepends onBranchesandSettingsand owns neither. Shop root wiring, lines 37 to 59.
A keyed set of child modules versus a plain map:
Attached ChildMap<K, M> |
Plain Map<K, V> in Data |
|
|---|---|---|
| Where declared | In the owner's Children group |
In the owner's Data |
| What a value is | A whole module with its own memory, key, version and service | A row |
| Who can read inside a value | Only the child module's own code | The owning module's code |
| Removal | Retires the child and everything under it when the frame ends | Removes a row |
| Same key added again | A new module with a new identity, starting empty | A new row |
| Upgrade | The child type has its own version files and converter | Rows convert inside the owner's converter |
Shop shows all of this. Branches declares ChildMap<u64, inventory::memory::v1::Memory>. Shop branches version file, line 3. The native test closes branch 9, opens it again, and reads None for item 44. Shop tests, lines 33 to 35.
A plain map cannot hold modules or handles to them:
ChildSlotandChildMapdeliberately do not qualify as saved data. The source carries a compile-fail example namedhidden_owner. Store children, lines 21 to 28.- A module
Identity"carries no ownership and cannot be deserialized", and it has no saved-data implementation. Store library, line 112.
So a plain map can hold a business key such as a branch number. To reach the module, code asks the owner by that key through a public method.
The SDK sets no count limit of its own on a ChildMap that an architect should rely on. Shop enforces MAX_BRANCHES = 32 in its own open method. The bound is an app decision. Shop branches, lines 4 and 33 to 46.
5. Compose by creating modules, composing them, and exposing public functions
Verdict: correct. Add that "compose" happens twice.
Which app code builds the initial tree: the root's install function, in one store.install call, inside one write frame. It creates the root, asks each child module for a new empty memory, attaches each one in its slot, and returns the root. Shop root wiring, lines 19 to 33. A created memory that is never attached is retired when the frame ends, so creation and attachment belong in the same frame. Conventions, lines 252 to 254.
Dynamic children are not built at install. Their owner creates and attaches them later inside one of its business methods. Shop's Branches::open does this. Shop branches, lines 33 to 46.
Then the root's bind function builds the service graph over that tree. Shop root wiring, lines 37 to 59.
The lifecycle of transient services:
- Built once per installed program, at the end of
installor ofrestore, by binding each service to its module. - Used by every call. Each call borrows views for the length of its frame only.
- Services for dynamic children are bound on demand inside the owner's method, from the keyed attachment. Shop branches, lines 8 to 15.
- Cleared by generated teardown before an upgrade. No service, scope, guard or ordinary Rust allocation is a valid object after the upgrade just because its bytes were kept. Upgrades, lines 228 to 231.
- Rebuilt by
restorein the new program, after any conversion.
6. On upgrade, a module defines its next version and writes the migration path
Verdict: correct for the changed module. Add correction 5.
Two kinds of upgrade exist, and the app's restore code chooses between them.
Same contract. No version file changed. restore reopens the store, opens the root with the current key, and rebinds services. Saved data is untouched. Shop's reopen is this path. Shop root wiring, lines 69 to 76. The nested lifecycle test installs a build with changed business code over populated state and asserts the state is equal. Nested lifecycle test, lines 103 to 106. The Shop lifecycle check asserts stock, tax and branches after the same kind of upgrade. SDK lifecycle test, lines 55 to 68.
Versioned migration. A memory declaration changes. Then:
- The changed owner gets a new
memory/vN.rs. The shipped file stays frozen. The converter lives in the new file. Conventions, lines 42 to 55. - Each parent names exact child versions, so every owner on the path from the changed module up to the root gets a new version too. Their converters only take the old child, hand it to the child's converter, and attach the result. Unchanged siblings keep their version. The guide says "a root V4 may still attach governance V2. Do not renumber unchanged children." Conventions, lines 42 to 45.
- The root attribute names the accepted predecessor with
previous = [memory::v1::Memory]. Only the current contract or an exactly declared predecessor is admitted. The SDK does not rebuild a chain of older versions. Upgrades, lines 129 to 146 and line 205. restoreasks the store which root contract is saved and chooses conversion or a plain open. Root authoring probe wiring, lines 57 to 70.
Owner-local nested conversion in a single upgrade:
- The root converter converts the root's own data and, for each child, takes it, calls that child's own converter, and attaches the result. The shared stable provider probe does this for two children. Composition probe root V2, lines 10 to 37.
- For dynamic children the parent loops over the keyed set. The nested Nyxus probe does
take_first, converts the leaf, and attaches it under the same key. Nested probe root, lines 113 to 124. - A kept attachment is taken from the old slot and attached to the new one unchanged. Its identity and contents survive. The root authoring probe's native test asserts the same identity and the same value
91after conversion. Root authoring probe wiring, lines 163 to 203. A whole unchanged keyed set can move across in one step withadopt_from. Store children, line 235. - A converter reads only its own old data. It reads no parent, sibling or service, makes no calls, and reads no clock. Upgrades, lines 180 to 185.
- All of it happens inside one canister upgrade. There is no background migration and no second step. The whole upgrade must fit the installation budget. A rewrite that does not fit is unsupported. Upgrades, lines 9 to 44.
- Unchanged native collections move into the new record without copying rows. Upgrades, lines 187 to 196.
7. The upgrade checks a hash of the types of everything attached
Verdict: right idea. Use correction 2.
What the compatibility fingerprint covers. The upgrade guide names two independent properties. Upgrades, lines 57 to 63.
- Physical representation. Actual layouts of every module cell, including private collection nodes, allocator metadata and kernel records.
- Interpretation. Each owner's frozen declaration file, the selected child versions, codecs, key ordering, drop behavior, and any sources, dependencies and policies the owner declared.
It follows declared types from the root through every Children group, slot and keyed set. It does not scan the instances in memory. Store architecture, lines 281 to 285. It also folds in the SDK's Store and allocator policies and the compiler identity. Store catalog
Consequences an architect should know:
- The version file is captured as text. Any edit to a shipped
vN.rschanges the fingerprint. That is why shipped files are frozen. Upgrades, lines 65 to 76 and 118 to 123. - Changing the SDK or the compiler can change the fingerprint with no app change. The list of approved equivalent builds is currently empty, and there is no conversion path for the Store kernel or the allocators. An app version migration assumes the same SDK kernel and compiler class on both sides. Compatibility, line 9. Upgrades, lines 155 to 172.
- The 32-bit and 64-bit memory profiles never upgrade into each other. Upgrades, lines 148 to 153.
- The check needs the canonical builder and an upgrade that keeps main memory. A raw Cargo build lacks the startup guard. Upgrades, lines 141 to 146.
What admission establishes: the new program was compiled to read exactly the saved contract, or a predecessor it names. A mismatch is refused before any saved pointer is opened. The new contract is published only after restore succeeds.
What admission does not establish:
- That the converter is correct, or that the business rules still hold on the converted values.
- That saved values are sensible. No value is inspected.
- That the author declared every piece of meaning. The guide says the macro "cannot discover arbitrary business dependencies or prove semantic equivalence".
- That business code is unchanged. Ordinary service and endpoint code is outside the fingerprint unless an owner lists it as a source. The guide says catalog equality "is not a hash of the whole executable".
- That the upgrade fits its budget.
- That the app was ready to upgrade. Pending work is a separate, app-owned check.
Wording for narration: "The canister remembers the contract of the memory it holds. A new build is admitted only if it expects that contract or names it as its predecessor. That proves the starting point. It does not prove the conversion."
8. Compatibility, readiness, verification and failure are app-level decisions
Verdict: not stated in the brief. The source makes each one the app's decision.
- Readiness and maintenance. The root's
checkcallback runs in the old program before the upgrade and can refuse it.shutdownreleases app resources. The SDK "does not infer application quiescence or restore pending application work automatically". Upgrades, lines 222 to 244. Heavy16'scheck_upgradereads its own modules and refuses while any queue or call count is non-zero. Heavy16 root, line 330. Because the check runs in the installed old program, the readiness rule must ship in the release before the one that needs it. - Failed upgrade. A refused admission, a refusing
check, a trap in conversion, or an error fromrestoreall end the same way. The Internet Computer restores the old program and its memory together. The app keeps running on the old release with its values intact. The root authoring lifecycle test asserts the old values after two refused builds and after a late failure. Root authoring lifecycle test, lines 67 to 77. - Later downgrade. After a migration succeeds, the canister holds the new contract. The old build does not name it as a predecessor, so installing the old build is refused at admission. The same test asserts this as "published target rejects downgrade". Root authoring lifecycle test, lines 89 to 91. Going back means writing a new forward version whose predecessor is the current one.
- Same-contract rollback. An older build with an exact matching contract can pass admission. The compatibility suite description lists "new-to-old KEEP" among its cases. The actual rollback still needs readiness and restore to succeed, and business rules can make it unsuitable. Rehearse it with both builds and representative values. This is a reading of the guide. Compatibility, line 69.
- Verification. The upgrade guide lists what to exercise: both versions compile, wrong contracts are refused, conversion and failed conversion, then a real install, upgrade, restore and trap rollback on populated state. It adds "Native tests do not establish IC endpoint or lifecycle behavior." Upgrades, lines 246 to 253.
9. Nyxus, Hylix and Minima place memory and keep things fast
Verdict: needs corrections 3 and 4.
- Nyxus and Hylix are per-declaration choices. "Engine selection belongs to each Memory declaration and its complete Data record." Nyxus is the default. The
hylixoption selects Hylix. A module cannot mix engines inside one data record, and one service can own two memories with different engines. Engines, lines 5 to 14. A Hylix declaration appears in the Hylix probe. Hylix probe records, line 17. - What differs for the designer. Nyxus keeps native values in the canister's preserved main memory, and code uses ordinary Rust collections under the module's guard. Hylix keeps the domain data as encoded records in stable memory, and ownership of stored values is explicit: inserting hands a value over, removing hands it back, and a removed value must be moved or retired or it leaks. The status page calls Hylix "a more demanding authoring model". Both engines use the same tree, the same frames and the same upgrade check. Engines, lines 62 to 66. Status, lines 43 to 46.
- Minima's actual status. "Minima is an implemented experimental foundation." It "is not a third Memory selector". Its collections are fields in a Nyxus data record, with fixed-width payloads in stable blocks. It ships in a separate crate,
cdk-rsx-collections-minima. Minima guide, lines 3 to 8. - Minima's public integration. The root sets up one arena over the canister's stable memory and passes it to the services that need it. If Hylix is also used, Minima owns the single physical stable capability and gives Hylix a view of it. Two stable allocators must never claim the same domain. The module declares each Minima collection's contract in its
dependencieslist. Composition probe root, lines 31 to 53. Composition probe payloads V1, lines 14 to 18. - Which domain requirements justify a choice. Use Nyxus unless a requirement says otherwise. Choose Hylix for a module whose data should live in stable memory and not in main memory, and accept explicit ownership in that module's code. Choose a Minima collection when the data is fixed-width and the collection's contract matches the need, for example a published table that is rebuilt as a whole or an approximate filter. Accept that Minima is experimental and that each populated collection reserves whole storage blocks.
- Speed. "Correctness, lifecycle support and performance are separate questions. Measure populated application behavior." Engines, lines 82 to 86. The Minima guide says exclusive blocks are "a layout guarantee, not a universal performance result".
10. Many collections, including B-trees and probabilistic ones
Verdict: correct. Know which exist and which are experimental.
A small practical set, with the constraint that decides each:
| Need | Choice | Contract that matters |
|---|---|---|
| Exact and ordered | Nyxus Map or Set |
A B-tree ordered by the key's Ord. Range iteration is not a saved snapshot. A paged listing carries its last key and bounds the work per call. Collections, lines 16 to 17 and 29 to 32. |
| Immutable, published as a whole | Minima FrozenSortedMap |
Fixed-width keys and values. Built from increasing keys. No point insert. A change means a replacement build. Experimental. Minima collections, lines 14 to 36. |
| Each entity owns its own state | ChildMap<K, M> |
A module per key, with its own lifetime and version. The app sets the bound. See claim 4. |
| Approximate membership | Minima BlockedBloomFilter |
"Additive approximate membership; positives require exact lookup; no deletion." A negative is exact. A positive must be confirmed against an exact collection. Experimental. |
| Approximate distinct count | Minima MinimaHll |
An estimate only. It cannot list its keys. Its error is statistical. Experimental. |
The Minima benchmark confirms each Bloom positive with an exact lookup and counts those lookups. Minima benchmark tables, lines 62 to 124.
Not available: "The current library exports no native HashMap, radix tree or spatial tree." Collections, line 214.
Every collection must be given a bound by the app. Shop caps items at 1,024 per inventory and refuses the next new item before writing. Shop inventory, lines 4 and 30 to 37.
11. Looking at the files
Verdict: the brief's instinct matches the convention.
An architect can read a design from the tree without opening service code:
lib.rslists what the canister offers.- Each feature folder is one owner. Its
mod.rsholds the public functions. Itsmemory/folder holds what it saves. memory/mod.rsshows which version is current. ThevN.rsfiles are the history of that owner's saved shape, and only the highest one may still be edited before it ships.root/memory/vN.rsshows the top of the owning tree.root/mod.rsshows install, restore and the service wiring.
Conventions, lines 8 to 62 and 259 to 264. RRT Heavy16 uses the same folders for admissions, config, flows, ledger and root. It is cited here as evidence that a large app keeps the convention. It is not a subject of the course. Heavy16 source tree
Exact wordings for the course
Use these sentences as written when a lesson needs the rule.
- "A module is three things: public functions, private memory, and the code between them."
- "Outside the module, its memory is a sealed handle. Only the module's own code holds the key."
- "The owning tree says where memory lives and when it is removed. The call graph says who talks to whom. They are different drawings."
- "A keyed set of child modules is an attachment. A map of rows is data."
- "Decide every refusal before the first write. An error does not undo a write."
- "Install builds the tree once. Restore finds it again. Both end by binding the services."
- "Services do not survive an upgrade. Memory does."
- "A new build is admitted only if it expects the contract the canister holds, or names it as its predecessor."
- "Admission proves the starting point. It does not prove the conversion."
- "Each owner converts its own memory. A parent passes its children down to their own converters."
- "A failed upgrade leaves the old release running. A finished migration cannot be undone by installing the old build."
- "A filter's no is exact. Its yes needs an exact check."