DisSysLab

What Agents Know

An agent acts on what it knows. In a distributed system it knows almost nothing: its own state, and whatever arrived in a message. This class makes “agent X knows P” precise, for a predicate P about the rest of the system, and then proves four things about it. Every proof is the same proof — a consistent cut, from the previous class, and the dataflow graph from the one before that.

What is P about?

Fix an agent X. We ask what X knows about the network of other agents and the channels between them. P is a predicate on that network, and on nothing else: not on X, and not on the channels incident on X.

P can be “agents U, V and Z are deadlocked”, or “every agent is waiting for a message and every channel is empty”, or “W solved its problem”. Each is a statement about the region inside the oval in the figure below, and each is something X may or may not be in a position to assert.

Figure 1. P is a predicate on the rest of the system. Press a predicate and the parts of the system it mentions light up. Press deadlocked and the three agents that P is about — U, V and Z — go red along with the channels between them, and so does X: that is the state of X in which X knows the three of them are deadlocked. Press all waiting, channels empty and the whole network goes green, X with it, because that P is about every agent and every channel between them. Press W solved its problem and only W goes blue, because that P is about one agent and therefore about no channel at all. Whatever P says, it says it about the agents inside the oval and the channels between them. X itself is outside, and so are the channels that touch X — X does not need to know anything about itself, and the messages in flight to and from X are exactly what its knowledge will turn out to depend on.

What information enables X to know that W solved its problem?

Figure 1 said what P is about. It said nothing about how X could ever be in a position to assert it. X is not next to W; the two are not even joined by a channel. So if X knows that W solved its problem, something must have carried the news, agent by agent, until it reached X.

Figure 2. What information enables X to know that W solved its problem? The same network as Figure 1. Press Information flow and watch the news travel: W turns blue, then the channel from W to Y, then the one from Y to Z, then the one from Z to X, and only then does X turn blue. Each arrow points the way the information went. Two things to take from it. X's knowledge was not acquired by looking; it arrived, along a chain of channels, one message at a time. And everything on that chain is older than X's knowledge of it — by the time X knows, the news has been in flight for as long as the chain took. Whether that matters is what the rest of this class is about, and the chain itself comes back as a theorem at the end.

A controller and a furnace

A controller C sends control messages to a furnace F, and F replies with the action it took. The furnace is also called the plant. Four steps take the system from one state in which C knows the furnace is on to the next; in asynchronous VLSI this is the four-phase handshake.

F is
In the channels
C knows
Figure 3. What the controller knows, step by step. C is the controller and F the furnace. The colours are the point: F is red while it is on and green while it is off, and C takes the colour of what it knows — red while it knows F is on, green while it knows F is off, and grey while it knows neither. A message carries the colour of the state it is about: turn off and turned off are green, turn on and turned on are red. Four steps, one per message, each of them a flight and an arrival. C sends turn off and goes grey at once, before anything has happened to F. F goes green the instant that message lands — but C stays grey, because nothing has told it. F sends turned off and no colour changes at all while it travels, because a message in transit tells nobody anything. C goes green the instant it arrives. Then the same two steps run again with turn on and turned on, and the ninth step is the first one over again. Two things are worth noticing. C loses its knowledge the instant it sends, and regains it only when it receives. And the state of F that C knows is always a state F was in, never necessarily the one it is in now.

The same handshake, drawn as a computation

The figure above shows states one at a time. Draw the whole computation instead, with a line for C and a line for F, and the intervals in which C knows something become segments of C's line. This is the dataflow graph of the previous classes: the nodes are steps, and an edge carries a state.

Figure 4. Knowledge as intervals on an agent's line. Eight steps, four messages, and the colours of the previous figure laid along the timelines. F's line is red while F is on and green while it is off, so it changes at 3 and at 6 — the two arrivals. C's line is red while C knows F is on, green while it knows F is off, and grey in between: red from 1 to 2, grey from 2 to 4, green from 4 to 5, grey from 5 to 7, red from 7 to 8. Ask the three questions and the matching stretches of C's line are picked out and named. Read the picture once more and the shape of the rest of the class is already in it: uncertainty begins at a send, knowledge arrives with a receive, and between C knowing one thing and C knowing its opposite there is always a stretch where C knows neither.

Two agents and two tokens

A smaller example, with nothing in it but counting. Two agents, X and Y, pass two indivisible tokens back and forth. What does X know about Y?

X holds
In the channels
Y holds
X knows Y holds
Figure 5. Counting is enough to produce uncertainty. When X holds both tokens it knows Y holds none: there are two tokens, X can see both of them, and nothing is in flight that X did not send. Send one, and X knows only that Y holds none or one — the token may still be in the channel, or it may have arrived. X cannot tell those two apart, and the difference is invisible to it until something comes back. Notice that X's uncertainty is not ignorance about the past. X knows exactly what it did. What it cannot know is how far its own message has got.

What “X knows P” means

Now the definition. Consider a point on X's line: an edge of the dataflow graph between two consecutive steps of X, labelled with X's state there. Call that state s.

Knowledge at a point X knows P when X's state is s means: P holds in every global state in which X's state is s.

That definition is about global states, and the previous class gave us the global states that matter: the consistent cuts. Many different cuts pass through one point on X's line, and they describe different global states — but X's own state is s in all of them, because they all cut the same edge of X's line. So the definition has a consequence we can draw:

Knowledge and consistent cuts If X knows P at a point on X's line, then P holds in the global state of every consistent cut through that point.

This cut's past
x's state here
So P must hold
Figure 6. One state of x, several states of the system. The thick segment is the point in question: x's line between steps 2 and 5, carrying state s. Press Next cut to step through the consistent cuts that pass through that segment. Each one is a different global state — the sets of completed steps differ, and so do the messages in the channels — and in every one of them x's own state is the same s. That is the whole content of the definition. x cannot distinguish these global states from one another, so for x to know P at this point, P has to hold in all of them. Knowledge is not a property of one state; it is a property of a set of states that look alike from where the agent is standing.

Losing knowledge, and gaining it

With the definition in hand the theorems are short, and they are all proved the same way: take two consistent cuts that are identical everywhere except at the agent in question, and notice that a predicate about the rest of the system cannot tell them apart.

Theorem An agent does not lose knowledge when it takes a step in which it sends no messages to other agents.

Theorem An agent does not gain knowledge when it takes a step in which it receives no messages from other agents.

The cut passes C at
Received in the past
All of them sent in the past?
Figure 7. Moving the cut, and what it costs. One consistent cut, drawn as a red line. It starts as a single vertical through after: everything to its left is the past and everything to its right the future, and every message received in the past was sent in the past — which is what makes it a state the system could have been in. Press the button. The cut moves at C alone, from after step 5 to before it, and nothing else about it changes: below C's line it is the same cut, so U and V have done exactly what they had done, and the channels between them hold exactly what they held. What changes is one thing. Step 5 is no longer in the past, so the message C took there is no longer received in the past — it is in transit instead, and turns blue. One fewer message received, and no new message sent, so every message received in the past is still sent in the past: the moved cut is a consistent cut too. Step 5 does send something: an alarm, which C sends to itself and takes at step 8, drawn as an arc over C's own line. The theorem allows it. Its hypothesis is that the step sends nothing to another agent, and an alarm tells U and V nothing — it never leaves C. Watch it as the cut moves: before the move the alarm is in transit, after it the alarm has not been sent, and either way U, V and the channels between them are untouched. That is the theorem in one move. C sends nothing to another agent at step 5, so the cut can always be walked back across it, and the part of the picture P talks about does not move at all.

And now the same picture with one thing changed: at step 5, C sends a message to U. The alarm it sends itself at 2 is still there and still harmless. What matters is the message that leaves C.

The cut passes C at
Received in the past
All of them sent in the past?
Figure 8. The step that does send, and what goes wrong. Nine events. C sends an alarm to itself at 2, taken at 5 — harmless, as before. But at step 5 C also sends a message to U, which U takes at 7. Events 8 and 9 lie to the right of after, so they stay in the future throughout, and the two messages aimed at them are in flight the whole time. The cut starts as a single vertical through after, and it is a consistent cut: every message received in the past was sent in the past. Now press the button. The cut moves at C alone, back to before step 5 — and the picture breaks. Step 5 is now in the future and step 7 is still in the past, so 5→7 runs from the future to the past. No state of the system looks like that, so this is not a consistent cut. The message turns red and is crossed. That is why the theorem says sends no messages to other agents. When the step sends nothing outward, the cut can always be walked back across it and C keeps what it knew. When it sends, the walk is blocked, and C can lose knowledge at exactly that step — which is what Figure 3's controller does every time it says turn off.

And the dual. Keep the same computation, but ask the opposite question: can the cut be walked forward across step 5? Step 5 receives only the alarm C sent itself, and nothing from another agent — which is the hypothesis of the second theorem.

The cut passes C at
Received in the past
All of them sent in the past?
Figure 9. The dual: walking the cut forward. The same nine events, and after now stands between 5 and 6. This time the cut starts as a single vertical through before, and the move takes C's crossing forward past step 5 rather than back. It works. Step 5 takes the alarm C sent itself at 2, and 2 is already in the past, so putting step 5 into the past adds a received message whose send was there all along. Nothing is received that was not sent, and the moved cut is a consistent cut too: every consistent cut through “before” is a consistent cut through “after”. Since P is a predicate on U, V and the channels between them — and none of that moved — anything C knows after step 5 it already knew before. That is the second theorem: an agent gains no knowledge at a step in which it receives nothing from another agent. Watch the alarm as the cut passes it: in transit before the move, delivered after. And compare with the figure above, where the same step blocked the walk in the other direction. One step, two theorems, and the difference is whether the message crosses the boundary of C.

Knowledge travels along paths

The next theorem is the one with teeth. If something becomes true somewhere in the system, and later an agent knows it, then there is a chain of messages from the one event to the other. Nothing is learned out of thin air.

Theorem If NOT Q holds before a step e, and C knows Q after a step e′, then there is a path in the dataflow graph from e to e′.

In the past
In the future
In this cut
Figure 10. No path, no knowledge. Q is a predicate on V, and it becomes true at event 4. What matters is not whether anything leaves 4 — a message may well leave it — but whether any sequence of messages leads from 4 to step 6. Here none does: C acts at 2 and 6, and what reaches C comes from 5, which happened before 4 had anything to say. Suppose, then, that C does know Q after step 6 — that is the claim written on C's line at the start. Press Draw the cut. A single straight line passes through V's edge from 1 to 4, where NOT Q holds, and through C's edge after 6, where C is supposed to know Q. It is a consistent cut: its past is 1, 2, 3, 5, 6, its future is 4, 7, and every message received in its past was sent in its past — so it is one state the system could have been in. And in that one state, Q is false at V while C knows Q. Both at once, which cannot be. The supposition is what has to go: with no message sequence from 4 to 6, C cannot know Q there. This is the previous theorem read backwards — no path from where the news was made to where it would be known, and the knowledge cannot be there.

Two more, and a warning about negation

The same argument, run in the other direction, gives the mirror theorem: if C knows Q before a step e and NOT Q holds after a step e′, then there is a path in the dataflow graph from e to e′. Figure 3 is an instance — C knows the furnace is on, and the furnace is off only after the message C sent has arrived.

And one consequence worth stating on its own, because it is the shape of Figure 4:

Theorem If C knows Q before a step, and NOT Q holds after some later step, then there is a point in between at which C is uncertain about Q.

C cannot pass directly from knowing Q to knowing NOT Q. Something must happen, a message must travel, and while it travels C knows neither.

Finally, a distinction that is easy to lose. NOT (C knows Q) is not C knows NOT Q. The first is much weaker: it is satisfied either by C knowing NOT Q, or by C having no idea. That second case is what we have been calling uncertainty:

Uncertainty C is uncertain about Q means NOT (C knows Q) and NOT (C knows NOT Q).

Every “C uncertain” label in Figures 3 and 4 is that conjunction, and every one of them is produced by the same thing: a message that C has sent, or is waiting for, and cannot see.