Chat canister
The chat reducer owns users, channels, message histories and replay windows in
chat/memory/v1.rs. Other services use its read-only selectors and dispatch typed
actions through the shared Rechain runtime. Workflow state and its generated
definition live under workflows/send/; submitted payloads are immutable retained
values, with the original logical admission bounds.
The root attaches module owners and binds one shared Reactor scheduler, Rechain
runtime and Takt runtime. Endpoints borrow a root frame for synchronous work.
Rechain dispatches the chat reducers, and the reducers retain channel messages
in application memory. This canister configures its Rechain chain with
record: false.
Follow startup and restore
- Declare the owned library and application memories, then attach them on install. Root memory · Install and reopen
- Bind the services once per install or restore. Start the Reactor IC controller, attach the scoped Takt driver, and start Rechain on the same scheduler. Service binding · Runtime startup
- Register the Takt JSON in the build script. Its operation bindings draw their views from the driver's current write scope. Generator registration · Send graph · Scoped definition
Chat uses drained KEEP. Reactor can store an incoming business reply while scheduled work is paused. A pending reply can prevent KEEP after the SDK callback counters reach zero. Resume dispatch and let the workflows and transport drain before retrying the upgrade. The root then clears the runtime services and rebinds them on restore. Root lifecycle · Other Takt KEEP boundaries
Run the packaged example
Set example=rrt-chat when following the release build instructions. Set
POCKET_IC_BIN and host using the bundled host setup in the same shell.
Release build ·
Host setup
node "$host/rrt-chat/run.mjs" \
--artifact="$run/artifacts/rrt-chat" --pocket-ic="$POCKET_IC_BIN" \
--result="$run/chat.json"
The runner uses generated Wire methods to populate two local canisters and send a message across them. It checks sender authorization, then lets a business reply reach the paused source. KEEP refuses with zero SDK callbacks and preserves the queued reply and the Running source. After manual resume, the original send completes once. A drained KEEP preserves history and the workflow result, and a second send checks dispatch after restore. Generated-client runner
Rehearse KEEP with a queued reply
Build three variants from the same packaged Chat directory after setting up the release build. The V1 feature includes queued-reply admission in the old image. The V2 feature restores the saved reply, and the trap variant checks rollback after reattaching the watches.
for image in addressed-keep addressed-keep-v2 addressed-keep-restore-trap; do
python3 "$sdk/tools/build-app.py" --manifest-path "$run/app/Cargo.toml" \
--features "$image" --name "$image" --out-dir "$run/artifacts" \
--offline --locked >"$run/$image.log" 2>&1 || exit
done
v1="$run/artifacts/addressed-keep"
node "$host/rrt-chat/run.mjs" --artifact="$v1" \
--candidate="$run/artifacts/addressed-keep-v2" \
--pocket-ic="$POCKET_IC_BIN" --result="$run/chat-queued.json"
node "$host/rrt-chat/run.mjs" --artifact="$v1" \
--restore-trap="$run/artifacts/addressed-keep-restore-trap" \
--pocket-ic="$POCKET_IC_BIN" --result="$run/chat-rollback.json"
Each run populates a separate old canister. The candidate run proves automatic
resume and one delivery. The trap run reads the preserved pause and then
resumes the original execution manually. The candidate command also supports
--past-deadline with a fresh result path. For apps with two supported
definitions, register both drivers before restoring the watches.
Queued-reply lifecycle and restore order
Test from the checkout
Native tests cover authorization, duplicate and conflicting nonces, bounded retention, population atomicity, delivery counters, and workflow query authority.
source tools/env.sh
cargo test --manifest-path tests/Cargo.toml --locked --offline -p rrt-chat-canister --lib
The Chat correctness suite checks local, same-subnet, and cross-subnet routes with larger populations.