arXiv:2611.24649cs.PLNov 2026

Manuscript Offprint

arXiv:2611.24649

A Principled Approach to Concurrency, Nondeterminism, and Asynchrony in Choreographies

Xueying Qin, Marco Peressotti, Fabrizio Montesi

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

XUEYING QIN, University of Southern Denmark, Denmark

MARCO PERESSOTTI, University of Southern Denmark, Denmark

FABRIZIO MONTESI, University of Southern Denmark, Denmark

Choreographic programming (CP) describes a distributed system as a global program and compiles it into communicating network programs via endpoint projection (EPP). Asynchrony captures the independent progress of communicating processes, while nondeterminism captures the range of behaviours that can arise from their interactions. However, the integration of both features into a theory of CP is absent.

We present Nyarlathotep, the first asynchronous and nondeterministic CP framework. We define its operational semantics of choreographies and networks using labelled transition systems. Besides asynchrony and choreographic nondeterminism, Nyarlathotep supports expressive features including general branching, out-of-order execution, and general recursion with parameterised procedures that processes can enter independently. We prove EPP sound and complete, establishing strong behavioural equivalence between the semantics of choreographies and their projected networks. We prove that projected networks are communication-safe and deadlock-free. We mechanised all our results in Lean 4.

CCS Concepts: • Computing methodologies → Concurrent programming languages; Distributed programming languages; • Theory of computation → Operational semantics; Program verification.

Additional Key Words and Phrases: Concurrency theory, Choreographies, Mechanised formalisation

1 Introduction

Traditionally, concurrent and distributed systems are programmed from a local perspective. Developers write programs for individual endpoints, and the overall behaviour of the system emerges from interactions amongst those endpoints. With such an approach, concurrent and distributed systems are prone to critical errors including deadlocks and mismatched communications, and the overall system behaviours are hard to reason about.

Choreographic programming (CP) is an emerging correct-by-construction programming paradigm, which addresses these issues by enabling developers to program concurrent and distributed systems from a global perspective [Montesi 2013, 2023b]. A choreography is a global program that specifies the intended computation and the interactions among endpoints, which are processes. Endpoint projection (EPP) automatically compiles a choreography into a network of endpoint programs that follow the behaviours specified by the choreography. The correctness of EPP establishes behavioural equivalence between choreographies and their projected programs. Consequently, the safety and liveness properties characterised by a choreography are preserved in networks. In practice, there are many stand-alone and library-level implementations of CP, such as Choral [Giallorenzo et al. 2024], Klor [Lugović and Jongmans 2024], Chorex [Wiersdorf and Greenman 2025], HasChor [Shen et al. 2023], MultiChor [Bates et al. 2025], and UniChorn [Chakraborty 2025].

Theories of CP have been rapidly developed over the past few years, and some have been accompanied by substantial mechanisation efforts, opening up opportunities to build certified compiler frameworks for programming concurrent and distributed systems. However, an asynchronous CP framework with choreographic nondeterminism is still missing.

Asynchrony and nondeterminism are each difficult to model. The textbook semantics for nondeterministic choreographic choice is wrong [Montesi 2023a; Qin et al. 2026]. In the multiparty session

Authors' Contact Information: Xueying Qin, xyqin@imada.sdu.dk, University of Southern Denmark, Odense, Denmark; Marco Peressotti, peressotti@imada.sdu.dk, University of Southern Denmark, Odense, Denmark; Fabrizio Montesi, fmontesi@imada.sdu.dk, University of Southern Denmark, Odense, Denmark.

types (MPST) community, researchers have found flaws in subject-reduction proofs [Castro-Perez et al. 2021; Scalas and Yoshida 2019; Tirore et al. 2025] and shown that a previously proposed asynchronous subtyping relation is undecidable [Bravetti et al. 2017]. Work on mixed choice highlights the difficulty of coordinating participants in the presence of nondeterminism, under both synchronous and asynchronous communication [Bocchi et al. 2026; Peters and Yoshida 2024].

However, an asynchronous nondeterministic CP framework is necessary for expressing complex system behaviours. In example 1.1, we use a recursive choreographic procedure definition to model a reusable lock. With asynchrony and nondeterminism, two processes p1p_1 and p2p_2 repeatedly compete to update a shared inventory at s, which manages the lock. s replies with OK to the first request it receives, regardless of the order in which the requests were sent. After sending OK, s can take a local snapshot of the inventory while the reply is still queued for the winner. The winner works with s in the procedure W, where s can use the snapshot to restore the inventory if an update fails. The completion of W serves as an implicit release. The notation C1+sC2C_1 +_s C_2 denotes a nondeterministic choreographic choice between C1C_1 and C2C_2, which s resolves by taking a step in one of the branches.

Example 1.1 (A Deadlock-Free Reusable Lock).

X(s,p1,p2)=(p1→s[REQ];s→p1[OK];s.backup:=snapshot(inventory));W(p1,s);p2→s[REQ];s→p2[KO]+sp2→s[REQ];s→p2[OK];s.backup:=snapshot(inventory);W(p2,s);p1→s[REQ];s→p1[KO]);X(s,p1,p2)\begin{aligned}X(s,p_{1},p_{2})&=(p_{1}\rightarrow s[\mathtt{REQ}];s\rightarrow p_{1}[\mathtt{OK}];s.\mathtt{backup}:=\mathtt{snapshot}(\mathtt{inventory}));\\&\quad W(p_{1},s);p_{2}\rightarrow s[\mathtt{REQ}];s\rightarrow p_{2}[\mathtt{KO}]\\&+_{s}p_{2}\rightarrow s[\mathtt{REQ}];s\rightarrow p_{2}[\mathtt{OK}];s.\mathtt{backup}:=\mathtt{snapshot}(\mathtt{inventory});\\&\quad W(p_{2},s);p_{1}\rightarrow s[\mathtt{REQ}];s\rightarrow p_{1}[\mathtt{KO}]);X(s,p_{1},p_{2})\end{aligned}

Endpoint projection produces process procedure definitions for the reusable lock, shown in example 1.2, each specifying the local behaviour of one of the participating processes. Each process can enter its procedure call independently. Repeatedly, p1p_1 and p2p_2 send REQ to s (s⊕REQs \oplus \mathtt{REQ}), each participating in W only upon receiving OK. Branches labelled by OK and KO are merged into a branching term that waits to receive a selection label from s. The first request that s receives resolves the nondeterministic choice (+). If both requests are queued, either can win. After sending OK, s can take a local snapshot of the inventory while the reply is still queued. It then executes its part of W before receiving and rejecting the other request with KO and repeating the procedure. The (§) notation here is the sequential composition of process terms, formally defined in section 4.2.1.

Example 1.2 (A Reusable Lock as Process Procedure Definitions). The two process procedure definitions for clients p1p_1 and p2p_2 are: X2(s,p2)=s⊕REQX_2(s,p_2) = s \oplus \mathtt{REQ}; s&{OK:W1(s),KO:∅}=∘(X2(s,p2))s \& \{OK : W_1(s), \text{KO} : \emptyset\} \stackrel{\circ}{=} (X_2(s,p_2)), and X3(s,p1)=s⊕REQX_3(s,p_1) = s \oplus \mathtt{REQ}; s&{KO:∅,OK:W1(s)}=∘(X3(s,p1))s \& \{\text{KO} : \emptyset, \text{OK} : W_1(s)\} \stackrel{\circ}{=} (X_3(s,p_1)). The definition for the server s is:

X1(p1,p2)=(p1&{REQ:p1⊕OK;backup:=snapshot(inventory);W2(p1);p2&{REQ:p2⊕KO})+p2&{REQ:p2⊕OK;backup:=snapshot(inventory);W2(p2);p1&{REQ:p1⊕KO})};X1(p1,p2)\begin{aligned}X_{1}(p_{1},p_{2})&=(p_{1}\&\{\mathtt{REQ}:p_{1}\oplus\mathtt{OK};\mathtt{backup}:=\mathtt{snapshot}(\mathtt{inventory});\\&\quad W_{2}(p_{1});p_{2}\&\{\mathtt{REQ}:p_{2}\oplus\mathtt{KO}\})\\&+p_{2}\&\{\mathtt{REQ}:p_{2}\oplus\mathtt{OK};\mathtt{backup}:=\mathtt{snapshot}(\mathtt{inventory});\\&\quad W_{2}(p_{2});p_{1}\&\{\mathtt{REQ}:p_{1}\oplus\mathtt{KO}\})\};X_{1}(p_{1},p_{2})\end{aligned}

We have studied existing theories of CP that could serve as a starting point to developing a theory expressive enough to express examples like example 1.1. We see two possible expressive and machine-checked candidates, with different approaches to concurrency. The state-of-the-art functional choreographic language λQC\lambda_{QC} [Samuelson et al. 2025] extends Pirouette [Hirsch and Garg 2022], supporting features such as process polymorphism and higher-order functions. However, it only supports synchronous communication. On top of that, invoking a function application requires all processes to synchronise, even those uninvolved in the call. This design not only conflicts with the concurrent semantics of distributed systems but also poses substantial obstacles to adding choreographic nondeterminism. Introducing +s+_{s} under λQC\lambda_{QC}'s global application rule leaves the example lock unprojectable: p1p_{1} and p2p_{2} cannot enter the procedure calls independently, a step for the losing process to joining the procedure need to be added, which causes two branches unmergeable. Following the textbook approach [Montesi 2023b], Mech [Qin et al. 2026] does not require global synchronisation and correctly models the semantics of nondeterministic choreographic choice. But its synchronous communication produces cumbersome nondeterministic semantics and limits the behaviours it can express (cf. section 5). Mech's approach to concurrency and algebraic characterisations for choreographies still make it a good starting point for extending CP.

In this paper we present Nyarlathotep, a semantic foundation for asynchronous and nondeterministic choreographies, which also features out-of-order execution, general branching, and general recursion parameterised over processes that allows processes to enter calls independently. Our paper makes the following contributions:

  • We present the first formalism for asynchronous and nondeterministic choreographies. We design new operational semantics for choreographies and networks to capture the interplay amongst asynchrony, nondeterminism, and out-of-order execution.
  • Nyarlathotep's operational semantics has a new locality property: unlike in Mech, where synchronous transitions can involve multiple processes, in Nyarlathotep each transition concerns only one active process, both in choreographies and networks. This property enables more structured and compositional reasoning about the correctness of EPP.
  • We prove the correctness of EPP, which yields networks behaviourally equivalent to their source choreographies and guarantees communication safety and deadlock freedom.
  • We mechanise all results in Lean 4, providing a machine-checked formal framework that enables the future development of a certified compiler for CP. Benefitting from the locality property, the size of the mechanisation of Nyarlathotep is only around half of Mech's.

References (27)