Assume, Guarantee or Repair

We present Assume-Guarantee-Repair (AGR) – a novel framework which not only verifies that a program satisfies a set of properties, but also repairs the program in case the verification fails. We consider communicating programs – these are simple C-like programs, extended with synchronous communication actions over communication channels. Our method, which consists of a learning-based approach to assume-guarantee reasoning, performs verification and repair simultaneously: in every iteration, AGR either makes another step towards proving that the (current) system satisfies the specification, or alters the system in a way that brings it closer to satisfying the specification. We manage handling infinite-state systems by using a finite abstract representation, and reduce the semantic problems in hand – satisfying complex specifications that also contain first-order constraints – to syntactic ones, namely membership and equivalence queries for regular languages. We implemented our algorithm and evaluated it on various examples. Our experiments present compact proofs of correctness and quick repairs.


Introduction
Verification of large-scale systems is a main challenge in the field of formal verification. Often, the verification process of such a system does not scale well. Compositional verification aims to verify small components of a system separately, and from the correctness of the individual components, to conclude the correctness of the entire system. This, however, is not always possible, since the correctness of a component often depends on the behavior of its environment.
The Assume-Guarantee (AG) style compositional verification [22,26] suggests a solution to this problem. The simplest AG rule checks if a system composed of components M 1 and M 2 satisfies a property P by checking that M 1 under assumption A satisfies P and that any system containing M 2 as a component satisfies A. Several frameworks have been proposed to support this style of reasoning. Finding a suitable assumption A is then a common challenge in such frameworks.
In this work, we present Assume-Guarantee-Repair (AGR) -a fully automated framework which applies the Assume-Guarantee rule, and while seeking a suitable assumption A, incrementally repairs the given program in case the verification fails. Our framework is inspired by [24], which presented a learningbased method to finding an assumption A, using the L * [5] algorithm for learning regular languages.
Our AGR framework handles communicating programs. These are infinite-state C-like programs, extended with the ability to synchronously read and write messages over communication channels. We model such programs as finite-state automata over an action alphabet, which reflects the program statements. The accepting states in these automata model points of interest in the program that the specification can relate to. The automata representation is similar in nature to that of control-flow graphs. Its advantage, however, is in the ability to exploit an automata-learning algorithm such as L * .
The composition of the two program components, M 1 and M 2 , denoted M 1 ||M 2 , synchronizes on read-write actions on the same channel. Between two synchronized actions, the individual actions of both systems interleave.  Figure 1 presents the code of a communicating program (left) and its corresponding automaton M 2 (right). The automaton alphabet consists of constraints (e.g. x pw ≤ 999), assignment actions (e.g. y pw := 2 · y pw in M 1 of Figure 2), and communication actions (e.g. enc!x pw sends the value of variable x pw over channel enc, and getEnc?x pw2 reads a value to x pw2 on channel getEnc).
The specification P is modeled as an automaton that does not contain assignment actions. It may contain communication actions in order to specify behavioral requirements, as well as constraints over the variables of both system components, that express requirements on their values in various points in the runs.
Consider, for example, the program M 1 and the specification P seen in Figure 2, and the program M 2 of Figure 1. M 2 reads a password on channel read to the variable x pw , and once it is long enough (has at least four digits), it sends the value of x pw to M 1 through channel enc. M 1 reads this value to variable y pw and then applies a simple function that changes its value, and sends the changed variable back to M 2 . The property P reasons about the parallel run of the two programs. The pair (getEnc?x pw2 , getEnc!y pw ) denotes a synchronization of M 1 and M 2 on channel getEnc. P makes sure that the parallel run of M 1 and M 2 always reads a value and then encrypts it -a temporal requirement. In addition, it makes sure that the value after encryption is different than the original value, and that there is no overflow -both are semantic requirements on the program variables. That is, P expresses temporal requirements that contain first order constraints. In case one of the requirements does not hold, P reaches the state r 4 which is an error state. Note that P here is not complete, for simplicity of presentation (see Definition 5 for a formal definition of a complete program).   The L * algorithm aims at learning a regular language U . Its entities consist of a teacher -an oracle who answers membership queries ("is the word w in U ?") and equivalence queries ("is A an automaton whose language is U ?"), and a learner, who iteratively constructs a finite deterministic automaton A for U by submitting a sequence of membership and equivalence queries to the teacher.
In using the L * algorithm for learning an assumption A for the AG-rule, membership queries are answered according to the satisfaction of the specification P : If M 1 ||t satisfies P , then the trace t in hand should be in A. Otherwise, t should not be in A. Once the learner constructs a stable system A, it submits an equivalence query. The teacher then checks whether A is a suitable assumption, that is, whether M 1 ||A satisfies P , and whether the language of M 2 is contained in the language of A. According to the results, the process either continues or halts with an answer to the verification problem. The learning procedure aims at learning the weakest assumption A w , which contains all the traces that in parallel with M 1 satisfy P . The key observation that guarantees termination in [24] is that the components in this procedure -M 1 ,M 2 , P and A w -are all regular.
Our setting is more complicated, since the traces in the components -both the programs and the specification -contain constraints, which are to be checked semantically and not syntactically. These constraints may cause some traces to become infeasible. For example, if a trace contains an assignment x := 3 followed by a constraint x ≥ 4 (modeling an "if" statement), then this trace does not contribute any concrete runs, and therefore does not affect the system behavior. Thus, we must add feasibility checks to the process.
Constraints in the specification also pose a difficulty, as satisfiability of a specification is determined by the semantics of the constraints and not only by the language syntax, and so there is more here to check than standard language containment. Moreover, in our setting A w above may no longer be regular, see Example 3. However, our method manages to overcome this problem.
As we have described above, not only do we construct a learning-based method for the AG-rule for communicating programs, but we also repair the programs in case the verification fails. An AG-rule can either conclude that M 1 ||M 2 satisfies P , or return a real, non-spurious counterexample of a computation t of M 1 ||M 2 that violates P . In our case, instead of returning t, we repair M 2 in a way that eliminates this counterexample. Our repair is both syntactic and semantic, where for semantic repair we use abduction [25] to infer a new constraint which makes the counterexample t infeasible.
Consider again M 1 and P of Figure 2 and M 2 of Figure 1. The composition M 1 ||M 2 does not satisfy P . For example, if the initial value of x pw is 2 63 , then after encryption the value of y pw is 2 64 , violating P . Our algorithm finds a bad trace during the AG stage which captures this bad behavior, and the abduction in the repair stage finds a constraint that eliminates it: x pw < 2 63 , and inserts this constraint to M 2 .
Following this step we now have an updated M 2 , and we continue with applying the AG-rule again, using information we have gathered in the previous steps. In addition to removing the error trace, we update the alphabet of M 2 with the new constraint.
Continuing our example, in a following iteration AGR will verify that the repaired M 2 together with M 1 satisfy P , and terminate.
Thus, AGR operates in a verify-repair loop, where each iteration runs a learning-based process to determine whether the (current) system satisfies P , and if not, eliminates bad behaviors from M 2 while enriching the set of constraints derived from these bad behaviors, which often leads to a quicker convergence. In case the current system does satisfy P , we return the repaired M 2 together with an assumption A that abstracts M 2 and acts as a smaller proof for the correctness of the system.
We have implemented a tool for AGR and evaluated it on examples of various sizes and of various types of errors. Our experiments show that for most examples, AGR converges and finds a repair after 2-5 iterations of verify-repair. Moreover, our tool generates assumptions that are significantly smaller then the (possibly repaired) M 2 , thus constructing a compact and efficient proof of correctness.
Contributions To summarize, the main contributions of this paper are: 1. A learning-based Assume-Guarantee algorithm for infinite-state communicating programs, which manages to overcome the difficulties such programs present. In particular, our algorithm overcomes the inherent irregularity of the first-order constraints in these programs, and offers syntactic solutions to the semantic problems they impose. 2. An Assume-Guarantee-Repair algorithm, in which the Assume-Guarantee and the Repair procedures intertwine to produce a repaired program which, due to our construction, maintains many of the "good" behaviors of the original program. Moreover, in case the original program satisfies the property, our algorithm is guaranteed to terminate and return this conclusion. 3. An incremental learning algorithm that uses query results from previous iterations in learning a new language with a richer alphabet. 4. A novel use of abduction to repair communicating programs over first order constraints.
5. An implementation of our algorithm, demonstrating the effectiveness of our framework.
Related Work Assume-guarantee style compositional verification [22,26] has been extensively studied. The assumptions necessary for compositional verification were first produced manually, limiting the practicality of the method.
More recent works [9,16,14,6] proposed techniques for automatic assumption generation using learning and abstraction refinement techniques, making assume-guarantee verification more appealing. In [24,6] alphabet refinement has been suggested as an optimization, to reduce the alphabet of the generated assumptions, and consequently their sizes. This optimization can easily be incorporated into our framework as well.
Other learning-based approaches for automating assumption generation have been described in [7,17,8]. All these works address non-circular rules and are limited to finite state systems. Automatic assumption generation for circular rules is presented in [12,13], using compositional rules similar to the ones studied in [21,23].
Our approach is based on a non-circular rule but it targets complex, infinite-state concurrent systems, and addresses not only verification but also repair. The compositional framework presented in [19] addresses L * -based compositional verification and synthesis but it only targets finite state systems.
Also related is the work in [18], which addresses automatic synthesis of circular compositional proofs based on logical abduction; however the focus of that work is sequential programs, while here we target concurrent programs. A sequential setting is also considered in [3], where abduction is used for automatically generating a program environment. Our computation of abduction is similar to that of [3]. However, we require our constraints to be over a predefined set of variables, while they look for a minimal set.
The approach presented in [27] aims to compute the interface of an infinite-state component. Similar to our work, the approach works with both over-and under-approximations but it only analyzes one component at a time. Furthermore, the component is restricted to be deterministic (necessary for the permissiveness check). In contrast we use both components of a system to compute the necessary assumptions, and as a result they can be much smaller than in [27]. Furthermore, we do not restrict the components to be deterministic and, more importantly, we also address the system repair in case of dissatisfaction.

Communicating Programs
In this section we present the notion of communicating programs. These are C-like programs, extended with the ability to synchronously read and write messages over communication channels. We model such programs as automata over an action alphabet that reflects the program statements. The alphabet includes constraints, which are quantifier-free first-order formulas, representing the conditions in if and while statements. It also includes assignment statements and read and write communication actions. The automata representation is similar in nature to that of a control-flow graph. Its advantage, however, is in the ability to exploit an automata-learning algorithm such as L * for its verification.
We first formally define the alphabet over which communicating programs are defined. Let G be a finite set of communication channels. Let X be a finite set of variables (whose ordered vector isx) and D be a (possibly infinite) data domain. For simplicity, we assume that all variables are defined over D. The elements of D are also used as constants in arithmetic expressions and constraints.
x is a read action of a value to the variable x through channel g, and g!x is a write action of the value of x on channel g. We use g * x to indicate some action, either read or write, through g. The pairs (g?x 1 , g!x 2 ) and (g!x 1 , g?x 2 ) represent a synchronization of two programs on read-write actions over channel g (defined later).
1. Q is a finite set of states and q 0 ∈ Q is the initial state. 2. X is a finite set of variables that range over D.
That is, for each state it holds that either all outgoing edges are labeled with constraints, or that all outgoing edges are labeled with assignments or communication actions. 5. F ⊆ Q is the set of accepting states.
The words that are read along a communicating program are a symbolic representation of the program behaviors. We refer to such a word as a trace. Each such trace induces concrete runs of the program, which are formed by concrete assignments to the program variables in a way that conforms with the actions along the word.
We now formally define these notions.

Definition 3.
A path in a program M is a finite sequence of states and actions p = (q 0 , a 1 , q 1 , . . . , a n , q n ), starting with the initial state q 0 , such that ∀0 ≤ i < n we have (q i , a i+1 , q i+1 ) ∈ δ. The induced trace of p is the sequence t = (a 1 , . . . , a n ) of the actions in p. If q n is accepting, then t is an accepted trace of M .
From now on we assume that every trace we discuss is induced by some path. We turn to define the concrete runs of the program.
1. β 0 is an arbitrary valuation. 2. If a i = g?x, then β i (y) = β i−1 (y) for every y = x. Intuitively, x is arbitrarily assigned by the read action, and the rest of the variables are unchanged.

If a i is an assignment
That is, the effect of a synchronous communication on a channel is that of an assignment. 5. If a i does not involve a read or an assignment, then β i = β i−1 . 6. Finally, if a i is a constraint in C, then β i (x) a i (and since a i does not change the variable assignments, then β i−1 (x) a i holds as well).
We say that t is feasible if there exists a run of t.
The symbolic language of M , denoted T (M ), is the set of all accepted traces induced by paths of M . The concrete language of M is the set of all runs of accepted traces in T (M ). We will mostly be interested in feasible traces, which represent (concrete) runs of the program. Intuitively, the symbolic language of a program M corresponds to its syntactic behavior, while the concrete language corresponds to the semantics of the program.
is executed beforehand.

Parallel Composition
We now describe and define the parallel run of two communicating programs, and the way in which they communicate.
The interface alphabet αI of M 1 and M 2 consists of all communication actions on channels that are common to both components. That is, In parallel composition, the two components synchronize on their communication interface only when one component writes data through a channel, and the other reads it through the same channel. The two components cannot synchronize if both are trying to read or both are trying to write. We distinguish between communication of the two components with each other (on their common channels), and their communication with their environment. In the former case, the components must "wait" for each other in order to progress together. In the latter case, the communication actions of the two components interleave asynchronously. Formally, the parallel composition of M 1 and M 2 , denoted M 1 ||M 2 , is the program M = Q, x, α, δ, q 0 , F defined as follows.
where Q 1 and Q 2 are new copies of Q 1 and Q 2 , respectively. The initial state is q 0 = (q 1 0 , q 2 0 ). 4. δ is defined as follows.

Regular Properties and Their Satisfaction
In this section we define the syntax and semantics of the properties that we consider. These are properties that can be represented as finite automata, hence the name regular. However, the alphabet of such automata includes communication actions and first-order constraints over program variables. Thus, such automata are suitable for specifying the desired and undesired behaviors of communicating programs over time.
In order to define our properties, we first need the notion of a deterministic and complete program. The definition is somewhat different from the standard definition for finite automata, since it takes the semantic meaning of constraints into account.
Intuitively, in a deterministic and complete program, every concrete run has exactly one trace that induces it.
Definition 5. A program over alphabet α is deterministic and complete if for every state q and for every action a ∈ α the following hold: 1. There is exactly one state q such that (q, a, q ) is in δ. 5 5 in our examples we sometimes omit the actions that lead to a rejecting sink for the sake of clarity. (q, c 1 , q ) and (q, c 2 , q ) are in δ for constraints c 1 , c 2 ∈ C and q = q , then c 1 ∧ c 2 ≡ false.

If
3. Let C q be the set of all constraints on transitions leaving q. Then ( c∈Cq c) ≡ true .
A property is a deterministic and complete program with no assignment actions. A trace is accepted by a property P if it reaches a state in F , the set of accepting states of P . Otherwise, it reaches a state in Q \ F , and is rejected by P .
Next, we define the satisfaction relation between a program and a property. Intuitively, a program M satisfies a property P (denoted M P ) if all runs induced by accepted traces of M reach an accepting state in P .
A property P specifies the behavior of a program M by referring to communication actions of M and imposing constraints over the variables of M . Thus, the set of variables of P is identical to that of M . Let G be the set of communication actions of M . Then, αP includes a subset of G as well as constraints over the variables of M . The interface of M and P , which consists of the communication actions that occur in P , is defined as αI = G ∩ αP .
In order to capture the satisfaction relation between M and P , we define a conjunctive composition between M and P , denoted M × P . In conjunctive composition, the two components synchronize on their common communication actions when both read or both write through the same communication channel. They interleave on constraints and on actions of αM that are not in αP .  6

. That is, the alphabet includes communication actions on channels common to M and P . It also includes individual actions of M and P . 4. δ is defined as follows.
(a) For a = (g * x, g * y) ∈ αI, or a = g * x ∈ αI: δ((q 1 , q 2 ), a) = (δ M (q 1 , a), δ P (q 2 , a)).
That is, on actions that are not common communication actions to M and P , the two components interleave.
Note that accepted traces in M ×P are those that are accepted in M and rejected in P . Such traces are called error traces and their corresponding runs are called error runs. Intuitively, an error run is a run along M which violates the properties modeled by P . Such a run either fails to synchronize on the communication actions, or reaches a point in the computation in which its assignments, coming from M , violate some constraint described by P . These runs are manifested in the traces that are accepted in M but are composed with matching traces that are rejected in P . We can now formally define when a program satisfies a property.

Definition 7. For a program M and a property P , we define M P iff M × P contains no feasible accepted traces.
Thus, a feasible error trace in M × P is an evidence to M P , since it indicates the existence of a run that violates P . Figure 3 and the property P of Figure 2. As we discussed in Section 1, M P . The trace t = read ?x pw , 999 < x pw , (enc!x pw , enc?y pw ), x pw == y pw , y pw := 2 · y pw , (getEnc?x pw2 , getEnc!y pw ), x pw2 == y pw , x pw ! = x pw2 , y pw ≥ 2 64 is a feasible error trace in M × P proving that an overflow is possible.

The Assume-Guarantee-Repair (AGR) Framework
In this section we discuss our Assume-Guarantee-Repair (AGR) framework for communicating programs. The framework consists of a learning-based Assume-Guarantee algorithm, called AG L * , and a REPAIR procedure, which are tightly joined.
Let M 1 and M 2 be two programs, and let P be a property. The classical Assume-Guarantee (AG) proof rule [26] assures that if we find an assumption A (in our case, a communicating program) such that M 1 ||A P and M 2 A both hold, then M 1 ||M 2 P holds as well. For LTSs [9], the AG-rule is guaranteed to either prove correctness or return a real (non-spurious) counterexample. The work in [9] relies on the L * algorithm [5] for learning an assumption A for the AG-rule. In particular, L * aims at learning A w , the weakest assumption for which M 1 ||A w P holds. A crucial point of this method is the fact that A w is regular [15], and thus can be learned by L * .

Lemma 1. For infinite-state communicating programs, the weakest assumption A w is not always regular.
Example 3. Consider the programs M 1 , M 2 and the property P of Figure 4. The weakest assumption with which M 1 satisfies P should contain exactly all traces (over the alphabet of M 2 ) that contain equally many actions of the form x := x + 1 and y := y + 1. This set of traces is not regular, and therefore cannot be learned by L * . To cope with this difficulty, we change the target of learning. Instead of learning the (possibly) nonregular language of A w , we learn T (M 2 ), the set of accepted traces of M 2 . This language is guaranteed to be regular, as it is represented by the automaton M 2 .
Note that in case that M 1 ||M 2 P , repair is never needed, and M 2 is a valid assumption. In the worst case, the procedure halts once it has learned M 2 . In particular, in case there are no error traces, termination of our algorithm is guaranteed. If M 1 ||M 2 P then there does not exist a matching assumption, and attempting to learn M 2 will reveal this. Therefore, using T (M 2 ) as a learning goal matches the AG rule.
The nature of AG L * is such that the assumptions it learns before it reaches M 2 may contain the traces of M 2 and more, but still be represented by a smaller automaton. Therefore, similarly to [9], AG L * often terminates with an assumption A that is much smaller than M 2 . Indeed, our tool often produces very small assumptions (see Section 5).
As mentioned before, not only that we determine whether M 1 ||M 2 P , but we also repair the program in case it violates the specification. When M 1 ||M 2 P , the AG L * algorithm returns an error trace t as a witness for the violation. In this case, we initiate the REPAIR procedure, which eliminates t from M 2 . REPAIR applies abduction in order to learn a new constraint which, when added to t, creates an infeasible trace. 7 The new constraint enriches the alphabet in a way which may make similar traces infeasible as well. We elaborate on our use of abduction in Section 4.2. The removal of t and the addition of the new constraint result in a new goal M 2 for AG L * to learn. We now return to AG L * to search for a new assumption A that allows to verify M 1 ||M 2 P .
An important feature of our AGR algorithm is its incrementality. When learning an assumption A for M 2 we can use the membership queries previously asked for M 2 , since the answer for them has not been changed. In the full version [1] we prove that the difference between the languages of M 2 and M 2 lies in words (traces) whose membership has not yet been queried on M 2 . This allows the learning of M 2 to start from the point where the previous learning has left off, resulting in a more efficient algorithm.
As opposed to the case where M 1 ||M 2 P , we cannot guarantee the termination of the repair process in case M 1 ||M 2 P . This, since we are only guaranteed to remove one (bad) trace and add one (infeasible) trace in every AGR REPAIR iteration (although in practice, every iteration may remove a larger set of traces). Thus, we may never converge to a repaired system. Nevertheless, in case of property violation, our algorithm always finds an error trace, thus a progress towards a "less erroneous" program is guaranteed.
It should be noted that the AG L * part of our AGR algorithm deviates from the AG-rule of [9] in two important ways. First, since the goal of our learning is M 2 rather than A w , our membership queries are different in type and order. Second, in order to identify real error traces and send them to REPAIR as early as possible, we add additional queries to the membership phase that reveal such traces. We then send them to REPAIR without ever passing through equivalence queries, which improves the overall efficiency. Indeed, our experiments include several cases in which all repairs were invoked from the membership phase. In these cases, AGR ran an equivalence query only when it has already successfully repaired M 2 , and terminated.

The Assume-Guarantee-Repair (AGR) Algorithm
We now describe our AGR algorithm in more detail (see Algorithm 1). Figure 5 describes the flow of the algorithm. AGR comprises two main parts, namely AG L * and REPAIR.
The input to AGR are the components M 1 and M 2 , and the property P . While M 1 and P stay unchanged during AGR, M 2 keeps being updated as long as the algorithm recognizes that it needs repair (we can guarantee termination in certain cases, as we discuss in Section 4.4).
The algorithm works in iterations, where in every iteration the next updated M i 2 is calculated, starting with iteration i = 0, where M 0 2 = M 2 . An iteration starts with the membership phase in line 2, and ends either when AG L * successfully terminates (line 16) or when procedure REPAIR is called (lines 7 and 24). When a new system M i 2 is constructed, AG L * does not start from scratch. The information that has been used in previous iterations is still valid for M i 2 . The new iteration is given additional new trace(s) that have been added or removed from the previous M i 2 (lines 9,11,20, 27). AG L * consists of two phases: membership, and equivalence. The membership phase (lines 2-11) consists of a loop in which the learner constructs the next assumption A i j according to answers it gets from the teacher on a sequence of membership queries on various 7 There are also cases in which we do not use abduction, as discussed in Section 4.3 2 ) in parallel with M 1 does not satisfy P , then t is a bad behavior of M 2 . Therefore, if such a t is found during the membership phase, REPAIR is invoked.
Once the learner reaches a stable assumption A i j , it passes it to the equivalence phase (lines [12][13][14][15][16][17][18][19][20][21][22][23][24][25][26][27]. In this case, AGR terminates and returns M i 2 as a successful repair of M 2 . If M 1 ||A i j P , then a counterexample t is returned, that is composed of bad traces in M 1 , A i j , and P . If the bad trace t 2 , the restriction of t to the alphabet of A i j , is also in M i 2 , then t 2 is a bad behavior of M i 2 , and here too the REPAIR phase is invoked. Otherwise, AGR returns to the membership phase with t 2 as a trace that should not be in A i j , and continues to learn A i j+1 . As we have described, REPAIR is called when a bad trace t is found in (M 1 ||M i 2 ) × P and should be removed. If t contains no constraints then its sequence of actions is illegal and its subtrace t 2 from M i 2 should be removed from M i 2 . In this case, REPAIR returns to AG L * with a new learning goal M i+1 along with the answer "no" to the membership query on t 2 . In 4.3 we discuss different methods for removing t 2 from M i 2 . The more interesting case is when t contains constraints. In this case, we not only remove the matching t 2 from M i 2 , but we also add a new constraint c to the alphabet of M i+1 2 , which causes t 2 to be infeasible. This way we eliminate t 2 , and may also eliminate a family of bad traces that violate the property in the same manner. We deduce c using abduction, see Section 4.2. As before, REPAIR returns to AG L * with a new goal to be learned, but now also with an extended alphabet. The membership phase is then provided with two new answers to the membership query: t 2 that should not be included in the new assumption, and (t 2 · c) that should be included.
Incremental learning One of the advantages of AGR is that it is incremental, in the sense that membership answers from previous iterations remain unchanged for the repaired system. Indeed, since this is the first time that AG L * queries t 2 , we can return to AG L * with the answer t 2 / ∈ T (M i+1 2 ), without contradicting any previous queries. In addition, t 2 obtained by abduction is a new word (over a new alphabet), which also was not queried earlier. Therefore, we can incrementally add t 2 and t 2 as answers from the teacher, and continue to use answers from previous queries on all other traces.

27:
Return to AGL * in Line 2 with tA / ∈ T (A i j ).

Repair by Abduction
We now describe the repair we apply to M i 2 , in case the error trace t contains constraints (see Algorithm 1, line 32). Error traces with no constraints are removed from M i 2 syntactically (line 31), while in abduction we semantically eliminate t by making it infeasible. The new constraints are then added to the alphabet of M i+1 2 in a way that may eliminate additional error traces. Note that even-though we add new alphabet letters to M 2 , we do not add new feasible traces, since the constraints added by abduction can only restrict the behavior of M 2 , making more traces infeasible. Therefore, we do not add counterexamples to M 2 .
-Exact. To eliminate only t from M 2 , we construct a program (an automaton) A t that accepts only t, and complement it to construct A t that accepts all traces except for t. Finally, we intersect A t with M 2 . -Approximate. Similarly to our repair via abduction in Section 4.2, we prevent the last transition that t takes from reaching an accepting state. Let q be the state that t reaches. We mark q as non-accepting, and add an accepting state q , to which all in-going transitions to q are diverted, except for the last transition on t. This way, some traces that lead to q are preserved by reaching q instead, and the traces that share the last transition of t are eliminated along with t. As we have argued, these transitions may also be erroneous. -Aggressive. In this simple method, we remove q, the state that t reaches, from the set of accepting states.
This way we eliminate t along with all other traces that lead to q. In case that every accepting state is reached by some error trace, this repair might result in an empty language, creating a trivial repair. However, our experiments show that in most cases, this method quickly leads to a non-trivial repair.

Correctness and Termination
For this discussion, we assume a sound and complete teacher who can answer the membership and equivalence queries in AG L * , which require verifying communicating programs and properties with first-order constraints.
As we have discussed earlier, AGR is not guaranteed to terminate, and there are cases where the REPAIR stage may be called infinitely many times. However, in case that no repair is needed, or if a repaired system is obtained after finitely many calls to REPAIR, then AGR is guaranteed to terminate with a correct answer.
To see why, consider a repaired system M i 2 for which M 1 ||M i 2 P . Since the goal of AG L * is to syntactically learn M i 2 , which is regular, this stage will terminate at the latest when AG L * learns exactly M i 2 (it may terminate sooner if a smaller appropriate assumption is found). Notice that, in particular, if M 1 ||M 2 P , then AGR terminates with a correct answer in the first iteration of the verify-repair loop. REPAIR is only invoked when a (real) error trace t is found in M i 2 , in which case a new system M i+1 2 , that does not include t, is produced by REPAIR. If M 1 ||M i 2 P , then an error trace is guaranteed to be found by AG L * either in the membership or equivalence phase. Therefore, also in case that M i 2 violates P , the iteration is guaranteed to terminate. To conclude, we have the following. -If, after finitely many iterations, a repaired program M 2 is such that M 1 ||M 2 P , then AGR terminates with a correct answer.
We have shown that every iteration of AGR is guaranteed to terminate with a correct answer. The detailed correctness proofs are in the full version of this paper [1].
In particular, since every iteration of AGR finds and removes an error trace t, and no new erroneous traces are introduced in the updated system, then in case that M 2 has finitely many error traces, AGR is guaranteed to terminate with a correctly repaired system.

Experimental Results and Conclusions
We implemented our AGR framework in Java, integrating L * implementation from the LTSA tool [20]. We used Z3 [10] as the teacher for the satisfaction queries in AG L * , and for abduction in REPAIR. Table 1  iteration, and are indicated by verification. We tested the three repair methods described in Section 4.3 for counterexamples without constraints, and used abduction when needed. Figure 6 presents comparisons between the three methods in terms of run-time and the size of the repair and assumptions (note that the graphs are given in logarithmic scale). As can be seen in Table 1, our tool successfully generates assumptions that are significantly smaller than the repaired and the original M 2 .
For the examples that needed repair, in most cases our tool needed 2-5 iterations of verify-repair in order to successfully construct a repaired component. Interestingly, in example #15 the aggressive method converged slower than the approximate method. This is due to the structure of M 2 , in which different error traces lead to different states. Marking these states as non-accepting removed each trace separately. However, some of these traces have a common transition, and preventing this transition from reaching an accepting state, as done in the approximate method, managed removing several error traces in a single repair. This example also includes repairs by abduction (as do examples #16, #18 and #19). Example #22 models a simple structure in which, due to a loop in M 2 , the same alphabet sequence can generate infinitely many error traces. The exact repair method timed out, since it attempted removing one error trace at a time. On the other hand, the aggressive method removed all accepting states, creating an empty program -a trivial (yet valid) repair. However, the approximate method created a valid, non-trivial repair.
Conclusion AGR offers a new take on the learning-based approach to assume-guarantee verification, and manages coping with complex properties and repairing infinite-state programs. Our experimental results show that using existing semantic tools, AGR produces very succinct proofs, and quickly and efficiently repairs flawed communicating programs.