Skip to content

The write path

A write is a call: POST /apps/{app}/intents { method, args, idempotencyKey?, confirm? }. This page follows one from the moment a node opens it to the answer the client gets back.

From the command line, the same call and a read of its write:

Terminal window
meroctl call -i my-kv set --args '{"key":"a","value":"1"}' --idempotency-key k1
# { "index": 42, "result": null, "events": [ { "kind": "Inserted", … } ], "receipt": { … } }
meroctl call -i my-kv get --args '{"key":"a"}' --view --min-index 42

meroctl (and every client library) attests the node, opens the sealed channel and sends POST /apps/{app}/intents inside it; a retry with the same --idempotency-key is answered from the log instead of running again.

A client may talk to any node of the cluster. Every node holds the system group, so it can authenticate the caller and find the app; if it is not the app’s leader, it forwards the call to a node that is. Clients reach a node in one of three ways, and all three end up in the same handlers:

  • A program (calimero-client, mero-js, calimero-client-py, meroctl) verifies the node’s attestation and seals every request (Networking & sealed channels).
  • A browser page on a configured origin (--origins) does the same through mero-js; those origins are both the passkey origins and the CORS origins.
  • A package’s own frontend at {label}.{apps-domain} signs in there and gets a session bound to that package (Packages & frontends).

The entry node judges the caller on system state at least as new as the system leader’s, so a credential revoked or a member removed through any node is refused here before the call reaches the app. The app’s leader is the only node that runs the WASM; the followers only apply what it appended. The answer carries a receipt signed by the entry node’s attested receipt key, so a client can later prove which node answered what at which log index.

  1. Open. The sealed envelope wraps the whole router: the node opens the request and routes the inner one afresh, so a sealed request meets exactly the handlers and limits a direct one would.
  2. Name the app. {app} may be the app id or its context id (hex(SHA-256(app_id))); the node maps one to the other. The app record is read from the system state, waiting briefly if it was just created through another node.
  3. Authenticate. The Authorization header holds a session token or an API key (cal_…). Either is judged on fresh system state: the node first catches its system replica up to the leader’s applied index, so a session revoked or a key deleted through another node is refused here at once.
  4. Gate. The caller must reach the app through its grants (Organizations, teams & access); a caller who does not gets 404 (or 401 if they sent no credential), so the app’s existence is not disclosed. An API key must not be read-only for a write, and must be scoped to this app and method if it is scoped at all. A session opened on a package’s frontend reaches only that package’s apps.
  5. Views called as calls. If the bundle’s ABI declares the method #[app::view], the call runs as a strong view instead: it reads the latest state, writes nothing, and may search.
  6. Confirm methods. If the app lists the method in confirmMethods, the call needs the account holder’s consent (below).
  7. Route. Node::call gives the call an idempotency key if it has none, then runs it locally if this node leads the app’s group, or forwards it to the leader over the peer sealed channel. A forward waits at most 5 seconds, then tries whoever leads now; the loop rides out elections for a few seconds before answering 503.
  8. Run and append on the leader (App execution, Replication). For a client’s call the leader reads the caller’s organization standing on fresh system state first: it waits until its own system replica has applied the index the entry node’s round named (CallRequest::sys_index), which covers every system write committed before the request arrived, so the call costs one read-index round, not two (One round per request).
  9. Answer. The node that took the request returns the result with a receipt signed by its attested receipt key.

An idempotency key makes a call safe to retry. The leader checks it inside the proposal, against the app’s applied state: if the same caller already ran a call with that key, the stored answer is replayed and nothing is appended.

  • Keys are scoped to the caller: account|key, app:{id}|key for an app’s own calls, public|key otherwise.
  • A client key is remembered for 24 hours by the log’s own clock (the leader’s timestamp in the entry). The newest 10 000 client records are kept whatever the clock says, so a leader whose clock jumps ahead cannot forget acknowledged calls; an app keeps at most 100 000 records of both kinds together (IDEMPOTENCY_MAX_RECORDS), oldest dropped first, at most 4096 per applied entry.
  • A call without a key gets a node key (node:…) before routing, remembered 10 minutes (the newest 1 000 always), so a retried forward of a call that did commit replays instead of running twice.
  • A call that hit a conflict records no key, so its rerun is a real run.

A method listed in the app’s confirmMethods (#[app::confirm]) runs only with a fresh passkey assertion over that exact call:

  1. The first intents request answers 412 CONFIRM_REQUIRED with a challenge id, the challenge, the relying party id and the account’s credential ids. The challenge is SHA-256("calimero.confirm.v1" | app | 0 | method | 0 | SHA-256(args) | nonce).
  2. The client has the person approve it with a passkey, and sends the same call again with confirm { challengeId, assertion }.
  3. The node checks the challenge was issued for this app, method, arguments and account, that it has not expired (5 minutes) or been used, and that the assertion is valid with user verification (a PIN or biometric, not just a touch).
  4. The assertion travels in the entry as consent, so the log records what was approved and by whom.

A challenge lives in the memory of the node that issued it, under an id that names that node; a retry that reaches another node takes it from the issuer (internal/challenge/take), so it is used once wherever it is answered. An API key can carry a person’s assertion only if it was created with allowConfirm; it cannot produce one. A confirm method called through /views is refused with 412: as a view its writes would be dropped, but its answer would have been handed back unconfirmed.

Outcome HTTP
The app returned 200 { index, result, events, receipt }, events being those the caller is in the audience of
The app returned an error 422 APP_ERROR with details.{code, fields}
The run trapped (panic, out of fuel, unknown method) 422 TRAP with details.{kind, detail}
The arguments pass 512 KiB 413 ARGS_TOO_LARGE, before anything is proposed
A read-only team member calls a method that is not a view 403, before it runs
The call kept racing leader changes 503; retry with the same idempotency key
No leader could be reached 503 UNAVAILABLE
A system write (account, passkey, org, node) did not commit in 10 s 503 UNAVAILABLE naming the system group’s leader, voters, learners and lagging members; it may still apply
The caller does not reach the app 404 (or 401 without a credential)

The index is the entry’s log index. A client that then reads from a replica can pass it as minIndex to read its own write (Reads).

Creating an organization, adding a member, installing a package or changing an app’s access are not app calls: the API builds a SystemCmd and appends it to the system group, whose state machine checks the actor’s authority when it applies.

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.

Group::propose takes no leadership round before a call’s append, so a deposed leader may run a call on stale state; its entry never commits, or commits as a no-op (base_index ≠ the app’s last entry, AppState::last_index: conflict, no idempotency record), and Node::call re-runs it instead of failing. The base is the app’s last entry, never the log’s applied index, which counts blank and membership entries too: with it the first call after every election conflicted once. Replies without an append (idempotent replays) are confirmed first. The component is prepared from the bundle read before the lock, so the call also answers a conflict when the state names another bundle by then (an upgrade applied in between; call_component compares AppState::bundle).

A call or read forwarded to an app’s leader waits at most FORWARD_TIMEOUT (5 s, peer_forward), then retries at whoever leads now; a frozen leader would otherwise hold a write for the 30 s HTTP timeout. Calls without a client key get a node key (node:…, kept 10 min) first, so a retry replays a call that did commit. System-log forwards keep the long timeout: some system commands are not idempotent yet.

Code: node::off_workers.

A logged WASM run (call, timer tick, init, a compute run’s result method) happens inside the group’s proposal lock, so it cannot move to spawn_blocking; it goes through block_in_place, which hands the worker’s other tasks (Raft heartbeats, the system group, HTTP) to another worker meanwhile.

(C2; calimero_log::Group::propose_led_staged, LoggedRun.)

Each of those proposals is staged. Its read step, under the applied state’s read lock, makes the checks, takes the unique ids and an owned LoggedRun (AppMachine::view, an O(1) imbl clone, the blobs, runs provider, secrets, base_index); its run step, with the lock released, runs the guest, pushes its files and builds the entry. The proposal lock is held throughout, so calls on one app still take turns and each builds on the one before (no self-conflict). An entry that commits while a run runs (a barrier, a membership change) now applies at once and the app’s reads go on, where they waited for the whole run before (a reader queued behind the waiting apply); the run’s entry then fails its base_index check and Node::call runs it again, its synchronous xcalls replayed under their keys.

(calimero_log::Group::propose_pipelined, Machine::fork, CallEntry::base_digest, Feature::PipelinedCalls.)

Taking turns from the read step through the commit held one app to about one call per commit round (~2 ms on 3 nodes): the run, the leader’s synced append, the round to a follower and the apply ran one after another, each a fraction of the time. Once the logged cluster version brings pipelinedCalls, a call’s proposal lock is released when its entry is handed to Raft, not when it commits. The next call builds on a copy of the app’s machine (AppMachine::fork: its storage and blobs are persistent maps, so the copy shares them until written) with the calls in flight applied to it ahead of the log, over the group’s rows (GroupState with an overlay of the rows those calls wrote, dropped as the group applies them). So a call’s run overlaps the commits before it, and their entries reach the followers and the disk together.

The rule that keeps this safe: a call built ahead of the log carries the digest of the state it ran on (baseDigest, the state digest every replica keeps), and apply refuses it (conflict) on a state of any other digest. Whatever goes otherwise than the leader predicted (an entry from elsewhere lands between, an entry takes another index than predicted, one is refused, the leader changes), the state the next call applies on is not the one it ran on, so that call is refused, and so is every one after it; Node::call runs each again. No call is applied on a state it did not run on. A call built ahead of the log reaches nothing outside its app: a run that would call another app synchronously or send an outbound request is stopped at that point, its build answers a reply, and the call is built again on the applied state once the calls in flight have their answers (calimero_log::Basis::ahead, RunExtras::ahead). Those effects are not undone with a refused entry, so they are made only from a state the log holds. At most 32 calls are in flight on an app (calimero_log::MAX_PIPELINE_DEPTH).

A reply built ahead of the log (an idempotent replay, a refusal) may rest on calls not committed yet: it waits for them, then builds again on the applied state. Timers, actions, uploads and every other entry still build on the applied state, after the calls in flight commit. Regressions (crates/log/tests/pipeline.rs): pipelined_increments_lose_none, an_entry_from_elsewhere_between_pipelined_ones_loses_no_increment (without the digest check, 26 of 300 increments were lost).