cdk-rsx-reactor
Durable ordered Wire transport and one shared scheduler for canister services.
Nyxus state is owned by memory::{RuntimeMemory, ReactorMemory}; transient
services bind those modules and expose read/write views on the caller's scope.
Saved payloads use native retained collections and immutable shared slices.
Reactor owns the orchestration Error and Result types used by delivery,
scheduling and the libraries built on them. With tripwire-workload, its
tripwire_codec module supplies bounded value-message encoding/decoding,
canonical scalar frames and principal helpers. That feature is independent of
tripwire, which selects Reactor's packed peer transport.
Tripwire ingress places admitted operation, route and body bytes in shared append-only chunks, leaving room for the owner header within 64 KiB. Queue entries retain checked byte/text spans; larger frames own a dedicated chunk. Authentication, descriptor validation and each frame's instruction-budget check precede its source copies. The packed reader checks row geometry and dynamic fields before iteration. Duplicate prefixes and unaccepted suffixes copy no payload bytes. Chunk capacity can include zero-filled unused space, and the last queued entry, completion or snapshot releases its owner.
Retries reuse each saved frame's payload bytes, origin and sequence. Reactor assembles each exchange from the eligible queued frames. A partial acknowledgement removes the accepted prefix, leaving the suffix queued. Wire exchanges use sparse extension blocks on batches, segments and frames. Each transport payload case has a stable tag and a bounded body. The records inside a case, including the origin and response body, carry sparse extensions. Borrowed reads validate extents and known fields against the shared message budget before admission. An unknown required case leaves the batch unacknowledged and eligible for retry. Acknowledgements use stable decision and rejection tags with sparse prefix records. Turn messages carry their own extension blocks. Response mailboxes authenticate the original address and attempt. Logical completion does not end an outstanding physical callback. In the default lifecycle, the actor checks full drain and shuts down the controller before KEEP. SDK cleanup opens a fresh Store frame after a real callback trap.
The controller pumps from one-shot SDK timers. The SDK discards a timer without running it when its message traps, or when its self-call is rejected for good, as happens to a wake in flight when the canister is stopped. The controller then forgets that timer and pumps again 60 seconds later. A pump that keeps trapping therefore runs once a minute, and other wake requests wait for that retry. A deadline pump that completes sooner cancels it.
Send a standalone request
The tools bundle includes examples/rrt-chat. It binds Reactor, Rechain, and
Takt in one typed root and exercises cross-canister delivery and drained KEEP.
Chat example
- Attach
RuntimeMemoryandReactorMemoryto the Store root. Bind both on install and restore with the local canister ID and installed reader version. Authorize the peer withadd_peeron both canisters. Root memory · Install and bind - Implement
ic::Hostwith the Store scope the controller supplies. Forward its methods toreceive,process_one,fanout_one,prepare_exchangeandfinish_exchangeon the Reactor view. Expose boundedreactor_receivethroughic::receive_wireand the self-guardedreactor_turnthroughic::turn_wire. Start timers withic::start(store, host, runtime)after binding. Host · Exports · Controller lifecycle - Declare an
Endpoint<Input, Receipt>and callEndpoint::requestin a write frame. Give each business operation a stableOrigin::operationand save its returnedAddresswith the pending work. Register a synchronouswatchafter saving the address. A ready result can invoke the watch immediately. On the peer, routeprocess_onethroughEndpoint::dispatch. Commit the business effect and its receipt in the handler's Store frame before returningDecision::Reply. Use the operation ID to look up the committed receipt if the app sees the same operation again. - Consume the mailbox with
take_result(address)in the scope supplied to the watch or in a later write frame. DecodeOutcome::ReplywithEndpoint::decodeand settle the pending operation in the same frame. ReconcileOutcome::Expiredaccording to the app's rules. Before ordinary KEEP, drain app-owned pending work and checkReactorView::assert_drainedto include unresolved and unclaimed addresses. Shut down the controller withic::shutdown()and release the shared scheduler withruntime.scheduler.shutdown()in the root's teardown. Bind the retained memory and start the controller again on restore.
The SDK controller dispatch switch holds new Reactor exchanges and scheduled turns. An exchange already in flight can acknowledge frames and release its permit. The canister still accepts peer ingress, and unsent frames retain their exact saved bytes. Explicit resume wakes pending work. Successful KEEP rebinds the controller with dispatch enabled. The root's Reactor upgrade checks still apply, including the ordinary drain of addressed work and outgoing transport. Pausing with unresolved work can require resuming to finish delivery before trying KEEP again. Takt-owned calls can use an explicit checkpoint for replies already queued in the Reactor inbox. Controller dispatch switch · Takt queued-reply KEEP
Physical completion returns a callback permit. A usable logical ACK advances the accepted prefix per priority lane. A business receipt comes from the handler and is delivered through the response mailbox. If a physical reply carries no usable ACK, Reactor retries the remaining frames with their exact saved payload bytes, origins and sequence numbers. A new exchange can group those frames differently. Physical delivery and acknowledgements
Run the typed request → watch → take_result example from the repository
root with the pinned compiler, prepared Cargo home and isolated target. It checks
that the ACK leaves the mailbox pending and that taking the receipt clears
the address for drain. Example source · Test setup
source tools/env.sh
cargo test --manifest-path cdk-rsx/Cargo.toml -p cdk-rsx-reactor --offline --locked \
request_response_mailbox_keeps_exact_source_bytes
Run the callback fixture to check the installed Host, including a physical reply with a malformed ACK, exact retry and drained KEEP. Build and run · PocketIC and Wire runtime setup
Author bounded replies and events
Install matching max_batch_bytes and max_batch_items settings across peers
that exchange frames. A single-frame batch accounts for 256 batch bytes, 512
frame bytes, the encoded payload, and the route name for a reply. Use the
smallest configured allowance when defining result limits for a route.
Keep typed results bounded and test their largest valid encoded values.
Use typed::Endpoint::dispatch_evolving with typed::{encode_evolving, decode_evolving}
to use a route DTO's Wire evolution projection in both directions. Derive
Wire on evolving records. Add an optional field with #[wire(id = N)] and
keep its ID attached to its original meaning. IC Wire stages present reply
extensions and open case bodies within the route's resource limits.
Preflight variable results before changing business state. If a route allows
an effect to commit without the full result, define a compact typed outcome
that says the result is unavailable and preserves the original effect
identity. Keep Later and Blocked decisions free of effects. An unexpected
oversized reply traps before enqueue, allowing the IC to roll back the turn.
An oversized publication leaves the recipient bucket intact.
A host can explicitly opt into a narrower reader-upgrade KEEP boundary with
ReactorView::assert_reader_upgrade_ready and
ic::shutdown_for_reader_upgrade. All business work must be drained separately;
only unblocked inbox frames requiring a newer reader may remain. Outgoing frames,
addresses, watches, subscriptions, publications and physical calls still block
that boundary. Ordinary assert_drained and ic::shutdown remain strict.
Cold restoration binds the same or a greater installed reader generation, then
calls ReactorView<Scope>::restore_reader(now) once before starting the controller.
It schedules newly supported frames using their original deadlines and saves the
advanced reader floor. Repeating restoration adds no readiness entries. Queued
bytes, sequence prefixes and blocked work are unchanged; downgrades reject.
The generation asserts installed capabilities. It never converts a positional
Wire contract or permits decoding a changed schema under an existing route.
The spec/ protocol models remain useful checks of delivery, ordering,
subscriptions, reservations and scheduling. They do not establish Rust lifetime
or compiled-ABI safety. Native tests and actual IC fixtures cover those separate
boundaries. See RRT for build and lifecycle policy.
License
This crate is available under the ICP3V License.