A useful failure to test in a workout journal is one where the set is already on disk when the caller sees an error. From the keyboard, that looks like a failed save. From the database, it looks like a finished write. If my next click constructs a new set, it can record the same five reps again. The weight, exercise, and date are poor ways to detect that. Two legitimate sets in the same workout often have identical values.
Keep the identity before sending the request
On the first tap, the mobile workspace builds a LogSetRequest. The request carries a generated client ID and a snapshot of the reps, unit, and plate stacks. The workspace persists it as pending before it calls the journal. The next tap after an uncertain save reuses the original request. While it is pending, the UI locks the draft. Editing the reps under the same ID would make it ambiguous which set the ID referred to. The request type · The mobile save command
The persistence rule has to reach the API. Connected mode posts to the existing SQLite-backed journal, where ClientId has a unique index. The service checks for the ID and the database also enforces uniqueness, which covers overlapping attempts that both pass the preliminary query. The workout row has a separate revision token for concurrent session changes. These are different failure cases. A conflict can mean a replay of this set, or it can mean that the journal changed while the request was in flight. The set insert · The index and revision token · HTTP conflict mapping
A conflict is a reason to read again
On a conflict, the mobile workspace reloads the journal and looks for the pending client ID. If it finds it, there’s a saved set to show. If the set is absent, the original conflict still propagates. Startup and manual refresh also look for the ID before clearing pending state. In the API integration test, two posts of the same request produce a success and a 409. A fresh read returns a single set. The API replay test · Startup and refresh reconciliation
| Situation | What the next read can establish |
|---|---|
| The original write failed before saving the set | The ID is absent. A retry can submit the same request. |
| The original write committed before an error reached the app | The ID is present. The app can show the saved set. |
| A different edit caused a conflict | The conflict itself gives no evidence the pending ID was saved. |
Make the failure happen on the right side of the write
The mobile test wraps the local store. It lets a real journal write succeed in the underlying test store and only then throws an IOException. The first workspace reports an error and keeps its pending ID. A fresh workspace opens the same store, finds the ID, and shows one 205 lb set. That test is stronger than an adapter that simply throws on every call. The latter only exercises the first row of the table. The interrupted-write test and store · The commit-then-throw adapter
The identity in this example belongs to a set. A new workout session is created in a separate call before the app submits its first set. That gives the test a precise boundary. Even if the caller loses the outcome of the set write, it can still ask whether that set exists. Session creation and the pending set