App execution
An app is a calimero:app component: a WASM component, built with
calimero-sdk, that defines a state machine: its data types and the methods
that change them. An execution (a run) is one call of one method. On a
cluster, only the app group’s leader runs calls; the other replicas apply
what the run produced (Replication).
The node runs components on calimero-app-engine-wasmtime through the host core
calimero-app-host (crates/node/src/node/component.rs,
crates/node/src/component.rs), preparing each bundle once and caching the
compiled artifact by its hash. A WASM core module (an SDK 0.12 app, which ran on
wasmer) is refused at upload (400 UNSUPPORTED_BUNDLE); an app of that kind
that a data directory still holds is listed and can be deleted, and anything
else on it answers 410 UNSUPPORTED_ENGINE.
What an app looks like
Section titled “What an app looks like”A method is a Rust function on the app’s state; &mut self makes a call,
#[app::view] a read. This is apps/kv-store’s set and get:
use calimero_sdk::prelude::*;
#[app::state(version = 1)]pub struct KvStore { entries: UnorderedMap<String, String>,}
#[app::event]pub enum Event { Inserted { key: String, value: String }, Updated { key: String, value: String },}
#[app::logic]impl KvStore { #[app::init] pub fn init() -> app::Result<Self> { Ok(Self::load()) }
pub fn set(&mut self, key: String, value: String) -> app::Result<()> { let event = match self.entries.insert(&key, &value)? { Some(_) => Event::Updated { key, value }, None => Event::Inserted { key, value }, }; env::emit(event, Audience::All)?; Ok(()) }
#[app::view] pub fn get(&self, key: String) -> app::Result<Option<String>> { Ok(self.entries.get(&key)?) }}meroctl app build turns the crate into a component with its ABI embedded
(calimero:abi), which the node reads to tell views from calls and to find
confirm methods (Build). On a cluster, a call to
set is one run on the leader, and the map’s writes are its diff.
One run
Section titled “One run”A run reads the app’s state as an ordered, immutable version (StateView);
its writes stay in the run. When it ends, they become the outcome’s diff,
which every replica applies. Each run gets a fresh instance of the component
from a pool of precompiled ones, dropped when the run ends, so nothing in a
module’s memory or globals carries from one caller to the next.
A run ends with one status, the same whichever engine ran it:
| Status | The caller gets | In the log |
|---|---|---|
Ok |
the result, and the events the caller is in the audience of | the diff, events, xcalls, started actions and compute starts |
AppError { code, message } (the method returned an error) |
422 APP_ERROR, details.{code, fields} |
logged, nothing else kept |
Trap OutOfFuel, OutOfMemory, StackOverflow, Fault (a guest panic, an out-of-bounds access, unreachable, a host panic), HostDenied (a call the run’s kind may not make) |
422 TRAP, details.{kind, detail} |
logged, nothing else kept |
Trap Timeout (the wall clock ran out) or Unavailable (the node had no instance slot, memory or file bytes for it) |
503 TIMEOUT, details.retryAfter |
not logged |
A logged failure spends the call’s idempotency key, so a retry with the key
answers the same failure. A timeout depends on the node’s load, not on the call,
so it is not logged and the key stays unspent: the client retries with the same
key. Outbound requests a run made are logged whatever its status, because they
left the node (below). A trap’s detail
is a fixed text, never data from the guest.
What the host offers a cloud run
Section titled “What the host offers a cloud run”The calimero:app world (crates/app-wit/wit/calimero-app.wit):
| Interface | What it does on a cluster |
|---|---|
storage |
The app’s replicated state: get, put, delete, the commutative add, ordered range |
context |
The caller, the app’s id and owner, its organization, the caller’s role and teams there (org-role-strict answers as org-role, from the node’s replica of the system state), the applied index, unique ids, and starting an action |
events |
Emit an event to an audience (all, the caller, listed accounts, a team, the org’s members or admins); a removed member stops receiving at once |
blobs, files |
The app’s blobs and sealed files |
search |
The app’s own full-text indexes, in views |
xcall |
Send a call into another app (outbox), or call or view one synchronously |
runs |
Start or cancel a compute run on a job node, the uploader of a sealed file, publish a done run’s output (logged writes only) |
rebuild |
A migration’s new key space; migrations are refused (MigrationsNotSupported), so no run gets it |
action |
Inside an action: its key, and views and calls of the app |
wasi:clocks, wasi:random |
The run’s clock and randomness, served by the host (Time and randomness) |
wasi:cli/stdout, stderr |
The app’s log (Logging); wasi:cli/environment is empty: no variables, no arguments |
wasi:http |
Outbound HTTPS, from actions and as recorded requests of a call (below) |
A package may also ship a compute component (world compute: files,
job and WASI’s clocks and randomness, no storage, no network), which job
nodes run outside the log (Compute actions).
A component imports this world and nothing else. Its WASI interfaces are
pinned to 0.2.12 and calimero:app is 0.5.7; an import at an older patch of
the same minor (wasi:*@0.2.z, calimero:app/*@0.5.z) links as well, so an
app built before a patch keeps installing and running. Nine WASI interfaces
that Rust’s standard library on wasm32-wasip2 imports whatever the app does
are accepted and served by stubs that refuse:
wasi:cli/{stdin, exit, terminal-input, terminal-output, terminal-stdin, terminal-stdout, terminal-stderr} and wasi:filesystem/{types, preopens}.
Stdin is empty, no terminal is present, preopens lists no directory, every
filesystem function fails and exit traps Fault. Nothing reaches the node’s
operating system. Any other import, wasi:sockets among them, is refused when
the bundle is uploaded or installed (400 BAD_BUNDLE).
Kinds of run
Section titled “Kinds of run”handle(kind, method, args) is the component’s one export; the kind says what
the run may do. A host call the kind does not allow traps HostDenied.
| Kind | Runs as | Logged | May |
|---|---|---|---|
init |
The app’s owner | Yes | Read and write state, emit events, xcall.send, unique-id, create files, start and cancel compute runs, publish outputs |
call |
The caller: an account, an API key, or public (not signed in; context.visitor names a visitor through a public link) |
Yes | All init may, plus synchronous xcalls, start-action and outbound HTTP |
timer |
system |
Yes | All a call may |
xcall-deliver |
app(source), or the person the sending app served, with their grant (Cross-app calls) |
Yes | All init may, plus outbound HTTP; no synchronous xcall, so a chain of them is one hop |
view |
The caller | No | Read state, search, xcall.view; any write, event or outbound request traps |
action |
Whoever started it | Its calls are | No state: action.view, action.call, synchronous xcalls, outbound HTTP |
blobs.* work in every kind but an action; files.info and runs.uploader in
every kind; files.open only in a compute run, which is an action run on a
job node (Compute actions). A method’s kind and
whom it admits come from the ABI, which
the node checks before it calls handle: a view never runs as a write, and a
confirm method never runs as a view.
Storage
Section titled “Storage”A component has one key space: its own keys, which the node keeps as hidden rows of
the app’s group, sealed on disk. Per-caller data is rows keyed by
env::caller(), and writer sets are rows the app checks before it writes
(apps/team-space); the host keeps no space of its own inside
an app’s keys. (SDK 0.12 apps had a private and a host space beside the shared
one; they are gone with that SDK.)
- Keys are at most 1 KiB; a longer one traps
HostDenied. Values have no cap of their own: the run’s bytes and the entry size bound them (Limits). add(key, delta)changes an integer without the guest reading it: the value is a shortest-form CBOR integer (an absent key is 0), the sum is stored the same way, and the add counts as one write. A value that is not such an integer, or a sum that overflows, trapsHostDenied. The log records the summed value.- A range cursor reads the state as of when it opened: the committed state
plus the run’s writes made before then, never writes made after.
getand the diff see the newest writes. So a scan that moves records ahead of itself (an update that changes their index key) never meets them again, where it could otherwise loop until it ran out of fuel. - The checked writes (
put-checked,delete-checked,add-checked) answer a write past the run’s write count or bytes aslimit-exceeded { limit, max, attempted }, write nothing for it, and let the run go on;put,deleteandaddtrap instead, for components built before them.
What the node checks after the run
Section titled “What the node checks after the run”Before a run’s outcome becomes an entry, the node applies these host-side rules:
- Read-only team members: a member whose row in the app’s team is read-only
reaches the app’s views only: a call to any other method is refused with
403before it runs, so no run burns the developer’s fuel uncounted. - Entry size: an entry over the log’s cap is logged trapped (
HostDenied), and arguments over 512 KiB, a call’s or a view’s, are413 ARGS_TOO_LARGE. - Conflicts: a run built on a state another entry has since moved past, or on a bundle an upgrade replaced, commits as a no-op and runs again.
Outbound HTTPS
Section titled “Outbound HTTPS”A component sends HTTPS from an action, or as recorded requests of a call
(both below), at most MAX_HTTP_REQUESTS (8) per run either way. Either way the request leaves only when every gate holds:
- the operator turned outbound on and allows the host (
[outbound]in the node’s configuration); - the app’s bundle is a signed release whose manifest declares a URL prefix covering the request;
- that prefix was approved for the publisher by whoever the cluster’s governance gives outbound approvals;
- never from a view,
init, a migration, or a read-only member’s call; httpson port 443 to a name that resolves only to public addresses, within the size limits, no redirects.
Actions (component apps)
Section titled “Actions (component apps)”A calimero:app component calls out from an action: an #[app::action]
method that runs outside the log, on the app’s leader. A call can also make recorded requests itself
(below), never a view.
- Start. A client calls the action’s method through
/intents, or a call or timer runsenv::start_action(method, &args). Either way an entry logs that it started, under a key (a.<term>.<seq>.<n>), and the answer is{ "actionId" }. - Run. The leader runs pending actions in a bounded pool, with a 10 s
budget and the starter as caller. An action has no storage. It reads
with
ctx.view, writes withctx.call, and sends HTTP withctx.fetchoverwasi:http. Eachctx.callis its own log entry under a key derived from the action’s key, the method, the arguments’ hash and an occurrence count, so a retried action’s calls replay, while two identical calls in one run are two writes and a retry that takes another path gets new keys rather than another call’s stored result. A method marked#[app::allow(action)]is reachable only from the app’s own actions. - Outbound. A request leaves only through the same gate as
above. The URL must sit under a prefix the signed release’s manifest
declares, whoever governance gives outbound approvals (the app’s organization, or the operator) must have approved it, the operator’s hosts apply, and
an action run sends at most 8 requests (
MAX_HTTP_REQUESTS). A credential the manifest binds to the host (secrets: one header or body field) is attached by the node, never placed by the app, and redacted from the response (Secrets). Bodies are bounded in-memory buffers, so a guest cannot block a node thread. - End. Success, or an app error, a fault or out-of-fuel, ends the
action at once. A timeout is retried with backoff, 5 attempts in all. The
end is logged. A failure sends an
ActionFailed { actionId, method, reason }event to the starter and runs the app’sonActionFailedas the starter. A new leader resumes every action that has not ended, with the same key.
Outbound HTTP from component calls
Section titled “Outbound HTTP from component calls”A component’s call, timer or xcall delivery may send requests itself (up to 8 per run)
(env::fetch), for a check that belongs in the same request as the
write it guards, such as a captcha service verifying a Turnstile token:
- The same gate as actions. A URL the signed release declares under
outbound, its organization (or, per governance, the operator) approved and the operator allows; a credential the manifest binds to the host is attached by the node and redacted from the response. Views,initand migrations cannot send (HostDenied), nor can a read-only member’s call. - Once, recorded. The leader sends it while it runs the call, before
proposing. The call’s log entry records the exchange (
Outcome::http: the request as the app made it, with placeholders, and the response the gate returned; bodies cut to 64 KiB), whatever the call’s status. Followers apply the diff and never fetch, and a retry with the same idempotency key replays the recorded answer. A run the log never commits (a leader race, a timeout) recorded nothing and sends again when it re-runs. - Bounded. The node waits at most 1.5 s for the response, inside the
call’s 2 s budget; a timeout, a refusal or an unreachable host is an error
the app’s
fetchreturns. - Trust. The leader sees the response before it is logged. Attestation covers the code that made the request and its TLS connection, not the remote server’s answer: the same trust as an action’s request.
apps/fixture-captcha’s verifyTurnstile is the example; the kv
fixture’s setHumanTurnstile reaches it with a synchronous xcall, so the
token is checked and the form written in one request.
Time and randomness
Section titled “Time and randomness”The host serves wasi:clocks and wasi:random itself, never from the node’s
operating system, by the kind of run:
| Run | Wall clock | Monotonic clock | Randomness |
|---|---|---|---|
init, call, timer, xcall delivery |
The entry’s timestamp | Fixed at the entry’s timestamp | ChaCha20 seeded for the run by the leader; followers see only the diff |
| View | The timestamp of the newest entry applied where it reads | Fixed at that timestamp | The node’s CSPRNG, not recorded |
| Action | The node’s clock, rounded down to the second | Fixed at the action’s start | The node’s CSPRNG, not recorded |
| Compute run | The timestamp of the entry that started it | Fixed at that timestamp | ChaCha20 from the run’s seed, so the run repeats exactly |
The monotonic clock never moves within a run, and a guest’s sleep or poll is
ready at once, so no guest code can measure elapsed time: a run cannot time
other tenants’ work, and a sleep never holds a node thread. A request for more
than 1 MiB of random bytes in one call traps HostDenied; the SDK asks in
pieces.
The leader stamps each entry with the later of its own clock and the last applied entry’s timestamp plus 1 ms, so an app’s timestamps never go backwards, even across a leader change. Idempotency expiry reads these timestamps, never a node’s local clock, so every replica drops the same records.
Timers
Section titled “Timers”An #[app::every("…")] method is a timer. The app’s leader looks for due
ticks every 100 ms (TIMER_POLL). A timer’s slots fall at the timestamp of the
app’s init entry plus whole multiples of its interval, and the leader
proposes the latest due slot (componentTick). The tick runs as system;
env::timer() gives its scheduled slot and the previous one applied, as
decimal strings on the wire.
- Once per slot. A replica applies a tick only if its slot is later than the timer’s last applied one, so a tick that two leaders propose around a failover runs once.
- Failures count. A tick that traps or returns an app error is logged with
its status and its slot counts as applied: it is not retried, and
previousstays right. A tick that times out is not logged, and the next poll proposes the slot again, or a later one if it is due by then. - No bursts. Slots missed while no leader ran collapse into one catch-up
tick for the latest of them. An app that must cover every slot loops over the
gap from
previoustoscheduled.
Determinism is not what converges
Section titled “Determinism is not what converges”Only the leader runs, so the clock, randomness, outbound responses and search answers cannot make replicas disagree. Runs are still bounded and transactional: a call or view gets 200 000 000 fuel, 64 MiB of memory and 2 s of wall clock, an action 10 s, and one run writes at most 10 000 keys and 1 MiB (Limits); a trap or an app error leaves an empty diff. Fuel pays for host work too, always: every host call, and each storage access, range batch, search and byte a call is handed or moves, costs fuel where the call happens, refused calls included (What host work costs), so a run cannot make the node read, copy or search without bound for little fuel, nor spend the fuel its host calls already owe.
Views and upgrades
Section titled “Views and upgrades”A view runs the same way against a replica’s applied state, with search
available; a write traps HostDenied (Reads). An
upgrade swaps the bundle; a named migration is refused
MigrationsNotSupported (Upgrades).
In calimero-node
Section titled “In calimero-node”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.
Reserved methods
Section titled “Reserved methods”Code: node::reserved_method, HOST_METHODS.
The node’s own commands (__upgrade, __blob, __blob_forget, __blob_revoke, __pipeline_start, __pipeline_cancel, __secret_set, __secret_clear) run only for a CallRequest::host request, which only the API module builds (for a route, or for a linked app’s pipeline start and cancel).
/intents and /views refuse a __ method (400 RESERVED_METHOD), and the leader refuses one named by an xcall or follow-up.
Outbound HTTPS
Section titled “Outbound HTTPS”Code: calimero-outbound.
Config::outboundcomes from--settings([outbound]).Node::outbound_forhands a client only tocall_local’s runs (not a read-only member’s) and to actions (NodeHttp), for a signed release that declares prefixes.- Identity is (package, pinned signer); approvals are
Org/Account::outbound_approvals[signer], set bySetOutboundApprovaland merged at apply bymerge_approval. - The request is made inside the propose lock on its own thread (
run_blocking); a leader-race re-run sends it again.
The egress switch
Section titled “The egress switch”SystemCmd::SetEgress { org, app?, egress }is ungated: an earlier release cannot decode it (a hard cutover).- It sets
Org::egress_offorAppRecord::egress_off, read throughSystemState::egress_off; the consent args aresystem::egress_args. outbound_forwraps every client incalimero_outbound::egress_gated, which reads the system state before each request and refusesEgressOff:.SetOutboundApprovalfor an org whose switch is off is409 EGRESS_OFF;api::refuse_egress_offanswers it before the passkey, also on the consent page’soutbound.- Turning egress on goes only through the consent page (
setEgress,consent_page::orgs::egress, a redegressOnattention); other principals get403 CONSENT_PAGE_REQUIRED(Principal::consent_page). GET /apps/{app}/egressanswersegress,offByandsummary(egress::NO_EGRESS);GET /orgs/{org}answersegressOff.
Engine and host
Section titled “Engine and host”Code: node/component.rs.
- One
WasmtimeEngineper node (Node::app_engine) caches compiled artifacts under<data_dir>/components, each with a MAC under a key derived from K_c. - At start the engine deletes another wasmtime’s or configuration’s artifacts.
Node::sweep_component_cacheruns everyCOMPONENT_CACHE_SWEEP_EVERY(1 h, the first an hour after start). It deletes artifacts of bundles no app uses and this node does not keep prepared, once unmodified for an hour.Node::prepared_forprepares a bundle once, single-flight.
Component state
Section titled “Component state”Code: component::ComponentState.
- Stored keys, generation prefix included, are hidden rows
rows::CKV, sealed and HMAC-keyed. - Each replica also keeps them in memory as
component::Kv, animbl::OrdMap, so a run’sStateViewis an O(1) clone with orderedrangescans. applywrites the next version sharing all it does not change, so a write while a run holds the previous one copies O(log n) nodes.restore(a restart, a snapshot install) reads it back from the rows.ComponentHead(last_ts_ms,last_id,install_ts_ms,timers, the idempotency rings) lives in the group’sHead.last_write_ms(ComponentHead::note_write) is the time of the newest call with a diff or files, or of an uploaded blob or file; it is left out at zero.
Node::call_component runs inside Group::propose_led, off the async workers (node::off_workers, which every run uses).
base_index is the app’s last entry (AppState::last_index), and answers carry the node’s receipt.
ABI gate
Section titled “ABI gate”Code: Node::abi_gate, abi_check.
- It reads the ABI of the bundle the group runs;
/intentstakesviewandconfirmfrom it, andAppRecord::confirm_methodsis always empty. - A
computeorcomputeResultmethod isWrongKindon/intentsand/viewsfor every caller, System included.
Unique ids
Section titled “Unique ids”- In
Node::next_id,id_termis the termpropose_led’s leadership check found;id_seqis a per-term counter continuing frommax(memory, AppState last_id). - A deposed leader’s entry never commits, or applies as a no-op through
base_index. - A leader restored into its old term catches up with its own log before its first proposal, so the counter continues past every entry it appended.
Time and timers
Section titled “Time and timers”Node::app_clock adds Config::clock_offset_ms; tests move it with Node::advance_clock (feature testing).
lib.rs polls every node::TIMER_POLL, and Node::tick_timers proposes each due slot as ComponentCmd::Tick.
Events
Section titled “Events”A component’s EventRecord carries its audience and caller.
The stream (api::local_events, or a peer’s internal/events) and a call’s answer check SystemState::receives when they send it.
- The stream judges on fresh system state, since an event made after a removal committed can reach a replica that has not applied it.
- A read-index round, applied here (
Node::sys_caught_up), covers the backlog and then each batch of up toapi::MAX_EVENT_BATCHlive events. - A replica that cannot catch up within
Config::read_waitends the stream; the subscriber resumes from its last id. - Every stream
gatelets open also re-judges its principal before each batch (api::still_admitted,Principal::admitted_on). A session token’s own expiry does not end a stream, as it is refreshed.
The usage book
Section titled “The usage book”Code: component::RunUsage, DayUsage.
componentInit,componentCallandcomponentTickoutcomes carryusage { fuel, wallMs, writes, bytesWritten, events }, measured by the leader (Outcome::from_host); aHostDeniedreplacement keeps fuel, wall time and writes.- Apply adds it to
ComponentHead::usage(aUsageBook) per UTC day of the entry’sts_ms; followers never measure, so every replica’s book is the same. - Pruning keeps
USAGE_DAYSback from the earlier of that day and the day after the newest held, so a far-future stamp never erases real days. - Not counted: timeouts (never logged), views, actions and compute runs.
- The API gives every figure as a decimal string, so no client loses precision on a 64-bit value.
- The API reads a book at its app group’s read index, so it counts every call acknowledged before the read (Reads).
What a component sees
Section titled “What a component sees”component::SysDirectoryanswers the org, owner and the caller’s role and teams;orgs-ofanswers only the app’s own organization, so an app learns nothing of the caller’s other organizations.- The host refuses event handlers and TEE runs to a component, and an xcall into a wasmer app is a dead letter.
Apply reads through the batch
Section titled “Apply reads through the batch”Code: component.rs: outgoing_in, action_in, replay_in.
A host row an entry’s apply reads comes from its StateTx, never the group’s committed state.
A catching-up replica applies many entries in one batch and must end where its leader, which applied them one at a time, did.
A row that cannot be read or decoded (decode_in, get_json) fails the batch (StateTx::fail) instead of reading as absent, so that replica stops on the entry rather than apply it differently.
Actions
Section titled “Actions”Code: component/action.rs.
abi_checklets an account or API key start one; the outcome carriesActionOut { id: a.<term>.<seq>.0 }.- Apply records it pending (
rows::CACT ‖ id,ActionsHead::pending, at mostMAX_PENDING_ACTIONS) with the starter’sCallerand the entry time. Node::run_actionsruns pending ones from the leader’s timer poll, at mostMAX_ACTION_WORKERSat once (theaction_slotssemaphore).attempt_actionruns on a blocking thread withkind = action,Budget::actionand a monotonic clock from the start.NodeActionservesview(Node::view, strong, withViewRequest::action) andcall(call_componentwith the key derived from the action’s key, method, arguments and occurrence andCallRequest::action); the action’s key in either is what alone reachesallow(action)methods, and only the node’s action runner sets it.- The end is
componentActionEnd; a timeout retries (action_retry,retry_after_ms) untilMAX_ATTEMPTS. ActionFailedis an event with anAccountsaudience.- An end another leader logged first changes nothing.
Outbound HTTP from calls
Section titled “Outbound HTTP from calls”Code: RunExtras::outbound, TimedHttp.
- Each response is awaited at most
CALL_FETCH_TIMEOUT, and never past the run’s deadline. - The exchange is recorded as
component::HttpRecordinOutcome::http, bodies cut to 64 KiB with their lengths.
A run’s deadline covers its host calls
Section titled “A run’s deadline covers its host calls”Wasmtime’s epoch deadline is checked only while guest code runs, so a run waiting in a host call would wait as long as the host does: a sync xcall up to SYNC_XCALL_WAIT, past a 2 s budget.
run_withand the action runner takedeadline = now + budget.wall_clockand hand it toHostCore::with_deadline.- Every host that waits honours it:
TimedHttp(actions’ outbound included),NodeXcall(wait_all) andNodeAction(wait). - A wait that reaches the deadline ends the run
Trap(Timeout, WALL_CLOCK_EXCEEDED), as an overrun in guest code does. - A
Timeoutis never logged (Outcome::is_retryable), and replicas apply only logged outcomes, so the deadline changes no entry and needs no gate.