Skip to content

Cross-app calls

A run may send messages to other apps (env::xcall(app, method, &args)). The message is a follow-up: it runs after the sending entry commits. The guest API is in Cross-app calls; this page is how the cluster runs them (crates/node/src/component/xcall.rs).

// Sender (apps/fixture-kv): queue a message; it leaves once this entry commits.
pub fn relay(&mut self, app: String, key: String, value: String) -> app::Result<()> {
env::xcall(&app, "setFromApp", &SetArgs { key: &key, value: &value })?;
Ok(())
}
// Sender: told when the platform gives up on a message.
#[app::allow(system)]
pub fn on_xcall_failed(&mut self, app: String, method: String, reason: String) -> app::Result<()> {
self.xcall_failures.insert(&method, &format!("{app}|{reason}"))?;
Ok(())
}

The target method names who may call it, #[app::allow(app = "<source>")] or #[app::allow(app = "*")], and sees the sender as Caller::App(<source>).

A run’s messages go to its outcome. When the entry ends Ok, they are appended, in order, to the source app’s outbox, kept as hidden rows of the source app’s group. A failed run sends nothing. The outbox holds at most MAX_OUTBOX (10,000) messages; one past it goes to the dead letters at once, and the messages already queued stay queued and are delivered in order.

Before the logged cluster version brings xcallKeepsQueue (1.0.0-rc.39), an xcall past a full outbox also skipped every message queued before it; an entry logged then replays as it applied, so replicas keep one outbox.

The source’s leader delivers the head of its outbox one message at a time, so messages leave each source in order. The target runs the method as an xcall delivery, with Caller::App(<source>).

The node that runs the target checks:

  1. Entry point. The target method’s ABI must allow the source: #[app::allow(app = "<source>")] or allow(app = "*") (allowApps).
  2. Boundary. The two apps are in the same organization. Every app is in one, so an account’s own apps reach each other when they share an organization, and apps of two different organizations never do.
  3. Provenance. The target sees the caller as Caller::App(<source>), set by the node; no argument can claim it. Only where the person the source’s run serves granted it does the call run as that person instead (As the person).

An app calls another as itself: the target sees Caller::App(<source>) and never learns whom the source’s run was serving. A person can let an app do more: call some methods of another app as them, so the target applies its own rules for that person, as if they had called it directly. A calendar that already keeps each person’s events works unchanged under a scheduling plugin.

  • The release says what it would call. Each reference in the source’s signed uses lists the methods of that package it calls as the person (methods, at most 64). The release’s card shows them, and an upgrade’s consent page flags a reference whose methods change.
  • The person grants it. PUT /apps/{source}/delegations/{target} with the person’s passkey over exactly the target and those methods (<source> / __delegate / { target, methods }). They must reach both apps, which are in one organization. DELETE takes it back without a passkey; GET /apps/{source}/delegations lists what they granted. Deleting either app ends it. The grant is the account holder’s own: a session opened on an app’s frontend is refused the route (403), and the source’s frontend asks on the consent page instead (delegate { app, target }), which names both apps and every method before the passkey.
  • The node decides, call by call. When the source’s run was started by the person (their account or an API key of theirs), its message, synchronous call or view of a granted method runs on the target with the person as the caller and env::via() (WIT context.via, calimero:app 0.5.2) naming the source. A message is judged when it is delivered, so a grant taken back meanwhile stops it. Anything else (no grant, another method, a person who no longer reaches the target, a timer or an action, a run another app called) runs as the source app.
  • The target’s checks apply to the person. A method that needs the person’s passkey confirmation is refused (ConfirmRequired); a plugin never confirms for them. A target that wants less for a call through an app reads env::via().

Grants exist only once every node runs 1.0.0-rc.31 (Feature::Delegation), and a message’s outbox row names its person from the logged cluster version that brings it, so every replica keeps the row alike.

env::xcall_call(app, method, &args) runs the target’s method as one call in its own log, as Caller::App(<source>), before the sending run continues, and answers its result; env::xcall_view runs a view on the target’s latest committed state. Both are futures, awaited in an async fn app method (or a generated client’s methods, which are the same futures, typed). Both pass the same checks, and the target must be a component app other than the sender. They are not atomic: the target’s call commits whatever the sender does next, so a target method should be safe to have run (a captcha’s verify spends the challenge either way). A re-run of the sending call replays the target’s answer: the target’s idempotency key is derived from the sender’s, the target, the method, the arguments and how many identical calls came before in the run. A read-only member’s run may make a synchronous view, never a synchronous call. A delivered xcall makes no synchronous call. The methods pipeline.start, pipeline.get and pipeline.cancel reach no method of the target: the node answers them for a linked pipeline app (Runs an app starts).

Concurrency. The SDK runs an async fn method with a small executor of its own: it polls the method until every future it awaits waits on an xcall, then sends those xcalls to the node in one xcall.batch (WIT calimero:app@0.5.7) and polls again with the answers. Futures awaited one after another make one batch each; futures awaited together (app::join!(a, b), app::join_all(v)) are in one batch, which the node runs at once:

let cal = uses::calendar()?;
let (events, count) = app::join!(cal.my_events(), cal.event_count());

The sending run holds its own app’s proposal lock while it waits, so a batch holds it for the slowest request rather than the sum of them. Requests to the same target take turns on the target’s lock, as two callers’ would. Each request of a batch is checked, counted and keyed exactly as the same call or view made on its own, in list order: the occurrence counter runs across the run’s batches, so a batch of two identical calls gets two keys and a re-run makes the same batches with the same keys. A batch is answered in order, a refused request in its place.

Limit Value
Synchronous xcalls one run makes, batched or not (MAX_SYNC_XCALLS); a batch that would pass it is refused whole 16
Arguments of one (MAX_SYNC_XCALL_ARGS_BYTES) 512 KiB
Answer handed back for one (MAX_SYNC_XCALL_RESULT_BYTES) 1 MiB
How long a run waits (SYNC_XCALL_WAIT): for one call, or for a whole batch (one deadline); never past the run’s own wall clock, which then ends it Timeout 3 s

A request still running at the deadline is told it timed out; a call may still commit in its target, and the sender’s retry replays it. A component built before 0.5.4 makes its xcalls one at a time with xcall.call and xcall.view, which nodes keep serving.

The target keeps, per source app, the highest sequence number it applied; a message at or below it is answered as delivered without running. A leader change on either side never runs a message twice. A target keeps watermarks for at most MAX_WATERMARKS (10,000) sources; past that the lowest is dropped.

A timeout or an unreachable target is retried with backoff (at most 30 s between attempts) for up to an hour from the send (XCALL_WINDOW_MS). Then, or at once for a deleted target, one outside the organization, or one that is not a component (an app the node no longer runs), the message goes to the source’s dead letters (the newest 1,000), and the source’s onXcallFailed runs if its ABI has one that allows the system. Anything the target answered, an app error or a trap included, is a final answer; so is a refusal because the target’s developer is over its fuel cap for the day.

A message carries a budget: how many deliveries it and every xcall it leads to may still take. A run that no xcall delivered (a client’s call, a timer tick, an action, onActionFailed) starts a chain for each message it sends, with MAX_XCALL_CHAIN (128) apiece. A delivered message’s run spends one of its budget and splits the rest evenly among the messages it sends, the first ones taking the remainder. A message sent with nothing left goes to the source’s dead letters at once (“the xcall chain used its budget of deliveries”); it takes no outbox slot and its source’s onXcallFailed does not run.

A dead-lettered message’s onXcallFailed run stands in for its delivery: it spends one of the message’s budget and splits the rest among the messages it sends, as the delivered run would have. So a handler that sends again what failed, which fails again, stops with the chain, at the same 128.

So however a chain fans out, one message leads to at most 128 deliveries, and an app whose method sends itself xcalls stops once its chain is spent, rather than running with no client calling it. A chain of a few hops, or a delivered run that fans out to a few apps, stays well inside the budget.

The leader of the sending run sets the budget, and replicas dead-letter a spent one, only once the logged cluster version brings xcallBudget (1.0.0-rc.39): an earlier release would queue it. A message logged without a budget (an earlier release’s) starts a chain when it is delivered, or when its onXcallFailed runs.

Limit Value
Messages one run sends 100
Deliveries one chain takes (MAX_XCALL_CHAIN) 128
Messages one outbox holds (MAX_OUTBOX) 10,000
Retry window (XCALL_WINDOW_MS) 1 hour from the send
Dead letters kept (MAX_DEAD_LETTERS) 1,000
Sources one target keeps a watermark for (MAX_WATERMARKS) 10,000

An empty or overlong app id or method, or a reserved (__) method, is refused at the send.

Where the node implements this chapter, by the names in its code: paths are under crates/node/src unless another crate is named. The design and its reasons are above; a module’s own detail is in its //! doc, and the node’s mental model is crates/node/AGENTS.md.

Code: SystemCmd::SetDelegation, SystemState::delegations, Node::caller_for and forwarded in node/component.rs; docs: protocol xcall “As the person”.

A person lets an app call another as them. The release the source runs lists, per reference in its signed uses, the methods it calls as the person (BundleUse::methods); PUT /apps/{app}/delegations/{target} (api::apps::app_delegate) grants exactly those for the target’s package, with the person’s passkey over <source> / __delegate / { target, methods } (system::delegation_args), both apps reachable by them and in one organization (Feature::Delegation, rc.31); DELETE takes it back without a passkey; GET /apps/{app}/delegations lists the caller’s own. Deleting either app drops the grant (remove_app). The grant route is holder (never a package-bound session); an app’s frontend asks on the consent page (delegate { app, target }, consent_page::delegate_request: both apps and the methods from api::apps::delegation_plan, the page stale when the source’s release moved, and act runs api::apps::delegate after checking the methods are still those shown). A run whose caller is a person offers that person to the apps it calls (forwarded): a synchronous call or view (NodeXcall::person) and a message (XcallOut::on_behalf_of -> Outgoing::on_behalf_of, written only from the logged cluster version that brings Feature::Delegation, Node::carries_person, as the row is replicated state). caller_for decides at the source, for a delivery when it is delivered: as the person, with CallRequest::via / ViewRequest::via = the source, where they granted the source that method of the target and still reach it; else as Caller::App(source) with no person named. The target’s host core gets via with HostCore::with_via (env::via); the usual ABI checks apply to the person, so a confirm method is refused (ConfirmRequired). A run another app called offers no one onward.

(D13, D25, D29, component/xcall.rs.)

An Ok entry’s Outcome::xcalls go to the source’s outbox (XcallHead in ComponentHead, rows rows::COUT ‖ seq, at most MAX_OUTBOX). The source leader’s timer poll (Node::deliver_xcalls, at most DELIVER_BATCH a round) delivers the head through call_component with CallRequest::xcall = XcallFrom { source, seq }, Caller::App, a node:xcall-… key; the target checks the boundary again (same_boundary: one org), its watermark (XcallHead::seen, D25: answered as delivered without running), the ABI (allowApps, "*" = any; abi_check), runs kind = xcall-deliver and records CallEntry::xcall, whose apply moves the watermark whatever the status. The source then logs componentXcallDone { seq, dead }. Timeouts and 5xx are retried (xcall_retry, in memory, backoff_ms) until XCALL_WINDOW_MS from the send; a missing target, another org’s, a wasmer app, or the window passing dead-letters it (rows::CDEAD, newest MAX_DEAD_LETTERS) and runs the source’s onXcallFailed if its ABI allows the system. GET /apps/{app}/xcalls (owner or org admin; a node without a replica asks one, internal/xcalls, Node::app_xcalls). The chain budget: the run’s leader gives each XcallOut its budget in Node::run_with (share_budget, from RunExtras::xcall_budget, the delivered XcallFrom::budget; None starts a chain), only once Feature::XcallBudget is logged (Node::shares_xcall_budget); Outgoing and XcallFrom carry it on, and XcallHead::send dead-letters a Some(0) without taking a sequence number. Node::on_xcall_failed passes the dead-lettered Outgoing::budget as CallRequest::chain_budget, which the handler’s run takes as its RunExtras::xcall_budget. A full outbox: the run’s leader sets Outcome::keep_queue on an entry that sends xcalls once Feature::XcallKeepsQueue is logged (Node::keeps_xcall_queue), and XcallHead::send then dead-letters one past MAX_OUTBOX without taking a sequence number; an entry without the flag replays as an earlier release applied it.

Code: NodeXcall.

A run made with a key (RunExtras::key: a call’s call:<caller>:<idempotency key>, a tick’s tick:<method>:<slot>, an action’s action:<id>, a view’s placeholder) reaches other apps through xcall.call/xcall.view. The target must be another component app within same_boundary (any other answer is one no such app in this organization). A call goes through call_component with the host core’s derived key, Caller::App(source) and CallRequest::sync_from (the target checks the boundary again and runs it as xcall-deliver, so it reaches no further); a view through Node::view (strong). The run’s thread waits at most SYNC_XCALL_WAIT (3 s) while the runtime runs it, and never past its own deadline; two apps calling each other at once both end Timeout at their deadline. A batch (xcall.batch, NodeXcall::batch) prepares each request as the same call or view would (prepare_call, prepare_view), spawns them all on the runtime and waits for them with one SYNC_XCALL_WAIT deadline (wait_all), so a run holds its own proposal lock for the slowest request, not their sum; requests to one target take turns on its lock.