From Orchestration to Choreography through Contract Automata

We study the relations between a contract automata and an interaction model. In the former model, distributed services are abstracted away as automata - oblivious of their partners - that coordinate with each other through an orchestrator. The interaction model relies on channel-based asynchronous communication and choreography to coordinate distributed services. We define a notion of strong agreement on the contract model, exhibit a natural mapping from the contract model to the interaction model, and give conditions to ensure that strong agreement corresponds to well-formed choreography.


Introduction
We investigate the relations between two models of distributed coordination: contract automata [3] and communicating machines [4].
The former model has been recently introduced as a contract-based coordination framework where contracts specify the expected behaviour of distributed components oblivious of their communicating partners. The underlying coordination mechanism of contract automata is orchestration. In fact, such model envisages components capable of communicating messages on some ports according to an automaton specifying the component's behavioural contract. These messages have to be thought of as directed to an orchestrator synthesised out of the components; the orchestrator directs the interactions in such a way that only executions that "are in agreement" happen. In this way, it is possible to transfer the approach of [2,1] to contract automata so to identify misbehaviour of components that do not realise their contract.
We illustrate this with the following simple example. Alice is willing to lend her aeroplane toy, Bob offers a bike toy in order to play with an aeroplane toy, while Carol wants to play with an aeroplane or a bike toy. Let a and b denote respectively the actions of offering an aeroplane or a bike toy and, dually, a and b denote the corresponding request actions. The contract automata for Alice, Bob, and Carol correspond to the following regular expressions, used here for conciseness: If Alice exchanges her toy with Bob, then all contracts are fulfilled. Instead, if not coordinated, Alice, Bob, and Carol may share their toys in a way that does not fulfill their contracts. In fact, Alice can give her aeroplane to Bob or Carol, while Carol can receive the bike from Alice or Bob, therefore if Alice gives her aeroplane to Carol the contracts of Alice and Carol are fulfilled while Bob's contract is not. In the model of contract automaton the coordinator acts as the mam of the three kids who takes their desires and suggests how to satisfy them (and reproaches those who do not act according to their declared contract).
Communicating machines -the other model we consider here -were introduced with the aim of studying distributed communication protocols and ensure the correctness of distributed components again formalised as automata. But -unlike contract automata -communicating machines do not require an orchestrator since they interact directly with each other through (FIFO) buffers. In fact, a relation between communicating and distributed choreographies has been recently proved in [8].
We show that these models -invented to address different problems and having different coordination mechanisms -are related. For this purpose, we introduce the notion of strong agreement, which requires the fulfillment of all offers and requests. Strong agreement differs from previous notions of agreements for contract automata (cf. Section 3) and enables us to introduce strongly safe contract automata, that is those automata accepting only computations that are in strong agreement. Strong agreement and safety are key to establish a correspondence from contract automata to communicating machines.
Indeed if a contract automaton enjoys strong safety (and it is well-behaved on branching constructs) then the corresponding communicating machines are a well-formed choreography.
Structure of the paper. We recall contract automata and communicating finite-state machines in Section 2. The new notion of agreement on contract automata is in Section 3. The translation of contract automata into communicating machines is given in Section 4 where we also prove our main theorem. In Section 5 we discuss possible extensions of our results to other notions of agreement for contract automata and semantics for communicating machines. Finally, concluding remark are in Section 6.

Background
This section summarises the automata models we use in the paper. Both models envisage distributed computations as enacted by components that interact by exchanging messages. As we will see, in both cases components, abstracted away as automata, yield systems also formalised as automata.

Contract Automata
Before recalling contract automata (introduced in [3]), we fix our notations and preliminary definitions. Given a set X , as usual, X * def = n≥0 X n is the set of finite words on X (ε is the empty word, ww ′ is the concatenation of words w, w ′ ∈ X * , w (i) denotes the i-th symbol of w, and |w| is the length of w); write x n for the word obtained by n concatenations of x ∈ X and x * for a finite and arbitrarily long repetition of x ∈ X . It will also be useful to consider X n as a set of tuples and let x to range over it. Sometimes, overloading notation (and terminology), we confound tuples on X with words on X (e.g., if w ∈ X n , then | w| = n is the length of w and w (i) denotes the i-th element of w).

Transitions of contract automata will be labelled with elements in the set
• requests of components will be built out of R while their offers will be built out of O, • ∈ R ∪ O is a distinguished label to represent components that stay idle.
We let a, b, c, . . . range over L and fix an involution · : L → L such that A contract automaton (cf. Def. 2) represents the behaviour of a set of participants (possibly made of a single participant) capable of performing some actions; more precisely, as formalised in Def. 1, the actions of a contract automaton allow them to " advertise" offers, "make" requests, or "handshake" on simultaneous offer/request matches.
We define the relation ⊲⊳⊆ L * × L * as the symmetric closure of • a 1 and a 2 are actions of the same length We write a 1 ⊲⊳ b a 2 when there is b ∈ R ∪ O such that a 1 and a 2 are actions on b and a 1 ⊲⊳ a 2 .
Fact 1 ⊲⊳ is an equivalence relation on L * . Definition 2 (Contract Automata) Let Q (ranged over by q 1 , q 2 , . . .) be a finite set of states. A contract automaton of rank n is a (finite-state) automaton A = Q n , q 0 , L n , T, F , where • q 0 ∈ Q n is the initial state • F ⊆ Q n is the set of accepting states , the i-th participant stays idle) and -a is either a request, or an offer, or else a match action A principal is a contract automaton A of rank 1 such that, for any two transitions (q 1 , a 1 , q ′ 1 ), (q 2 , a 2 , q ′ 2 ) in A , it is not the case that a 1 ⊲⊳ a 2 .

Example 1
The principals of Alice, Bob, and Carol in Section 1 are given below

Automaton of Alice Automaton of Bob Automaton of Carol
Given a contract automaton A = Q n , q 0 , L n , T, F of rank n, usual definitions and constructions of finite-state automata apply. In particular, where → * is the reflexive and transitive closure of →. As usual, s 1 − →s m+1 (for some s 2 , . . . , s m ) and s → iff for no s ′ it is the case that s → s ′ .
We now borrow from [3] the product operation of contract automata. Given a finite set of contract automata, this operation basically yields the contract automaton that interleaves all their transitions while forcing synchronisations when two contract automata are in states ready to "handshake" (i.e. , they can fire complementary request/offer actions).

Definition 3 (Product) Let
The product of A 1 , . . . , A h , denoted as i∈{1,...,h} A i , is the contract automaton Q n , q 0 , L n , T, F of rank n = n 1 + . . . + n h where: or c (i) = a i , c (l) = n l for each l = i ∈ {1, . . . , h}, and q ′ = q 1 . . . q i−1 q ′ i q i+1 . . . q h when ( q i , a i , q ′ i ) ∈ T i and for all j = i and ( q j , a j , q ′ j ) ∈ T j it does not hold that a i ⊲⊳ a j .

Example 2
The contract automaton below is the product of the contract automata in Example 1.
Notice that from the states q 0 and q 6 (where participants can handshake) only match actions depart; offer and request actions are not included in the product.

Remark 1
Notice that the product in Def. 3 is not associative; an alternative (but more complex) definition of associative product can be given by "breaking" existing matches when composing automata [3].
Hereafter, we assume that all contract automata of rank n > 1 are the product of n principals. Also, we consider deterministic contract automata only. Such assumptions could be relaxed at the cost of adding some technical intricacies.

Communicating Machines
Communicating machines [4] are a simple automata-model introduced to specify and analyse systems made of agents interacting via asynchronous message passing. We adapt the original definitions and notation from [4] and [7] to our needs; in particular, the only relevant difference with the original model is that we have to add the set of final states. Let P be a finite set of participants (ranged over by p, q, r, s, etc.) and C def = {pq p, q ∈ P and p = q} be the set of channels.

Remark 2
The set P can be thought of as the set of integers {1, . . . , n} (and likewise for contract automata). However, we adopt a different notation to make the translation from contract automata to communicating machines clearer.
The set of actions is Act def = C × (R ∪ O) and it is ranged over by ℓ; we abbreviate (sr, a) with a@sr when a ∈ O (representing the sending of a from machine s to r) and, similarly, we shorten (sr, a) with a@sr when a ∈ R (representing the reception of a by r).

Definition 4 (CFSM) A communicating finite-state machine is an automaton
where Q is a finite set of states, q 0 ∈ Q is the initial state, δ ⊆ Q × Act × Q is a set of transitions, and F ⊆ Q is the set of final states. We say that M is deterministic iff for all states q ∈ Q and all actions ℓ ∈ Act, if (q, ℓ, q ′ ), (q, ℓ, q ′′ ) ∈ δ then q ′ = q ′′ . Also, we write L (M) ⊆ Act * for the language on Act accepted by the automaton corresponding to machine M.
We will consider only deterministic CFSMs. The notion of deterministic CFSMs adopted here differs from the standard one which requires that, for any state q, if (q, a@sr, q ′ ) ∈ δ and (q, b@sr, q ′′ ) ∈ δ then a = b and q ′ = q ′′ (see e.g., [7]). The reason for the definition is to reflect the semantics of contract automata.
The communication model of CFSMs (cf. Definitions 5 and 6) is based on (unbounded) FIFO buffers -the channels in C -used by participants to exchange messages. To spare another syntactic category and cumbersome definitions, we draw the messages appearing in the buffers of CFSMs from the set of requests R. Recall that the set of participants P is finite.

Definition 5 (Communicating systems) Given a CFSM M
Hereafter, we fix a machine M p = (Q p , q 0p , R ∪ O, δ p , F p ) for each participant p ∈P and let S = (M p ) p∈P be the corresponding system.
We write s − → s ′ for ∃ℓ : s ℓ − →s ′ and denote with → * the reflexive and transitive closure of →. The set of reachable configurations of S is RS(S) = {s s 0 → * s}. A sequence of transitions is k-bounded if no channel of any intermediate configuration on the sequence contains more than k messages.
Condition (1) in Def. 6 puts the content a on a channel sr, while (2) gets the content a from sr.

Notational Synopsis
To avoid their continuous repetition, through the paper we assume fixed a contract automaton A = Q n , q 0 , L n , T, F of rank n.
For readability we summarise the notations introduced so far in the following table.
X * set of finite words on a set X ; ε is the empty word x concatenated n-times (resp. arbitrarily many) with itself contract automata of rank n P set of participants (ranged over by p, q, i, j,A, B,C, etc.) C set of channels (ranged over by pq) M p communicating machine of participant p S a system of communicating machines Finally, we assume that the states of any automaton/machine are build out of a universe Q (of states).

Enforcing Agreement
This section introduces a new notion of agreement on contract automata -called strong agreement -that elaborates the notions of agreement and weak agreement introduced in [3]. The three notions differ on the conditions for the fulfillment of an interaction between different principals. Briefly, an agreement exists if all the requests, but not necessarily all the offers, are satisfied synchronously. Intuitively, this means that the orchestrator "simultaneously" guarantees two participants that their complementary actions are matched. Instead, a weak agreement exists when request actions can be performed "on credit". In other words, a computation yelds weak agreement when the fulfillment of a request action can happen after the action has been taken. Intuitively, this corresponds to an asynchronous communication admitting actions taken on credit provided that obligations will be honored later on.
Here, we focus on strong agreement, which strengthens the previous notion of agreement by requiring the fulfillment of all offers and requests in a synchronous way. In Section 4 we will show how this condition corresponds to interactions between communicating machines.

Definition 7 (Strong Agreement and Safety) A strong agreement on L is a finite (non-empty) sequence of match actions. We let Z to denote the set of all strong agreements on L.
A contract automaton A is strongly safe if L (A ) ⊆ Z, otherwise it is strongly unsafe. We say that A admits strong agreement when L (A ) ∩ Z = / 0.
Note that ε does not belong to Z; the reason is that ε would not be an interesting agreement because it does not require any interaction (neither with the controller nor between principals). For this we require that the initial states of contract automata are not accepting states. We show how to generate a strongly safe composition of contracts with an approach borrowed by the supervisory control theory for discrete event systems [6]. In this theory, discrete event systems are basically automata where accepting states represent the successful termination of a few tasks while forbidden states are those that should not be traversed in "good" computations. The purpose is then to synthesize a controller that enforces this property. The supervisory control theory distinguishes between controllable events (those events that the controller can disable) and uncontrollable events (those that are always enabled). Moreover, the theory partitions events in observable and unobservable; the latter being a subset of uncontrollable events. It is known that if all events are observable then a maximally permissive controller exists that never blocks a good computation [6].
Since the behaviors that we want to enforce in A are exactly those traces labeled by words in Z ∩ L (A ), we specialise the notions of supervisory control theory by defining • observable events to be all offer, request, and match actions; • forbidden events to be non-match actions.

Definition 8 (Controller) A (strong) controller of A is a contract automaton KS
Note that the most permissive controller is unique up-to language equivalence.

Example 3
The MPC of the contract automaton in Example 2 consists of the states q 0 , q 1 , q 3 , and q 4 with transitions ( q 0 , (a, a, ),

Proposition 1 If KS
is the intersection of two regular languages and all actions are controllable, there exists a contract automaton KS ′ A accepting it (cf. [6]). By definition, KS ′ A is a controller of A strictly containing L (KS A ), contradicting the hypothesis that L (KS A ) is the most permissive controller.
A state q of a contract automaton A is called redundant if, and only if, from q no accepting state of A can be reached.

is a match transition}, F is the sub-automaton of A consisting of the match transitions of A only.
Proof. By construction, the transitions of KS A are a subset of the transitions of A , hence L (KS A ) ⊆ Z ∩ L (A ). Therefore KS A is a controller of A and we have just to prove that L (KS A ) = Z ∩ L (A ). We proceed by contradiction.
Let w ∈ (Z ∩ L (A )) \ L (KS A ). Since Z does not contain the empty string we have w = ε and there must be a transition t = ( q, a, q ′ ) not in KS A in the accepting path of w (which is unique since we consider deterministic contract automata only), otherwise w ∈ L (KS A ). We know that a is a match action because w ∈ Z, and q, q ′ are not redundant states of A because the transition belongs to an accepting path. Hence there must be t ∈ KS A , since by construction match transitions between non-redundant states are in KS A .

Example 4
The MPC of Example 3 is obtained from the CA in Example 2 by applying the construction of Lemma 2.
The controlled system of a contract automaton A identifies the match transitions of A and those transitions that lead "outside" of the controller; for this we use a distinguished state ⊥ ∈ Q n (for any n) in the following definition.

Definition 9 (Controlled system) Let KS
The controlled system of A under KS A is defined as the automaton ( q 1 , ( , , a), q 2 ), ( q 0 , (a, , a), q 6 ) to the MPC of Example 3.

Example 5 The controlled system of the CA in Example 2 is obtained by adding the transitions
It is worth remarking that the transitions reaching ⊥ in the controlled system of A identify the start of the computations in A which lead to violations of strong agreement.
In the next definition, we introduce a notion of strong liability, to single out the principals that are potentially responsible of the divergence from the expected behaviour.
Definition 10 (Strong Liability) Given a controlled system KS A /A , the set of liable participants on a trace w ∈ L (A ) is given by: We let TLiable(KS A /A ) to denote the set of transitions of A that make principals liable.
Note that the transition labelled by a in Definition 10 is the first which diverges from the expected path (since, by Definition 9, state ⊥ does not have outgoing transitions). Indeed a liable index identifies a principal that fires an action taking the computation away from agreements.

Example 6
The liable indexes of the contract automaton in Example 2 are 1 and 3, corresponding to Alice and Carol respectively; the transitions that make them liable are respectively q 0 , (a, , a), q 6 and q 1 , ( , , a), q 2 . The former liable transition is a match that leads to a non-match transition.
Note that labels allow us to track participants firing actions so to find (the indexes of) the liable principals. Our aim is to restrict the behaviour of principals so that they follow only the traces of the automaton which lead to strong agreement, while avoiding the others.

From Contract Automata to Communicating Machines
The translation of a principal into a communicating machine is conceptually straightforward. Indeed, the translation just yields a machine isomorphic to a principal in the composed contract automaton; the only difference are the labels. To account for the "openness" nature of contract automata -where principals can fire transitions not matched by other principals -in Definition 11 below we use the '−' symbol representing a special ("anonymous") participant distinguished by the participants corresponding to the principals and playing the role of the environment. For this reason, we will assume from now on that actions in Act are built on C ∪ {−}.
Definition 11 (Translation) The translation a p ∈ Act of an action a on L n respect to a participant p (with 1 ≤ p ≤ n) is defined as: a@ij if a is a match action and i and j are such that a (i) ∈ O and a ( j) ∈ R and p = i a@ij if a is a match action and i and j are such that a (i) ∈ O and a ( j) ∈ R and p = j a@i− if a is an offer action and i is such that a (i) ∈ O and p = i a@−j if a is a request action and j is such that a ( j) ∈ R and p = j ε otherwise The translation of A to a CFSM is given by the map ..,n} the communicating system obtained by translating the contract automaton A .
Given ϕ ∈ L n * , we define The product is the contract automaton below with initial state q 0 = q 01 , q 02 , q 03 a, ) ( , , c) By applying Lemma 2 on the product automaton we obtain the MPC: We introduce the 1-buffer semantics of communicating machines, recall that w is the vector of buffers. Intuitively, this semantics forbids a machine to send a message to one of its partners if there is a non empty channel in the system.

Definition 12 (1-buffer, deadlock,convergent) A configuration ( q; w) of a CS S = (M p ) p∈P is stable if
and only if w = ε, while is final if it is stable and q ∈ (F p ) p∈P . The 1-buffer semantics of S is given by the relation where → is the relation introduced in Definition 6 and We say that the system S is convergent if and only if for every reachable configuration ( q; w) it is possible to reach a final configuration in the 1-buffer semantics.

Moreover a configuration ( q; w) is a deadlock if and only if is not final and ( q; w) ։
Note that if a system is convergent than it is deadlock-free. The 1-buffer semantics above is instrumental to the relation we establish between strong agreement of contract automata and convergence of CFMSs.

Remark 3
Note that by considering only finite traces, we rule out all the unfair traces. For example, consider the following strongly safe CA: If the first and second participants could execute the transition ( q 0 , (a, a, ), q 0 ) infinitely often then the third participant would be prevented from reading the message b. This behaviour is ruled out by considering only finite traces. Indeed all the possible traces generated by the automaton above are described by the regular expression (a, a, )  *  (b, , b), where the third participant will eventually reach its goal.
We define snd( a) def = i when a is a match action or an offer action such that a (i) ∈ O and, similarly, rcv( a) def = j when a is a request or a match and j is such that a ( j) ∈ R.

Property 3 Let S(KS A ) be a CS obtained by Definition 11, and s 0 be its initial configuration. Then for
all f such that s 0 f ։ there is a strong agreement ϕ such that f = ϕ or f = ϕ a@ij for some a, i, j. Proof. The proof follows trivially by observing that KS A contains only match transitions and that the 1-buffer semantics does not allow other behaviours for the CS.
Before providing the main results, we introduce a notion of well-formedness of contract automata. We require that an output action of a participant in a particular state is independent from the states of the other participants in the system.  ( q 1 , (a, a, ), q i ) ∈ T KS . The next theorem characterizes the relations between a CA and the corresponding CS. It states that the CS is capable of performing all the moves of the controller of the CA, while the CA is capable of performing those traces of the CS that are in strong agreement. Moreover, if a CA has the branching condition, the runs of the CS leading to a deadlock configuration correspond in CA to runs traversing liable transitions, and likewise when the CS reaches a non-deadlock configuration which does not reach a final configuration. 1 with a match action on a where principal i makes the offer and principal j makes the request on a. Let q 0(i) and q 0( j) be the initial states of participants i and j in S(KS A ). By Definition 11, we have for some q 1 and q 2 that ( q 0(i) , a@ij, q 1(i) ) and ( q 0( j) , a@ij, q 2(i) ) are transitions of participants i and j, respectively. We have s 2 a@ij ։ a@ij ։ s ′ 2 since after the first transition participant j remains in its initial state. 2. The proof is again by induction. Assume s 2 a ։ s ′ 2 , where a is a match on a which involves (the principals i and j corresponding to) participants i and j. As before let i perform the offer and j the request. By Definition 3 (of product), we have that there is a transition ( q 0 , a, q) in A from its initial state.

Theorem 1 Let S(KS
When |ϕ| > 1, we have s 2 ϕ ։ s ′′ 2 a ։ s ′ 2 and there is w ′ ∈ (L n ) * such that (by the induction hypothesis) Reasoning as in the base case, we conclude that A has a transition of the form ( q ′ , a, q ′′ ).
3. Let s ′ 2 = ( q; w) be the deadlock configuration reached from s 2 with f .
We distinguish two cases: • if w = ε (namely some buffer in w is not empty) thenφ is not a strong agreement (in fact, if it were a strong agreement then the 1-buffer semantics of S(KS A ) would yield w = ε). Then by Property 3 we have f = ϕ a@ij andφ = ϕ a. Moreover, Theorem 1.1 guarantees that a run s 0 ϕ − →s ′ 0 = ( q ′ , w ′ ) exists in A and, by Definition 11 and the branching condition, there is a transition ( q ′ , a, q ′′ ) in A where a is a match action on a. By contradiction, assume that there is no liable transition in the run s 0  Definition 12), the state q of configuration s ′ 2 = ( q; w) is not final, there is no participant ready to fire an output, and there is a participant waiting for an input on one of its buffers. The latter condition is guaranteed by the construction of CFSMs from controllers. Since w = ε, we have f = ϕ andφ = ϕ where ϕ ∈ Z and there is a run s 0 ϕ − →s ′ 0 = ( q 1 , w ′ ) in A (by Theorem 1.2). Note that q 1 is redundant in KS A (otherwise by Theorem 1.1, s ′ 2 would not be a deadlock configuration) and, by construction (Lemma 2), q 1 is removed from KS A . This implies that a liable transition has been traversed in s 0 ϕ − →s ′ 0 .
4. Wlog we can assume that ϕ is a strong agreement ( otherwise we have s 2 ϕ a@ij ։ s ′ 2 for some i, j, a and since s ′ 2 is not a deadlock it is possible to perform the step s ′ 2 a@ij ։ s ′′ 2 and we have that ϕ a is a strong agreement where a is a match action with a (i) = a, a ( j) = a). Moreover, from s ′′ 2 is not possible to reach a final state, and we apply the following reasoning to s ′′ 2 , ϕ a instead of s ′ 2 , ϕ. Note that the converse of Theorem 1.3 does not hold. Indeed if a CA A passes through a liable transition, it can be that S(KS A ) never reaches a deadlock configuration.

Example 9 Consider the CAs and CMs of Example 7. A possible trace belonging to the system S(KS A⊗B⊗C )
is generated by the transitions: (q 01 , a@AB, q 11 ), (q 01 , a@AB, q 21 ). By using Theorem 1.2 this trace corresponds to the liable transition ( q 0 , (a, a, ), q 7 ) of the product automaton.
However after this two steps the system S(KS A⊗B⊗C ) will never reach a deadlock configuration. Indeed, it is always possible to perform the transitions:(q 1 1 , a@AB, q 11 ), (q 21 , a@AB, q 21 ). Note that S(KS A⊗B⊗C ) is deadlock-free but not convergent.
We are now ready to state our main result: the controller of a CA has the branching condition if and only if the corresponding CS is convergent.   ( q, w). We distinguish two cases:

Theorem 2 Let A be a contract automaton, KS A be its MPC, and S(KS
• s ′ 2 is not a deadlock configuration. Then by applying Theorem 1.4 we have ϕ = ϕ 1 aϕ ′′ for some ϕ 1 , a, ϕ ′′ such that q 0 Note that a is a match action, otherwise a participant in S(KS A ) has fired an action to the environment in ϕ. Since S(KS A ) is derived from KS A and all the transitions of KS A are match, this is not possible. Assume a is an action on a with snd( a) = i, rcv( a) = j for some i, j ∈ P.
By hypothesis we know that s 2 ։ , hence in the configuration s ′ 2 the participant i is able to fire the action a@ij. By Definition 11, 3 there must be a state q 2 in KS A such that ( q 2 , a, q 3 ) is a transition in KS A (recall that S(KS A ) is derived from KS A ) and q 2(i) = q 1(i) (otherwise we would not have s ′ 2 a@ij ։ ), and since ( q 1 , a, q ′ 1 ) ∈ TLiable(KS A /A ) we conclude that the branching condition does not hold in KS A , obtaining a contradiction.  ( q 1 , w). As the previous case, by Definition 11, 3 there must be a state q 2 in KS A such that ( q 2 , a, q 3 ) is a transition in KS A where a is a match an action on a with snd( a) = i, rcv( a) = j and q 2 (i) = q 1 (i) . Moreover since s ′ 2 is a deadlock, it must be that there is no transition ( q 1 , a, q 4 ) in KS A , otherwise by Theorem 1 . 1 we have s ′ A consequence of Theorem 2 is that a strongly safe CA has the branching condition if and only if the corresponding CS is convergent.

Corollary 4 Let A be a contract automaton, then A is strongly safe and has branching condition if and only if S(A ) is convergent.
Proof. The statement follows trivially by notice that if A is strongly safe then A = KS A , hence KS A has the branching condition and we can apply Theorem 2.   ( , a, , a) which is not available in state q 3 , and from state q 3 we have the match transition ( , a, a, ) which is not available from state q 1 . The translation yields the CMs: A deadlock configuration is generated by the trace a@AC.a@AC.a@BC.
Example 11 Figure 1 ( q 9 , (d, , d), q ′ ) in KS A for some q ′ . Moreover there is a liable transition with label ( q 9 , ( , , d), ⊥) in Figure 1 which represents the possible deadlock in the system.

depicts the automaton KS
A deadlock configuration in S(KS A ) is given by the trace ϕ d@CA where: In the configuration s ′ 0 = ( q, w) the buffer w is not empty, because w (CA) = d. Moreover the machine A is prevented to read the message on the buffer since its configuration in q is ok@BA.d@CA.

On extending the approach
We discuss possible extensions of our approach to other existing types of agreement on CAs, and on different semantics of CMs, where there are no constraints on the number of messages in a buffer. We start by comparing the other existing types of agreement with the 1-buffer semantics for CMs.

On agreement
The property of agreement requires that all the requests are matched. It allows strings made by match and offer actions only. In the following we discuss a correspondence similar to Theorem 2 for the property of agreement.
Example 12 Consider the CAs corresponding to the regular expressions A = b.d + c.e+ d.e and B = d.e. The controller K A⊗B for the property of agreement is given by the CA: The translation in Definition 11 yields the CMs: Under the 1-buffer semantics, the system S(K A⊗B ) always reaches a deadlock configuration since in every execution there are messages in the buffer with no receiver, corresponding to the offer actions in the controller.
If we assume that the unmatched offers are consumed instantaneously by an artificial participant representing the environment, we still have possible deadlock configurations in S(K A⊗B ), for example if the participants execute the sequence of transitions ( q 0 1 , b@A−, q 1 1 ), ( q 0 2 , d@B−, q 2 2 ), ( q 2 2 , e@BA, q 3 2 ).
Note that K A⊗B has no branching condition: in q 1 , q 3 the participant B is the state q 0 2 , but from q 3 there is no match transition on action d.
Under the assumptions that the offer actions are consumed by the environment, that it is possible to prove that the controller of the CA A has a slightly modified version of the branching condition if and only if the corresponding system S(K A ) is convergent. The proof is obtained by noticing that in the 1-buffer semantic a deadlock configuration is reached only if a participant A send a message a to a participant B and B is unable to consume the message. By Definition 11 this can happen only if there are two different states in the CA where A is in the same internal state and the match transition is available only in one of the two states, i.e. K A has no branching condition. We also need to consider those configurations which are not convergent nor deadlocks as done in Theorem 2.
On weak agreement For the property of weak agreement things are more intricate, indeed it is necessary to modify the actual translation. This is due to the possibility for a participant to fire a request if in the future the offer will be available, while in the CMs if the buffer is empty it is not possible to perform an input action.
To overcome this problem it is possible to synthesize one or more CMs which act as brokers. They receive as input all the actions of the participants, which are now translated into outputs, and reply with messages in a way to drive the participants through the trace in weak agreement.

On different semantics
We now discuss the relations between CAs and other semantics for CMs.
Example 13 Consider the following CA A ⊗ B: We have A = a + b, B = b + a. This CA is strongly safe and has the branching condition. However, by considering the non 1-buffer semantics for CMs, the translated system is not deadlock free. Indeed a possible deadlock in S(K A⊗B ) is generated if the first participant performs the action a@AB and then the second performs the action b@BA. This is because participant B can ignore the message received by the participant A and follow the other branch of the CA. These behaviours is not permitted by the 1-buffer semantics, which forces participants to follow the successful branch.
The previous example shows that if we allow a less constrained semantics for CMs then Theorem 2 does not hold any more. Indeed, we need to introduce other constraints on the behaviour of the CAs to obtain a correspondence with convergent systems.
Note that in the previous example, from state q 0 both participants contain a branch where they can execute an input or an output action. This is called a mixed choice state. It is possible to prove that if a CA has the branching condition, it is strongly safe and has no mixed choice states then the corresponding system is convergent with non 1-buffer semantics. However the converse does not hold. Indeed there exists systems with mixed choice states that enjoy convergence.
Example 14 Consider the following CA A ⊗ B: We have A = a.b + b.a, B = b.a + a.b. This CA is strongly safe, has the branching condition, and contains a mixed choice state, i.e. q 0 . Nevertheless, the corresponding system is convergent.
As showed by the previous example, for obtaining a correspondence similar to Theorem 2, we need to consider those bad mixed choices, where the participants behave differently in the different branches.

Concluding Remarks
We have established a formal correspondence between contract automata, an orchestration model, and communicating machines, a model of choreography. An interesting implication of our results is that contract automata can be seen as an alternative semantics of communicating machines. In fact, the product of communicating machines could be built as a contract automaton once match-actions are properly defined as tuples where output messages appear before the corresponding input ones. However, contract automata are more general in the sense that they would also admit matches where a request appears before its corresponding offer. Exploring those alternative semantics is of interest and it is scope for future work.
The dichotomy orchestration-choreography has been discussed in many papers (see e.g., [9]). The only formal results (we are aware of) that link a choreography to an orchestration framework is in [5]. A precise comparison with [5] is not straightforward as the models use a bisimulation-like relation to exhibit a conformance relation between choreographed and orchestrated computations. Here, we study the conditions to "force" orchestrated computations to well-behave (strong safety), and convergence in a choreography framework in terms of strong safety in the orchestration one.
A practical outcome of our result is that strong safe contract automata can execute without controller (if they are trusted). In fact, one can translate them into communicating machines that run without central control.
For the time being, our result only states that strong agreement corresponds to the 1-buffer semantics of communicating machines. In other words, the execution of the machines is basically synchronous. (We note that this has some advantages since communicating machines with 1-buffer semantics are more computationally tractable [7].) We conjecture that results similar to the one presented in this paper can be achieved for weaker notions of agreement (for example, the ones in [3]) when considering asynchronous behaviours of communicating machines. This is nonetheless left as future work.