Getting Two Phones to Agree on One Turn: The Four Structures of the Partner Workout and Their Limits
A partner workout looks like a turn-based game, but a set that has been done cannot be undone. We survey methods from turn-based games and distributed systems, and lay out what four designs solved, the assumption that blocked them in the end, and the structure we are now examining.
Abstract
A partner workout, in which two people take turns doing sets and write down each other’s records, looks on the surface like a turn-based game. But it has to keep going without a server, the phones sit locked in pockets, and a set that has already been done cannot be undone by software. From September to December 2026 we built four structures to keep this turn in agreement, and we are now examining a fifth. This paper retraces what each structure solved and which assumption blocked it, using design documents, change logs, and model run results.
We draw three conclusions from this record, and all of them are interpretations. First, authority must be assigned fact by fact, not for the workout as a whole. Second, two phones holding the same value does not mean the value is right. Third, if a turn that must never go backward is computed from personal records that can be corrected later, every change to a record becomes a problem for the turn. The structure under review builds on these three, but it is not a final structure confirmed on the real engine and on two phones.
1. The Problem
In a partner workout, two people take turns on the same exercise. While one person does a set, the one touching the phone is usually the person next to them. That person starts the other’s set and writes down the weight and reps. The record goes into the other person’s workout record. So the two phones must give the same answer about the current exercise and turn, and each person’s records must neither be missing nor written twice.
Seven conditions make this problem hard.
- C1. It must work without a server. Two phones close to each other must be able to continue a workout over Bluetooth alone.
- C2. A silent phone is normal. The phone is locked in a pocket, and a locked phone cannot send anything without a Bluetooth connection.
- C3. Reality comes first. A set happens before it is entered. Unlike a move in a game, a set that has already been done cannot be undone because it does not fit the rules.
- C4. Records belong to each person. Even when disconnected from the partner, a person keeps working out alone, and the records must keep being kept.
- C5. We write into the other person’s record. Writing for the person next to you is the default flow, not an exception.
- C6. Messages are lost, arrive twice, and arrive out of order. The same message can also come over two routes, Bluetooth and the server.
- C7. The two people also talk outside the app. They say “let’s do the next exercise” first, and then press buttons; the app cannot know that order.
2. Basis for This Paper
What is written in design documents and change logs we call a “record”; what we obtained by running a model or a search program we call a “run”; and an explanation that groups causes from today’s vantage point we call an “interpretation.” The conditions in Section 1 are constraints found in design documents from several periods, organized from today’s vantage point. The generalization in Section 8 is also an interpretation. For external sources, we opened the original text or official documentation to check what they say, and the sources are listed at the end.
We did not run a comparison experiment under the same conditions each time the structure changed. What we call a “problem” below is a problem confirmed in the design documents and audits of the time. It is not a measured comparison of error rate or speed between structures.
3. How Games Agree on a Turn
3.1 A single authoritative state: typical turn-based games
The simplest method is to keep the game state and the turn in one place. In Apple’s GKTurnBasedMatch, Game Center stores the match and delivers it to the participants. One participant has the current turn, and the turn passes from that participant to the next. If a participant does not respond, the turn can be passed to a predetermined next participant. The default timeout is one week [1].
In the open-source turn-based game engine boardgame.io, a master runs the game rules and computes the next state. A client may show a predicted result first, but it is eventually reconciled to the master’s state. The current player is playOrder[playOrderPos]. The turn is not a value inferred from the game record; it is state that the game engine manages separately [2].
In this approach, input that is not on the current turn may be rejected, because a rejected move is something that never happened in the game. This premise does not hold for the sets of a partner workout (C3).
3.2 Executing the same commands together: lockstep
Age of Empires did not send the full state of every unit; each computer executed the same commands at the same point in time. For example, a command issued in communication turn 1000 was executed in turn 1002. In between, the machines exchanged messages and prepared to process them. In return, the game could not run faster than the slowest computer, and it could stall when delay or packet loss occurred. When execution results diverged, the game halted, and even a difference that started out tiny grew over time [3].
In a partner workout, having the two phones wait for each other would violate C2 and C4. One person’s phone being locked cannot stop the other person’s workout.
3.3 One player as host
Instead of a server, a player’s device can decide the game state. Unity describes the structure in which one game instance runs both the simulation and a player client as a listen server [4]. In Photon Fusion 1’s Host Mode, the session is lost if the host’s connection drops. With host migration, a new host can continue from the last snapshot stored in the cloud. It is not on by default, the client must handle it separately, and changes after the last snapshot are not kept [5].
3.4 Sharing authority
In Unity’s Distributed Authority, several game instances share responsibility for the state of objects. There is no server running the game, but a small central state service manages some of the state and relays communication [4]. In Photon Fusion’s Shared Mode, a client initially holds state authority over the objects it creates, and can later hand it to another client [5].
This resembles the condition “my set is held by my phone.” But it does not by itself settle whose the turn that two people share is.
3.5 Merging values and ordering
A state-based CRDT converges when its values form a join semilattice, merging computes the least upper bound of two values, and updates never move a value backward. Under these conditions, if every update is eventually delivered, replicas that have received the same updates reach the same state. The result of a merge is the same if the order is changed, if the grouping is changed, or if the same value is merged several times. The same report left the question of what kinds of invariants CRDTs can preserve as future research [6].
Lamport defined the happened-before relation between events as a partial order. When logical clock values are equal, he broke the tie by a predetermined process order, extending it to a total order. But this order can differ from the order people know. Even if a person sends request A, then phones a friend and has the friend send request B, the system does not know about the phone call and may place B before A [7]. An order agreed by voice in a gym is the same as this phone call (C7).
The last column of the table below is our interpretation of each approach against the conditions of a partner workout.
| Approach | What decides the outcome | When there is no response | Why it is hard to use as is for a partner workout |
|---|---|---|---|
| Turn-based game server or master | The server or master | After a set time, the turn can be passed to the next person | Short-range connection without a server (C1), and sets that cannot be undone (C3) |
| Lockstep | Everyone computes from the same commands | The game can slow down or stall | Waiting for a locked phone would stop the other person too (C2, C4) |
| Player host | The host | If the host leaves, the session is lost or moves to a new host | Each phone also holds its own record (C4) |
| Shared authority | The client that holds authority over the object | Differs by product and setting | The authority over the turn that both use is not settled |
| CRDT | The merge rule | Merged later | Convergence alone does not make the relation between sets and the turn correct |
4. The Four Structures We Built
1 · Sep 27
2 · Oct 12
3 · Oct 16
4 · Nov 17
5 · under review
4.1 Generation 1: messages exist, but nothing decides the turn (September 27)
In the first structure, the two phones sent events over Bluetooth and sent the same events to the server as well. The turn went to the person with fewer sets on the current exercise, and when the set counts were equal, the host chose who went first. The decision first lived in screen code. Until early October the engine, the Rust code that holds the product’s rules, had no concept of a turn; it began computing the turn only on October 8. The server only relayed events.
The partner file in the screen code grew from 537 lines to 2,208 lines by the October 5 audit. In the October 9 audit there were 14 types of messages. The list existed separately in about twelve places across the server, Rust, React Native, Swift, and Kotlin, and the check script verified only three of them. The three implementations that handled received messages answered the same message differently. Messages were delivered, but the meaning of shared progress was not settled in one place.
4.2 Generation 2: replicating and merging shared progress (October 12 to 14)
The second structure replicated a single shared progress onto both phones and aligned each person’s workout to it. At first, every press sent all actions so far. With eight actions, the message was 3.5KB, and sending it in seven chunks took about a third of a second. On the same day, we changed it to send only the actions the other side did not yet know.
To end the start countdown at the same moment on both phones, we needed to know the clock difference. Measuring in one direction only mixes in the transit time, so we used the four timestamps T1 to T4 of a message exchange. This is the same principle by which NTP computes the clock offset θ and the round-trip delay δ [8]. Among the measurements, we used the value from the exchange in which messages traveled fastest.
θ = ((T2 − T1) + (T3 − T4)) / 2 δ = (T4 − T1) − (T3 − T2)
We also separated sending to the server from Bluetooth communication. Previously the phone waited on the server for 0.2 to 0.3 seconds even with a good signal, and up to the 30-second request limit with a poor signal.
On October 14 we rebuilt the merge rule. Each slot was identified by the order in which the exercise entered, the person, and the set number, and for each slot the merge took whichever of the possible next states was further along. Passes, exercise selection, and ready state were also merged by maximum or union.
Open < Started < Discarded < Settled merge(a, b)[slot] = max(a[slot], b[slot])
This rule relies on the same property as the CRDT in Section 3.5. Because each slot only moves forward in order, the merged result is the same even when messages are duplicated or reordered. The change log records that this prevented cases such as a pass erasing a set that had already started or been saved, and a late start reverting a workout that had already ended.
But even when the shared progress on the two phones was the same, we still had to check separately whether it matched each person’s workout. The engine also held the position and sets of the personal workout, so we kept rewriting the personal workout to fit the merged result. When we designed the next structure on October 16, the code we counted was 760 lines for merging progress, 580 lines for aligning the personal workout to the progress, and about 1,378 lines for the partner part inside the workout session. Convergence made the two replicas equal, but it did not remove the invariants between the shared progress and the personal workout.
4.3 Generation 3: the host’s phone decides the shared progress (October 16)
The third structure tried to remove merging itself. Only the host’s phone changed the shared progress, and the other phone requested the action it wanted. At close range it had to work without a server, and the server of that time did not judge product rules, so we could not have the server decide. At design time we expected messages to drop from 14 types to 9, and the items stored in the room from about 70 to about 20. These were not values counted again after implementation.
It resembles the player host in games, but there was an important difference. In a game, the state computed by the host can be taken as the result of the game. In a partner workout, the set count the host decided, whether a set was in progress, and the current exercise also existed in each phone’s personal workout. The same fact lived in two places.
So the code that fit the host’s progress to the personal workout and the code that fit the personal workout to the host’s progress ran together every 3 seconds. The November 17 design document summarized that most defects came from this link: duplicated sets, repeated countdowns for the next set, sets that landed on a different line, and missing vibration. Finally, connection was judged only by the time a message was last received, so even a phone with nothing to send looked disconnected. When there was no response from the host, the other person could not use the buttons.
4.4 Generation 4: computing shared progress from each person’s own state (November 17)
In the fourth structure, even the host does not write the other person’s state. Each phone sends its entire state with a number v that only goes up, and accepts the other person’s state as a mirror only when its number is larger. The turn, the start, and the end are computed by the same pure function given the two states. Sharing responsibility for state resembles the approach in Section 3.4, but we have no central service managing it, and the turn is not an object that someone holds.
done(p) = counted(p) + passes(p)
turn = lifting side if one side is lifting
side with the smaller done otherwise
first chosen by the host on a tie
// if both are lifting, each phone puts its own side firstTo change the other person’s state, a phone sends a request. In the November 17 design, the request carries a set number or ID, and instead of sending a separate acknowledgment message, the sender reads the result from the other phone’s next state. The sending phone and the receiving phone decide with the same function, applies, whether a request can be applied. The 1984 end-to-end argument likewise explains that confirmation that a message reached the other machine is not enough, and that the confirmation one actually wants can only be produced by the destination application. It also said that duplicates created by the application must be filtered by the application [9]. Reading the other person’s state as the result is consistent with this view. There is no record that we designed from this paper.
We also judged connection differently. At first the app sent a signal to the server every 20 seconds to say it was open, but it could send it only while the screen was on. On the night of November 17 we removed this signal. Silence alone is no longer taken as a disconnect; we judge the phones to be unconnected only when a message that needs a reply was sent, there is no Bluetooth connection, and nothing has been heard for 10 seconds. Even when unconnected, each person can continue their own workout.
On November 23 we cut it further so that state is sent only when it changes or when a new route to the other phone opens. We removed the acknowledgment of received state, resending every 3 seconds, and clock measurement. Acknowledgment and resending remain only for requests that change the other person’s record.
This structure kept the principle “my state is held by my phone.” But the design had one more principle: “the turn is not stored; it is computed from the two people’s set counts.” The November 30 investigation named this second principle as the root cause.
The design document of the time also said that each side holding its own state is the standard for mobile cooperative games. It named features of Photon and Unity, but gave no link or citation to support the claim. In the Unity and Photon documentation we checked for this paper, we also found nothing recommending this approach for mobile. So we do not use this claim as a basis for the design.
5. The Right Principle and the Wrong Premise
A personal record and a shared turn change in different ways. A personal record can be corrected or deleted later, and it can arrive late. A shared turn must not return to an order that has already passed. Generation 4 computed a turn that must not go back from records that can change. Changes to a record, and even the order in which requests arrived, became problems for the turn.
The November 30 investigation counted 19 values that decide the current exercise and turn. Separately, there were 3 values used for the start signal. The investigation grouped the causes of the problem into the following three relations.
| Relation | What this relation made necessary |
|---|---|
| The turn is computed from personal set counts | A mirror of the other person’s set count, a calculation that also adds requests not yet applied, passed turns, restrictions when correcting a set, and a turn that advances only after the record is saved |
| A personal workout can refuse a move of the shared exercise | Comparing shared progress with the personal workout and realigning them, a state of waiting for the previous set to finish, and a request to finish without recording |
| A set’s ID is created when the set ends | Guessing the set in progress from its number and the workout’s version, and judging a request stale even after a change unrelated to that set |
There were also two people who could start an exercise. Each decision carried a number, the larger number won, and when the numbers were equal the host’s decision was followed. This is consistent as a way of putting simultaneous events into one order. Lamport’s total order also breaks ties between equal clock values by a predetermined process order. But as an interpretation, there is no guarantee that this order is the same as the order the two people agreed on by voice [7]. No defect caused by this difference is recorded.
6. What Verification Checked
6.1 The model and mutations
We wrote the generation 4 rules as a Quint model. A model is an executable spec of the rules. We also put message loss, duplication, reordering, and app termination into the model. For example, we checked the following conditions.
- SetOnce: a set with the same number in the same exercise for one person is recorded only once.
- MirrorNeverOlder: the mirror of the other person’s state never goes back to an earlier number.
- NoSilentLoss: a set written for the other person must remain in one of the states the model defines, and must not vanish without explanation. The model also has a state in which a set is closed without being recorded. So this does not mean every set is recorded.
- TurnAgrees: when the two phones know each other’s latest state and no request is waiting to be reflected, they compute the same turn, except when both people are doing a set.
We also deliberately changed the model’s rules one line at a time and checked whether the conditions detect the violation. For the parts where the design changed, we newly checked with mutations M1 through M15 and M2b. For each run we fixed a seed and ran randomly 10,000 or 20,000 times, up to 40 to 50 steps, and each mutation was caught by at least one of the model’s conditions. Because the runs are random, this does not mean every sequence was checked. We did not rerun the old mutations of rules that were not changed at that time, and we also found no record of rerunning the mutations after the November 23 change. After that, we also ran the sequences the model produced on the real engine and compared the results.
TurnAgrees is a condition for when the two phones know each other’s latest state and no request is waiting to be reflected. It does not mean the two phones compute the same turn before a message arrives. Also, this model started from the rule “the turn is computed from set counts.” We could check whether the engine follows that rule, but we could not check whether that rule should be used. Whether the rule fits the product was not a question for this verification. Nor can we say that passing the model’s conditions prevented every loss of records in real use.
6.2 Failures that cannot occur in practice
On November 30 we also found the opposite problem. One replay produced a sequence in which a record written for the other person arrives during the start countdown. A replay is a check that runs the sequences produced by the model on the real engine. In the real app the record button did not appear at that moment; the situation arose because the replay was advancing the clock.
So when a replay fails, we first write in one sentence who creates that situation, with which button or message, and in what order. If we cannot write the sentence, we do not add defensive code to the engine; we fix the model and the replay. A model can miss something that is possible, and it can also create something that is actually impossible.
7. The Fifth Structure Under Review
7.1 Shared progress as a single value
The structure under review does not compute shared progress from personal records; it keeps it apart as one small value.
Play = { n, block, first, turn, over }n is the number of the run the host started, block is the exercise, and first is the person who goes first. turn is the number of turns that have already passed. If it is even, it is first’s turn; if odd, it is the other person’s turn. over says whether this run is open or, if it is closed, for what reason. Only the host can create a new run, so for a given n there is only one block and one first.
When merging two values, we pick the run with the larger n. When n is equal, we pick the larger turn, and a closed run is never reopened. If two sides closed it at the same time for different reasons, we pick one by a fixed order.
merge(a, b) = a if a.n > b.n
= b if b.n > a.n
= { n: a.n,
block: a.block,
first: a.first,
turn: max(a.turn, b.turn),
over: max(a.over, b.over) } if a.n = b.n
// Open comes first in the fixed order of `over`Only the host creates a new n, and keeping block and first unchanged for the same n is something the write rule, not the merge, must guarantee. Under this rule, if block and first are always the same for the same n and the order of over is fixed, this merge forms a join semilattice: when n differs, the larger side is the least upper bound of the two values, and when n is equal, the larger value of turn and of over, each taken separately, is the least upper bound. So the order or repetition of merges does not change the result. When n differs, the turn and over of the smaller side are discarded together. For the two phones to actually converge, each phone must change values only forward in this order, and every value must eventually be delivered. This proof covers only the merge of Play. It does not prove the relation to the personal workout, or devices and communication.
The button does not send “raise the turn by one.” It states the fact that “turn k of run n has passed.” It changes turn to k+1 only when the current turn is k. Even if both people pass the same turn at the same time, it passes only once. An action that adds one gives a different result when repeated, but if an already passed turn is stated as the same value, the result is the same however many times it is heard.
7.2 Name the set before it starts
A turn and a set are different. A turn can be passed without doing a set, and a set that was started can be canceled and started again. So we do not build the set ID from the numbers of the run and the turn. The phone of the person who will do the set creates the ID of the next set in advance. The start request and the record request specify this ID.
A start request is applied only when the requested turn is still the current one, its set ID equals the receiving phone’s next set ID, and there is no set in progress and no open logging window. A record request is applied only to a set its owner has neither recorded nor canceled. If the exercise cannot be found or the joint workout has ended, nothing is recorded. The shared progress does not change records, and correcting or deleting a record does not roll back a turn that has passed.
We keep the current position of the personal workout. Removing even this value would make a solo workout depend on the partner room. Instead, when the shared progress changes, the personal position is also changed once, in the same save. The open logging window is separated from the exercise position, so that being in the middle of logging does not block the shared exercise from moving.
7.3 Results of a small search
We searched only the core rules with a small Rust program. A sent message could arrive any number of times, in any order, or never. The bounds are 2 runs, 2 turn passes, 6 set IDs per person, and at most 10 steps. Separately, we checked the merge over 48 values, reduced by leaving out block and first and using 4 values of n, 4 of turn, and 3 of over; in every combination the result was the same whether the order was changed or merges were repeated.
| What we checked | Result |
|---|---|
| States | 2,417,373 |
| Actions | 5,705,261 |
| Violations of the stated conditions | None |
| Records written for the other person that were applied late | 154,325 |
| Of those, applied to an open logging window | 93,464 |
| Of those, applied after moving on to the next set ID | 26,890 |
| Starts made for the other person that were applied | 10,730 |
| Wrong rules we deliberately inserted | All 8 found |
The first draft of the design did not pass. When a record request was compared only with the current set ID or the open logging window, the search program found, within five steps, a sequence that loses a record. So we changed the rule to reject only requests for sets that were already recorded or canceled.
“No violations” holds only within the stated bounds and 10 steps. We did not include start and ready, rest and timing, the end of a workout, record corrections and comments, adding and deleting exercises, recovery after the app is restarted, the lock screen, and the watch. This search program also did not check the real engine, the Quint model, the screens, Bluetooth, or the server. This result is not a proof of safety; it means we found no counterexample within the stated bounds.
7.4 What shrinks and what grows
The following values are expectations from before implementation. Not every item shrinks. The values that decide a personal set actually grow by one, and the canceled set IDs must also be kept in the room.
| Item | Structure at the time of the investigation | Structure under review (expected) |
|---|---|---|
| Values that decide the exercise and the turn | 19 | 5 |
| Values used only for the start signal | 3 | 0 |
| Types of requests sent to the other person | 4 | 2 |
| Fields in the mirror of the other person’s state | 13 | 11 |
| Types of messages | 10 | 10 |
| Values of a personal set | 5 | 6, plus canceled set IDs added to the room |
Separately from the search, on November 30 we put an implementation of this direction into the product code and the model, but did not release it. On re-examination we did not settle on it as the final structure. The values in the table above are not measurements of this implementation. Later experiments are being done separate from the product code. The condition is to keep every feature of the partner workout and change only the structure.
8. Comparing the Five Structures
| Structure | Where shared progress is decided | Turn | Limit identified |
|---|---|---|---|
| Generation 1 (September 27) | Screen code on both phones | Computed from set counts | Message handling and decisions split across several implementations |
| Generation 2 (October 12) | The replicas on both phones | Computed from the merged shared progress | Shared progress and the personal workout must keep being aligned |
| Generation 3 (October 16) | The host’s phone | The host’s shared progress | The same facts duplicated in the personal workout, and the other person cannot operate if the host does not respond |
| Generation 4 (November 17) | The same function given both states | Computed from set counts and passed turns | Personal records that can be corrected affect the turn |
| Generation 5 (under review) | A single mergeable Play value | The passed-turn count turn | Not a final structure confirmed on the real engine and two devices |
The six principles we drew from this process are below. These principles are our interpretation of our own experience; they are not an experimental result showing that they necessarily hold in other systems.
- Authority is assigned fact by fact, not for the workout as a whole. Authority over my record and authority over the shared turn are different.
- Convergence and correctness are different. We check separately the rule that makes values equal and the conditions the value must satisfy.
- A derived value inherits the properties of its source. A value that must never go back is not computed from values that can change or be deleted.
- Name facts rather than actions. Writing “turn k of run n has passed” instead of “add one” keeps the meaning the same when repeated.
- Silence is not evidence of failure. Connection is judged by whether a reply actually came to a message that needs one.
- Doubt the rules being verified too. A model can check that code follows a rule, but a person must check that the rule fits the product.
9. Limits of This Paper
- There is no experiment comparing error rate, latency, or battery across the five structures on the same devices and conditions.
- In the records we reviewed, we did not find results of systematically checking each of the four structures on two real phones. On November 29 we checked by connecting a simulator and one real phone over QR, but the Bluetooth connection was not used.
- For the causes of defects, we followed the judgments of the design documents and code audits. It is not an experiment that changed each cause one at a time and compared.
- Line counts and item counts are values for understanding the structures. Because the points and scopes of counting differ, they cannot be used to compare the quality of the structures directly.
- The four structures were built with two people as the basis. For three or more people, only a strategy was set in October and nothing was implemented. The even and odd rule of turn under review also fits only two people.
- The fifth structure is still under review. It cannot be adopted on the search results of this paper alone.
10. Conclusion
In a turn-based game, an authoritative state decides the next turn and can reject a move that does not fit. In a partner workout, the set happens first outside the app, the records belong to each person, and the two phones can stay disconnected for a long time. So instead of taking over a game’s structure as is, we had to begin by separating what is a shared fact and what is a personal fact.
The four designs moved in the direction of merging values, narrowing the deciding phone to one, and separating each person’s state. The November 30 investigation named three relations as root causes: the turn was computed from personal records, a personal workout could refuse a move of the shared exercise, and a set had no name when it started. This paper centered on the definition of the turn among them. We are now examining a structure that treats the turn not as a result computed from personal records, but as an independent fact that the two people hold together.
References
[1] Apple Developer Documentation, GameKit: GKTurnBasedMatch; Starting turn-based matches and passing turns between players; Turn timeouts. developer.apple.com
[2] boardgame.io documentation: Multiplayer; Turn Order; Concepts. boardgame.io
[3] P. Bettner, M. Terrano. 1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond, 2001. www.gamedeveloper.com
[4] Unity, Netcode for GameObjects: Network topologies (2.6); Distributed authority topologies (2.11). docs.unity3d.com
[5] Photon Engine, Fusion 1: Introduction; Host Migration. doc.photonengine.com
[6] M. Shapiro, N. Preguiça, C. Baquero, M. Zawirski. Conflict-free Replicated Data Types. INRIA Research Report RR-7687, 2011. inria.hal.science
[7] L. Lamport. Time, Clocks, and the Ordering of Events in a Distributed System. Communications of the ACM 21(7), 1978. lamport.azurewebsites.net
[8] D. Mills, J. Martin, J. Burbank, W. Kasch. Network Time Protocol Version 4. RFC 5905, 2010. www.rfc-editor.org
[9] J. H. Saltzer, D. P. Reed, D. D. Clark. End-to-End Arguments in System Design. ACM Transactions on Computer Systems 2(4), 1984. web.mit.edu
