Store architecture
Store gives a Rust canister one actor-owned tree of private module memories. Nyxus stores native retained values in preserved main memory. Hylix stores positional records and offset-backed collections in IC stable memory. Both use the same module identities, attachment rules, scopes and checked root lifecycle. Experimental Minima collections combine retained descriptors and scalar control with fixed-width stable payloads beneath that same tree.
Store admits retained images against explicit memory contracts. See the upgrade rules for admission and conversion, conventions for authoring, status for supported usage, and testing for verification.
Design boundaries
Persistent ownership and transient service composition are separate graphs. A parent owns a child's attachment and calls its public service to change its state. A service binds to its own memory identity and needs no path through its ancestors to access that memory.
Each stateful owner declares complete versioned memory in memory/vN.rs.
memory/mod.rs selects the active version and exports intentional construction
and conversion operations. Data and the memory key remain private to the owner;
children expose their memory markers and public domain operations.
Root code constructs attachments, composes version conversions and wires services. Business operations belong to their modules. Parent conversion delegates a changed child to that child's converter rather than interpreting another owner's fields.
The attached module tree is durable application state. Service instances, executor futures, timers and ordinary Global allocations are transient. Preserving Wasm bytes does not make arbitrary Rust allocations safe to reopen. Every saved native representation must satisfy its data and admission contracts.
Implementation layers
| Layer | Responsibility |
|---|---|
| Platform | Target memory geometry, shared main-memory page authority and byte providers |
| Nyxus | Explicit retained allocator and recursive native-data admission |
| Hylix | Stable64 arena, fixed codecs and explicit stable ownership |
| Minima | Experimental exclusive stable blocks, fixed encodings and borrowed workspace |
| Collections | Native Nyxus containers and offset-backed Hylix containers |
| Store | Module identity, private access, attachment lifetime and conversion |
| Memory ABI | Compiled physical and semantic representation certificates |
| SDK | Wire/Tripwire endpoints, calls, executor, timers and generated root lifecycle |
| Wasm tool | Final artifact validation and guarded startup transformation |
Store depends on the engines, not on concrete Collections implementations. Independent native collections can use Nyxus's allocator and data contract, provided they supply complete physical and interpretation recipes. Their algorithms and conversion helpers remain with their collection crate.
The exact graph collections follow these same boundaries: native graphs own Nyxus allocations, while Minima graph descriptors own stable payload. Both belong to ordinary private owner Data. Logical graph edges add neither Store attachments nor proof that another owner's business record exists.
Minima follows this split: cdk-rsx-engine-minima provides the retained block
authority and byte access; cdk-rsx-collections-minima provides algorithms.
Its Root and Collection descriptors are Nyxus Data, with explicit semantic
dependencies and ordinary physical admission. It adds no Memory selector.
When composed with Hylix, one physical stable capability supplies both Minima
blocks and Hylix's virtual contiguous image; independent allocators cannot share
that domain. The existing engines and Store paths stay unchanged.
Runtime and Nyxus heaps share an allocation strategy with separate page ownership. Small slots occupy buddy spans; each page keeps its free-span bitmap locally, while global bins contain available pages. Empty pages return immediately to the shared provider. This limits cross-page metadata writes without moving live objects or changing their lifetimes. Optional numeric Nyxus placement hints separate write-hot spans while default/read-mostly spans share page capacity; ordinary Global allocation remains independent. See runtime memory.
Method entry co-locates its hot transient controls in a build-reserved gap above the stack. Typed partitions hold the executor, runtime allocator, root App header and Hylix frame controls; payloads keep their normal allocators. Startup resets those controls after old-code teardown and before rebinding. This changes placement, not persistent ownership or the upgrade contract. The maintained entry path maps the corresponding SDK work.
The SDK's call boundary preserves owned response bytes and distinguishes cleanup-synthesized rejection from an observed reply/reject callback. Response decoding and application effect identity remain separate responsibilities. An oversized or undecodable successful response does not prove the remote effect failed. See Wire calls and the call implementation.
Module identity and ownership
A memory declaration generates an opaque ModuleMemory marker, owner-private
MemoryKey, source contract and certificate for its actual module cell.
The module separates owner Data from accounted Children attachments.
Marker identity defaults to its module path and name; application code does not
choose numeric storage slots.
Each Memory declaration selects the engine for its complete Data record.
Nyxus is the default; hylix selects Hylix. One service may own several private
memories with different engines. Their composition may attach beneath any
parent at any depth, provided its ownership path reaches the actor root.
See engines for the representation boundary.
ChildSlot<M> owns an optional child. ChildMap<K, M> owns dynamically keyed
children. These containers account for attachment ownership and remain separate
from ordinary business-data collections.
Creation and taking an attachment produce move-only Detached tickets.
Attaching consumes the ticket. Create, move and reattach within one write scope;
an unconsumed detached module retires during scope finalization. Ownership
operations reject cycles and attempts to act through the wrong owner.
ModuleRef<M> and service Rc values are nonowning. They do not keep a removed
module alive. Module references carry namespace, slot, generation, an admitted
pointer and a binding epoch. Slot reuse rejects stale identities; conversion
changes the epoch so an earlier typed binding cannot interpret its successor.
The directory persists a vacant-slot head; retired slots link through their unused pointer word. Creation pops one vacancy or appends, without scanning live modules, and checks global generation exhaustion before changing the directory. The directory keeps its high-water capacity. Native collection values have no individual Store objects or per-entry ownership records. Reclamation visits the owned subtree or values being removed rather than sweeping unrelated application state.
Scoped services
A service binds once through a private binding::Memory<OwnerMemory> and lends
borrowed views. Generated service adapters project declared dependencies using
the caller's existing scope. Persistent attachment paths do not dictate the
service dependency graph.
One outer Actor::read lends a ReadScope; Actor::with lends a write Scope.
Synchronous service composition shares that actor frame. Ordinary domain methods
do not need ancestor forwarding closures or raw Store arguments.
An owner reads or writes its own Data through guards. Read scopes cannot write. Release mutable guards before callbacks or another service that could borrow the same memory. Module and collection loans prevent conversion, retirement or frame completion from invalidating active access.
No scope, view or borrowed value may escape its actor closure or cross await.
Carry owned DTOs through asynchronous calls and reacquire a fresh scope in the
continuation. Transient Rc sharing between services grants no persistent owner
or permission to read another module's private Data.
Scopes manage access and lifetime finalization. They are not a local transaction system. Returning an error does not undo completed mutations. Validate expected business rejection before persistent writes; the IC supplies rollback when an execution traps. Native tests require an explicit host snapshot when simulating that behavior.
Nyxus native representation
Nyxus containers keep their explicit allocator through growth, clone and drop.
Owned elements recursively satisfy NyxusData. Ordinary std containers use the
transient Global allocator; copying their headers into retained Data does not
make their backing allocations durable.
Map and Set use the pinned standard-library B-tree implementations with Nyxus allocation. Vec and Queue use native retained buffers. Box, Rc, Weak, String, SharedSlice and SharedString provide additional admitted owning carriers. SharedBytes and SharedText retain checked immutable ranges on one shared byte allocation, with complete header ownership in the compiled physical graph. The transient append-only packet builder writes only disjoint unpublished tail bytes and never exposes its complete owner. Published ranges remain immutable; their final shared owner releases the complete allocation. See collections for construction and retention costs. Collection operations run directly on typed values under a module guard, without a codec or Store publication step for each entry.
NyxusData establishes the recursive data-admission boundary. A separate physical
certificate covers the concrete representation, including private container
nodes and allocator headers. Neither a Rust type name nor the outer value's size
is enough to qualify a preserved native image.
Native ownership uses Rust destruction and concrete retained reference counts. There is no tracing collector, automatic relocation or arbitrary heap adoption. Cyclic Rc structures and forgotten values can leak. Engine and collection policies form part of the admitted interpretation contract.
Recursive data admission and audited opaque kernel edges also exclude pointers from persistent state into Runtime allocations. Physical ABI matching alone is not that proof. Unsafe custom admission must preserve the exclusion. Startup does not repair forgotten retained reference counts or synthesize destructors.
Hylix stable representation
A Hylix module uses the same native directory, attachment and private-key rules.
Its retained module cell contains hylix::Record<Data>, a fixed stable-allocation
descriptor. Domain fields and collection contents live behind stable64 offsets.
The small kernel anchors remain retained and require KEEP; a heap-independent
stable root is not a project requirement.
Hylix Data derives fixed positional Codec and HylixValue contracts.
Offset/generation identities distinguish live allocations from reused storage.
The arena owns allocation, reuse and bounded byte access; collections own their
layouts, read spans and decoded working rows.
Protected slab descriptors validate allocation identities before payload headers. Empty slabs become reusable extents across size classes; adjacent free extents can coalesce within the boundaries left by protected descriptor segments. A request still needs one suitable contiguous extent. Block generations are opaque identities, without global numeric ordering. The engine contract defines the allocator format and reuse rules.
One actor frame decodes each accessed module record once. Later guards borrow that frame's current value under the existing module loan. Successful write-frame finalization retires pending owners, publishes remaining dirty module records, then flushes the arena's dirty byte spans. Collection row edit guards publish their own rows into coherent arena buffers when they end. A provider finalization failure after the callback traps, so retained and stable changes rely on the same IC rollback boundary.
Decoded module workspaces do not survive the frame. The bounded segment cache may retain clean bytes after committed write frames. Losing that cache cannot lose committed state. Queries discard their buffers without flushing, and provider teardown releases cache backing before KEEP.
Cache misses copy stable bytes into initialized transient heap workspace. Cold allocation validation can also load a protected descriptor segment. A bounded decoded slab cache reuses metadata and batches allocator changes until mutable eviction or finalization, before the stable flush. Immutable misses preserve pending changes; only clean entries survive commit. Another bounded cache reuses validated allocation headers by complete block identity. Private header writes update it; retirement invalidates the token before release, and frame discard clears it. Misses perform protected descriptor and header admission; every requested payload range retains its bounds check. Pinned views keep their segment payload alive; all-pinned misses use scoped scratch rather than extending the resident-cache bound. Collections can decode directly from a provider loan when the requested span permits it.
Stable ownership is explicit. Insertion transfers an owner; removal and pop return one. Move it into another durable owner or retire it. Use explicit sharing for another counted edge and retire displaced owning fields. Ordinary handle Drop is inert; discarding a raw owner can leak stable storage. Branded temporary owners provide lexical disposal and transfer for supported construction and mutation operations.
Cell and SharedCell guards retain allocation and frame loans. Forgotten writers reject frame completion; a later frame cannot accept their delayed publication. SharedCell combines a counted owner header and encoded mutable value in one allocation. Final retirement excludes live guards before freeing nested owners. Snapshots carry identities or read access without manufacturing a durable edge.
Named-record field tokens project fields under the same whole-module borrow. They do not infer ownership changes. Replacing an owning field still requires explicit transfer or retirement. Raw codecs are trusted storage infrastructure, not a decoder for client-provided persistent handles.
See collections and runtime memory for the authoring surface and allocation details.
Minima's separate storage contract keeps allocator metadata outside
exclusive stable payload blocks. Collections choose narrow spans or whole 4 KiB
nodes and borrow reusable workspace. A private root/owner header is shared by
compact page descriptors, with sixteen inline entries and retained overflow.
An opaque two-word CollectionBlockRef borrows the whole move-only collection
and its admitted block base. That lifetime proves live owner/page ownership;
provider access still checks exact Root and byte bounds. Separate raw BlockRef
access retains domain and live owner-generation checks because a raw block can
outlive its collection. Wrappers forward both typed paths. Drop checks physical
generations and reclaims whole blocks through retained authority. Collection and
virtual Hylix growth share bulk page acquisition, reserving metadata and growing
only the fresh physical extent needed after reuse. Transient providers must end
before KEEP and reopen from the admitted Root afterward. The
foundation setup describes this
binding. Native provider reopening does not establish actual canister KEEP or
rollback; verify those lifecycle boundaries separately.
Physical and semantic admission
A preserved pointer is useful only if the new executable can interpret its complete representation. The compiled root catalog combines actual target layouts, module source contracts, engine/Store policies and the interpretation contracts of the actual admitted carriers. It includes private native nodes, allocation headers and owning child types.
The owning type closure is compiled from certified Children, ChildSlot and ChildMap declarations. It does not discover module types by scanning instances. Unsupported layouts fail compilation. Layout computation and static contract checks belong at build time; changing bounds, ownership and generations still require runtime checks.
Physical layout and semantic meaning are different inputs. A changed comparator, drop implementation or serializer can invalidate saved state without changing its width. Owners declare relevant sources and dependencies explicitly. The generator cannot prove an arbitrary application's dependency closure.
Carrier proofs supply their own interpretation recipe. The compiler follows native and logical codec types, including payloads erased from an offset-backed descriptor, and freezes the selected policy metadata beside the physical certificate. Root admission folds that metadata; ordinary data binding retains its physical check without another policy traversal. Roots no longer add an entire Collections package policy. Shared implementation recipes remain shared dependencies; test-only items are excluded from production-source recipes.
Libraries retaining interpreted Wire bytes pin the codec contract in their own memory. Consumer DTOs, custom serializers, key ordering and drop behavior remain explicit owner contracts; type reflection cannot discover arbitrary business dependencies. There is no runtime schema registry or instance scan.
Wire encodes communication separately from native or stable memory layouts. Ordinary public and peer application interfaces use bounded Wire or explicit Tripwire routes for compact fixed areas and selective request reads. Tripwire transmits no schema or framing words; compiled positional contracts must match between producer and consumer. Root persistence admission checks the retained representation independently and cannot establish a remote message's contract. Typed nested records and bounded lists carry exact windows on the original source, validate selected container metadata without payload materialization, and encode directly into the final destination. Their views remain scoped to synchronous execution. Fixed external IC protocols retain their required encoding. See Wire.
The qualified compiler and standard-library representation recipes are part of native admission. Build-time persistence qualification may map an exact reviewed implementation fingerprint to an existing interpretation identity; unknown fingerprints remain distinct. Physical facts and owner declarations are never replaced by such mappings. This preserves one runtime contract comparison, without a runtime compatibility registry. Matching layout alone does not establish unchanged interpretation, and cross-format image migration remains unimplemented.
Root conversion and installation
Memory versions freeze the source and target contracts for an intentional application upgrade. A converter consumes its own source Data, transforms changed fields and delegates changed opaque children. Unchanged native collections can move without copying their rows. Changed ordering requires explicit reindexing.
The generated root compiles the current catalog and explicitly declared predecessors. It does not reconstruct a historical migration chain at startup. Changing the executable does not convert saved bytes, and a predecessor is not automatically accepted under changed kernel or interpretation policies. Allocator and Store-directory conversion are separate, unimplemented mechanisms. The freeze boundary describes the complete persisted invariant and qualified implementation/toolchain closure an eventual release must preserve.
Canonical Wasm preparation installs the startup guard. During KEEP:
- Old code checks its business and transport boundary, clears registered transient services, timers, executor and library cache providers, then checks every declared owner and provider again after destructors. Callback, task, timer, loan and Hylix publication/flush barriers remain strict. The clean marker certifies that quiescence; it does not require every Global/Runtime allocation to have been freed. Provider traversal belongs only to teardown.
- Raw startup validates bootstrap and provider geometry and consumes the marker before resetting statics or invoking Rust.
- Startup resets the SDK-control gap and the new linker-bounded static/BSS range, replays initializers and admits the compiled catalog before saved pointers open. Build-time bounds cover every active initializer; stack and unused static bytes need no reset. Admission accepts only the current or an exact declared predecessor. Before new Runtime allocation, validated provider recovery frees only old Runtime page ownership. It never interprets the old Runtime payload or frees Nyxus runs. Old code does not perform this reset.
- Restoration opens the admitted source, performs explicit conversion, rebuilds services and publishes the target catalog only after successful binding.
Unknown source images reject rather than reformat. Failed admission or a late conversion trap relies on IC installation rollback to restore executable and memory together. Store maintains no undo journal or savepoints.
The IC may slice installation across rounds without exposing a partially converted root to ordinary queued updates. DTS does not remove total instruction or memory limits. Collection conversion must still fit the actual installation budget and available space; no universal migration-size guarantee is implied.
Applications must establish their own safe business boundary before teardown. The SDK still requires quiescent callbacks, tasks, timers, loans and providers; it does not migrate unresolved remote effects or infer whether an application may replace their identities. See upgrades.
Verification and deployment
The SDK supports wasm64 canisters by default and explicit wasm32 canisters; native targets serve tests and tools. The memory profiles have distinct saved formats and native layouts. Cross-profile KEEP is rejected before saved pointers open; compiler, physical and semantic catalog checks remain required. Use the canonical builder, since raw Cargo Wasm lacks the checked startup transformation. Runtime and retained allocations share platform page authority; stable memory remains a separate address space.
Memory-cost analysis distinguishes logical accesses from charged regions. Record the selected execution environment's accounting geometry and first-read behavior. Copies and heap-buffer touches remain work even when a stable read avoids mapping its source. Profiling defines the measurement boundaries.
Actual-canister lifecycle and matched complete-workload evidence complement native tests. A passing microbenchmark does not establish callback recovery, upgrade safety or complete workload cost. Grown capacity is distinct from live allocation and RSS. Preserve exact artifacts, source identities, measurements and rejected candidates with each run; benchmarks defines the comparison contract.
Use root upgrades to establish application quiescence and qualify the incoming build against the installed persistence contract. Consult current support for the application boundaries and SDK testing when qualifying changes.