RRT Heavy16: A Workflow From Request to Receipt
Audience task and outcome
- Task Accept a job from a client, run its steps in order, some on this canister and some on a peer, and let the client ask how far it got.
- Observable outcome The viewer can follow a job from the
startendpoint to a receipt and a status. They can author a Takt workflow from its four inputs, a graph file, a payload version, rules and operations, and register it in the build. They can connect a remote step to a peer's route and say what they must declare about it. They can state what has to be finished before an upgrade. In the workflow test, the local graph performs2ledger commands and the sequence graph performs4. - Starting point Lesson 8 built the ledger command. Lesson 5 made one awaited call by hand.
- Handoff This is the last film. The closing beat returns to the upgrade rule from lesson 6.
- Pacing Five minutes. It is the longest film in the course.
The worked example
RRT Heavy16 defines seven workflows. This film uses two. The local workflow runs two steps on its own canister, an Open command and then an Audit command, through the ledger from lesson 8. The sequence workflow sends a Reserve command to a peer canister, runs Deliver locally, sends Close to a second peer, and runs Audit locally. A client starts a job with start(kind, args), receives a receipt number, and reads request_status(number), which moves from Pending to Started with a workflow and an execution number. The native workflow test runs each graph to completion with controlled participants in place of real peers and asserts 2 effects and 2 block references for local and 4 and 4 for sequence. Local workflow folder · Sequence workflow folder · Endpoints · Public messages · Admissions · Workflow test
Takt compiles a .takt.json graph into typed Rust. The graph owns the stages, their order and their retry policy. The handwritten memory version owns the payload. Rules hold pure predicates and mappings, and Operations hold the individual effects. Reactor delivers a remote step's request to the peer and brings back its reply. Author Takt workflows in Rust · Takt · Reactor · Orchestration
The story in one pass
A client calls start and gets a receipt number at once. The job waits in a bounded queue. The app starts it as a workflow and the receipt's status changes. Open the local workflow's folder and read its four inputs, then see how the build registers them. Watch the two local steps each record a ledger block. Turn to the sequence workflow, where one step runs on a peer. See what the author declares for that step and what an unclear reply means. Finish with the root's readiness check, which holds an upgrade until every job is done.
Views and visual objects
Use the shared visual language and the Heavy16 AppTree and App frame from lesson 8. Two cards come forward, Admissions and Flows. The Admissions StateCard is the receipt list from lesson 4, rows of number · status, with its next_to_start marker.
The new object is the GraphCard. It draws a workflow's states as the rounded node cards from the Takt film, in the order of the graph file, with one arrow per Next. A local state has a solid outline. A remote state has a dashed outline and a small clock. The current state is filled. Use the same node drawing at every size.
A second canister boundary labeled peer · left holds the same App frame at small scale. Its ledger and block row are the lesson 8 drawings, unchanged.
| View | Framing and anchor |
|---|---|
intake |
Client at left, the canister's public edge, the Admissions card and its receipt list. |
flow_files |
The workflows/local/ part of the AppTree, one or two EditorPane columns, and the local GraphCard beneath. |
run_local |
The local GraphCard above the Ledger card and block row. |
remote_step |
The sequence GraphCard, this canister and peer · left, with one EditorPane. |
readiness |
ReleaseStrip from lesson 6 with an EditorPane on root/mod.rs. |
Scene intake — A receipt first
Enters with The Heavy16 App frame from lesson 8.
Beat start — Accept the job and answer immediately
View and focus intake, pane on src/lib.rs then src/api.rs.
Show src/lib.rs lines 148 to 155, then src/api.rs lines 16 to 22.
#[cdk_rsx::update]
fn start(kind: api::Workflow, args: api::Start) -> api::Admission {
match start_workflow(kind, args.into()) {
Ok(id) => api::Admission::Ok(id.into()),
Err(error) => api::Admission::Err(error),
}
}
pub enum Admission {
#[serde(rename = "ok")]
Ok(Nat),
#[serde(rename = "err")]
Err(cdk_rsx_takt::Problem),
}
Narration
A client starts a job by calling start with a workflow kind and its arguments. The job may take many steps across several canisters, so the endpoint does not wait for it. It records the request and returns a receipt number, or a typed problem if it cannot accept.
Cue and animation On “calling start”, bring the pill start(Local, …) to the public edge. On “does not wait”, show the job's eventual path as a faint dotted trail leaving toward Flows. On “a receipt number”, add row 1 · Pending to the Admissions list and return ReceiptCard ok 1. On “a typed problem”, show a neutral err Busy card beside it.
Leaves with Receipt 1 · Pending and ok 1 at the client.
Beat bounded_queue — The app decides how much it accepts
View and focus intake, pane on src/admissions.rs.
Show Lines 151 to 158 of enqueue, with lines 18 and 19.
if caller != self.owner.owner
|| run > 1_000_000
|| job > 1_000_000
|| delay_millis > 60_000
|| self.queued()? >= MAX_PENDING
{
return Ok(Err(Problem::Busy));
}
Narration
Admissions is ordinary application code like the Shop's Inventory. It checks the caller and the arguments, and it refuses with Busy when too many requests are waiting. All of this happens before the request is saved.
Cue and animation On “checks the caller”, band the first condition. On “too many requests are waiting”, band MAX_PENDING and draw the cap line on the receipt list. On “before the request is saved”, bracket the if above the faded push call further down.
Leaves with A capped receipt list with one pending row.
Beat status — Ask how far it got
View and focus intake, pane on src/api.rs.
Show src/api.rs lines 24 to 35, then src/lib.rs lines 180 to 187.
/// An accepted ingress receipt is distinct from a workflow execution ID.
pub enum RequestStatus {
Pending,
Started {
workflow: Workflow,
execution: Nat,
#[serde(rename = "receivedAt")]
received_at: u64,
},
Rejected(cdk_rsx_takt::Problem),
}
Narration
The client can ask for the status of its receipt. At first it is Pending. Shortly after, the app takes the next request in line and starts it as a workflow. The status becomes Started and names the workflow and its execution number.
Cue and animation On “the status of its receipt”, send request_status(1) and return Pending. On “takes the next request in line”, advance the next_to_start marker past row 1 and move a job chip from Admissions to the Flows card. On “becomes Started”, change the row to 1 · Started and return ReceiptCard Started { workflow: Local, execution: 1 }.
Leaves with Receipt 1 · Started and a job chip at Flows.
Scene author_workflow — Four inputs and a registration
Enters with The job chip at the Flows card.
Beat folder — What a workflow is made of
View and focus flow_files, tree only.
Show The listing of src/workflows/local/. local.takt.json, mod.rs, memory/mod.rs, memory/v1.rs, rules.rs, operations.rs.
Narration
Each workflow has its own folder. The graph file says which steps run and in what order. The memory version declares the data a job carries. Rules are small pure functions the graph refers to. Operations are the steps that do something.
Cue and animation On “The graph file”, tint local.takt.json and draw an empty GraphCard. On “The memory version”, tint memory/v1.rs. On “Rules”, tint rules.rs. On “Operations”, tint operations.rs.
Leaves with Four tinted inputs and an empty graph.
Beat graph — The graph file owns the order
View and focus flow_files, pane on local.takt.json.
Show Lines 44 to 72, the States block and StartAt.
"States": {
"Open": {
"Type": "Local",
"Input": "Request",
"Output": "Request",
"Handler": "ops.open",
"Next": "Audit",
"Capabilities": [
"Dispatch",
"Clock"
]
},
"Audit": {
"Type": "Local",
"Input": "Request",
"Output": "Request",
"Handler": "ops.audit",
"Next": "Done",
"Capabilities": [
"Dispatch",
"Clock"
]
},
"Done": {
"Type": "Succeed",
"Input": "Request"
}
},
"StartAt": "Open"
Narration
The local graph has three states. Open is a local step handled by ops dot open, and it leads to Audit. Audit is handled by ops dot audit and leads to Done, which succeeds. The order of work lives in this file and nowhere in the Rust code.
Cue and animation On “three states”, draw nodes Open, Audit and Done on the GraphCard. On “handled by ops dot open”, band "Handler": "ops.open". On “leads to Audit”, band "Next": "Audit" and draw the first arrow. On “which succeeds”, draw the second arrow and mark Done. On “nowhere in the Rust code”, dim the operations.rs entry in the tree briefly.
Leaves with A complete three-node graph.
Beat retry_policy — Retries are declared, with a rule
View and focus flow_files, two panes.
Show local.takt.json lines 30 to 43, the Defaults block. rules.rs lines 35 to 37.
"Defaults": {
"OnExhausted": "Pause",
"TimeoutMillis": 30000,
"Retry": [
{
"When": "R.retryable",
"Backoff": {
"IntervalMillis": 250,
"MaxDelayMillis": 2000,
"MaxRetries": 5
}
}
]
},
pub fn retryable(value: &M::Error) -> bool {
matches!(value, M::Error::Unavailable)
}
Narration
The graph also declares what happens on failure. A step is retried when the retryable rule says so, up to five times with a growing delay, and the job pauses if retries run out. The rule itself is one line of Rust. Only the Unavailable error is worth retrying.
Cue and animation On “when the retryable rule says so”, band "When": "R.retryable" and link it to the function. On “up to five times”, band MaxRetries. On “the job pauses”, band "OnExhausted": "Pause". On “Only the Unavailable error”, band M::Error::Unavailable.
Leaves with The graph with a small retry badge on its edge.
Beat payload — The data a job carries
View and focus flow_files, pane on memory/v1.rs.
Show Lines 22 to 35, the Error and Progress enums, with Request's field list scrolled just above.
#[repr(u8)]
#[derive(Clone, Debug, PartialEq, Eq, NyxusData, cdk_rsx_memory_abi::Tagged)]
pub enum Error {
Rejected = 0,
Unavailable = 1,
Transport = 2,
}
#[repr(C, u8)]
#[derive(
Clone, Debug, PartialEq, Eq, NyxusData, cdk_rsx_memory_abi::Tagged, cdk_rsx_takt::Progress,
)]
pub enum Progress {
Request(Request) = 0,
}
Narration
A job's data is saved between steps, so it is declared in a versioned memory file like any other saved data. Progress lists the stages a job can be in, and here there is one, Request. It derives Takt's Progress. The file also declares the job's error type and how large a payload counts as, and those size answers must be truthful.
Cue and animation On “a versioned memory file”, pulse the v1 in the path and place a lock outline, recalling lesson 6. On “Progress lists the stages”, band enum Progress. On “derives Takt's Progress”, band cdk_rsx_takt::Progress. On “the job's error type”, band enum Error. On “must be truthful”, scroll to impl PayloadSize for Request and band its header only.
Hold or transition Hold on the PayloadSize header. Balloon reads the app writes these size functions. Takt trusts them for its admission limits.
Leaves with The payload file tagged v1.
Beat operations — The steps that do something
View and focus flow_files, pane on operations.rs.
Show Lines 72 to 87, the generated::Bindings implementation, then lines 24 to 30 of the local helper in the same file.
impl<S: Services> generated::Bindings for Operations<S> {
fn open(
&self,
context: &flow::Context,
value: &M::Request,
) -> flow::Known<M::Request, M::Error> {
self.local(context, value, wire::Kind::Open)
}
fn audit(
&self,
context: &flow::Context,
value: &M::Request,
) -> flow::Known<M::Request, M::Error> {
self.local(context, value, wire::Kind::Audit)
}
}
Ok(block) => {
let mut r = r.clone();
assert!(r.blocks.len() < 32, "bounded graph block references");
r.blocks.push(shared::number(&block));
flow::Known::Ok(r)
}
Err(e) => flow::Known::Err(classify(&e)),
Narration
Takt generates a trait from the graph with one method per handler. The app implements it. Open and audit each dispatch a ledger command, the one from the last lesson. On success the step adds the block number to the job's data and returns it as the next stage. On failure it returns one of the job's errors.
Cue and animation On “one method per handler”, link fn open to the Open node and fn audit to the Audit node. On “dispatch a ledger command”, draw a call line from each node toward the Ledger card. On “adds the block number”, band r.blocks.push. On “returns one of the job's errors”, band flow::Known::Err(classify(&e)).
Leaves with Each graph node linked to one Rust method.
Beat register — Tell the build about the graph
View and focus flow_files, two small panes.
Show src/workflows/build.rs lines 3 to 6 with the list shortened to its first entry, and src/workflows/local/mod.rs lines 1 to 4.
use cdk_rsx_takt_generator::{build_workflows, workflow};
build_workflows([
workflow!("src/workflows/local/local.takt.json"),
// … six more
])?;
pub mod memory;
pub mod operations;
pub mod rules;
cdk_rsx_takt::workflow!("local");
Narration
Two lines connect the graph to the build. The build script lists the graph file. The workflow's mod dot r s includes the generated code. If the graph names a handler or a stage that the Rust code lacks, the build fails, and Takt's project check points at the line in the graph file.
Cue and animation On “The build script lists”, band the workflow! line. On “includes the generated code”, band cdk_rsx_takt::workflow!("local") and show a ghost file generated appear in the folder. On “the build fails”, change "ops.open" to "ops.opne" in a small inset, stamp build error with a pointer to that line, then restore it.
Leaves with The workflow folder complete with its generated ghost.
Scene run_it — Local steps, then a remote one
Enters with The job chip at Flows and the complete local graph.
Beat run_local — Two steps, two blocks
View and focus run_local.
Show src/workflows/tests.rs, the first lines of all_seven_source_graphs_have_the_same_effect_counts that check the local graph.
let local::memory::current::Progress::Request(local) = check!(local, 2);
assert_eq!(local.blocks.len(), 2);
Narration
Now the job runs. Open dispatches its command and the ledger records a block. The job moves to Audit, which records a second block, and then to Done. The workflow test runs this graph and counts two commands and two block numbers in the finished job.
Cue and animation On “Open dispatches its command”, fill the Open node, send Open(3) to the Ledger, and forge block 000. On “moves to Audit”, fill Audit, send Audit(3), forge block 001. On “then to Done”, fill Done. On “counts two commands”, pass both assertions and show the job chip carrying blocks [0, 1].
Leaves with A finished local job and two blocks.
Beat remote_state — A step on another canister
View and focus remote_step, pane on sequence.takt.json.
Show src/workflows/sequence/sequence.takt.json lines 45 to 59, the Reserve state.
"Reserve": {
"Type": "Remote",
"Operation": "ops.reserveRemote",
"Contract": "R.contract",
"Next": "Deliver",
"Catch": [
{
"When": "R.rejected",
"Map": "R.failed",
"Next": "Rejected"
}
],
"Input": "Request",
"Output": "Request"
},
Narration
The sequence workflow starts with a step of a different type. Reserve is Remote. It runs on a peer canister. The graph names an operation for it and a contract, and it catches a rejection and routes the job to a Rejected state.
Cue and animation On “a different type”, draw the sequence GraphCard with Reserve, Deliver, CloseRemote, Audit, Done and Rejected. On “Reserve is Remote”, give Reserve and CloseRemote dashed outlines and clocks. On “a contract”, band "Contract": "R.contract". On “catches a rejection”, band the Catch block and draw the side arrow from Reserve to Rejected.
Leaves with The sequence graph with two remote nodes.
Beat remote_operation — What the author declares for a remote step
View and focus remote_step, pane on sequence/operations.rs.
Show Lines 119 to 120 and 129 to 144, the start of the RemoteOperation implementation and its prepare. Then sequence/rules.rs lines 38 to 42.
impl<S: Services> flow::RemoteOperation<M::Progress, M::Error> for Remote<'_, S> {
const SAFETY: flow::Safety = flow::Safety::Idempotent;
flow::RemotePreparation::Request(shared::saved_request(
context,
(self.destination)(r),
r.caller,
"work.dispatch",
&command(r, self.kind),
r.expires_at,
))
pub const contract: flow::ParticipantContract = flow::ParticipantContract {
id: "work.dispatch.v1",
safety: flow::Safety::Idempotent,
evidence: flow::Evidence::Receipt,
};
Narration
Prepare builds the dated ledger command for the peer's work dot dispatch route. The operation declares that it is idempotent. A retry sends the same request, and the peer returns its existing receipt for that command within the replay window. The author must check that the peer offers that guarantee before declaring the step safe to retry.
Cue and animation On “Prepare builds the dated ledger command”, band saved_request and lift a request pill Reserve(3) out of Reserve. On “work dot dispatch”, band "work.dispatch" and send the pill along a dashed arrow with a clock to peer · left. On “declares that it is idempotent”, band SAFETY and the graph contract's safety line. On “returns its existing receipt”, repeat the same call pill and return the peer's original block number. Hold on both Idempotent declarations.
Hold or transition Hold with the block forged on the peer. Balloon on Safety::Idempotent reads the author's promise about the peer. Takt relies on it when it retries.
Leaves with One block on the peer and a reply on its way back.
Beat reply — Known, failed, or unknown
View and focus remote_step.
Show sequence/operations.rs lines 145 to 164, the reply method.
let Ok((result, _caller)) = shared::dispatch_reply(bytes) else {
return flow::Reply::Unknown;
};
match result {
Ok(block) => {
// …
flow::Reply::Ok(r)
}
Err(e) if shared::is_too_old(&e) => flow::Reply::Unknown,
Err(e) => flow::Reply::Resolved(flow::Known::Err(classify(&e))),
}
Narration
When the reply comes back, the operation sorts it into three outcomes. A block number means the step succeeded. A clear business error means it failed, and the graph's catch takes over. A reply the operation cannot read yields Unknown. That outcome stays unresolved until the app has evidence.
Cue and animation On “the step succeeded”, band flow::Reply::Ok(r) and place its receipt next to the arrow to Deliver. On “it failed”, band the Resolved line and show a separate business-error receipt beside Rejected. On “cannot read”, band the first Unknown and show a third receipt with a question mark at the Reserve node.
Hold or transition Hold on the question mark. Balloon reads Unknown stays unresolved. Then cut to the successful test case with its block receipt already in view. Continue that separate run through Deliver, CloseRemote, Audit and Done, adding the local blocks for Deliver and Audit.
Leaves with A finished sequence job with four block numbers. The test asserts 4 effects and 4 block references.
Beat peer_side — The route on the receiving canister
View and focus remote_step, focus on peer · left, pane on src/lib.rs.
Show src/lib.rs lines 58 to 66 and 81 to 85, the work.dispatch branch of route, with the telemetry and fault-injection lines and the feature gate hidden.
if route == "work.dispatch" {
// …
app.commands()
.dispatch(context.origin.caller, now, command)?
// …
return Endpoint::<wire::Command, wire::DispatchOutput>::new("work.dispatch").dispatch(
context,
bytes,
|context, command| dispatch(context, command.as_ref()),
);
}
Narration
On the peer, the same application code receives the request. A route is a named, typed entry for messages from other canisters. This one decodes a command, dispatches it to the ledger, and replies with the result. Only canisters the owner has added as peers are accepted.
Cue and animation On “A route is a named, typed entry”, band Endpoint::<wire::Command, wire::DispatchOutput>::new("work.dispatch") and draw a small labeled port work.dispatch on the peer's boundary. On “dispatches it to the ledger”, band app.commands().dispatch. On “added as peers”, show the addPeer endpoint name from lesson 5 on the peer's public edge.
Leaves with Two canisters joined through the work.dispatch port.
Scene before_upgrade — Finish the work first
Enters with Both jobs finished.
Beat readiness_check — The app says when it is ready
View and focus readiness.
Show src/root/mod.rs line 4. Frame the literal line around check=check_upgrade, with the install arguments outside the editor crop. Then show lines 330 to 352, shortened to the first conditions.
pub fn check_upgrade() -> Result<()> {
cdk_rsx_store::assert_quiescent();
current().read(|app| {
let work = app.flows().runtime().stats()?;
let wire = app.reactor().stats()?;
if app.admissions().queued()? != 0
|| work.pending != 0
// …
{
return Err(Error::InvalidInput(
"typed-root KEEP requires full business and transport drain",
));
}
Ok(())
})
}
Narration
Heavy16 finishes its outstanding work before an upgrade. The root names a check callback. The check refuses the upgrade while any request is queued, any job is pending, or any message is in transit. The app finishes that work and tries again.
Cue and animation On “names a check callback”, band check=check_upgrade. On “any request is queued”, band app.admissions().queued()? != 0 and show one Pending row on the Admissions list while a new code card stops at the ReleaseStrip. On “any job is pending”, band work.pending != 0. On “finishes that work”, finish the pending work and tick the app check box from lesson 6.
Hold or transition Hold on the ticked box. Balloon reads drain first, then upgrade.
Leaves with A Heavy16 app ready to request the upgrade, with empty work queues and the existing receipt list and balances in view.
Try it
Verify Check the graph file, then run the workflow tests from the newstack root. Check and scaffold · RRT benchmark, native checks
source tools/env.sh
cargo run --manifest-path cdk-rsx/Cargo.toml -p cdk-rsx-takt-generator \
--bin takt-gen --locked --offline -- \
check benches/rrt/canister/src/workflows/local/local.takt.json
cargo test --manifest-path benches/rrt/Cargo.toml --locked --offline \
-p rrt-fourcans-canister workflows
Expected app-level result. The graph check exits successfully, and all_seven_source_graphs_have_the_same_effect_counts passes.
Change, adapted exercise Add a step to the local workflow. In your copy of local.takt.json, add a Close state of type Local with "Handler": "ops.close", the same Input, Output and Capabilities as Open, and "Next": "Audit". Point Open's Next at Close. In operations.rs, add fn close to the generated::Bindings implementation, calling self.local(context, value, wire::Kind::Close). Build once before adding close to see the error for the missing handler. Expected result afterward is that the local graph performs 3 commands and returns 3 block references, so the existing test's check!(local, 2) and local.blocks.len() assertions must be updated to 3. This state is not in the checkout. The graph file is one of the sources Heavy16 pins in its saved contract, so for a deployed app this is a contract change. Heavy16 build script
Source and review notes
| Item shown | Status |
|---|---|
.takt.json format, cdk_rsx_takt_generator::{build_workflows, workflow}, cdk_rsx_takt::workflow!, generated Bindings, cdk_rsx_takt::Progress, PayloadSize, Known, RemoteOperation, RemotePreparation, Reply, Safety, ParticipantContract, Problem |
Shipped Takt API and generator. Takt authoring |
cdk_rsx_reactor::typed::Endpoint, Decision, Context, add_peer on the Reactor view |
Shipped Reactor API. Reactor |
check = …, shutdown = … on #[cdk_rsx::root] |
Shipped SDK API. Lifecycle and pending work |
api::Start, api::Admission, api::RequestStatus, Admissions, Seed, workflows::Services, shared::dispatch, shared::saved_request, Operations, Remote, route, check_upgrade |
Heavy16 application code. Services and the shared helpers are local conveniences and are not SDK interfaces. |
start_workflow's page_profile wrappers, the Tripwire start variant, instruction_profile, state() metrics, telemetry in route, config().should_reject, test_reject_next |
Benchmark measurement and fault controls. Hide these lines in every excerpt. |
The sixteen-canister population, tools/run.py, tools/audit.mjs, host workload and verifier |
Benchmark setup. Never shown. |
ReactorHost, CoordinationHost, start_runtime, reactor_receive, reactor_turn in lib.rs |
Host wiring that connects the libraries at startup. Heavy16 writes it once in lib.rs. The film shows start, request_status and route and leaves this wiring unopened. |
- The Takt authoring guide's sample writes a local step with
"Operation". Heavy16's local steps use"Handler", and its remote steps use"Operation". The schema accepts both forms. Show the Heavy16 files as written. Workflow schema - The receipt number and the workflow execution number are different identifiers. The comment on
RequestStatussays so. Keep both visible in theStartedreceipt. - The orchestration guide states the rules behind
reply. A timeout does not cancel a call that was really sent and does not authorize a replacement effect, and saved retry bytes and operation identities stay the same across retries. The film states the author's side only, which is to declare safety truthfully and to returnUnknownwhen the outcome is unclear. - The workflow test replaces real transport with controlled participants. Its header says PocketIC qualifies the real wire and scheduler separately. Do not present the native test as a multi-canister run.
- The status page says upgrades with unresolved remote work are not implemented in general. Full drain is the default, including for this root. The film's closing sentence reflects that. Do not mention the narrower documented exceptions. Workflow evolution and upgrade boundaries
- Keep Reactor's batching, scheduling and delivery internals out of frame. A dashed arrow with a clock is the whole drawing of a remote step.
- The other five workflows, parallel, scheduled, child, fanout and relay, follow the same folder shape. Name them on a closing card only if the edit has room.