Skip to content
Text size
Text size

Offline work and sync

The task example includes a test that creates two local devices, changes each independently and then synchronises them.

A device needs the relevant domain rules, data and permissions before it can work offline. This test creates a task on Alice’s device, then creates Bob’s device from that state:

const alice = await testHolon({ law, deterministic: true });
const aliceApp = alice.app(tasksClient, { actor: "person:alice" });
const { task } = await aliceApp.addTask({ text: "Inspect the pump" });
const bob = await alice.device();
const bobApp = bob.app(tasksClient, { actor: "person:bob" });

device() is a test-harness operation that starts another local runtime from the current state. Both devices begin with the same task. This setup does not model a new user signing in for the first time without a connection.

await aliceApp.tagTask({ task, tags: ["inspection"] });
await bobApp.tagTask({ task, tags: ["maintenance"] });

No sync occurs between these calls. Alice sees inspection; Bob sees maintenance. The test asserts both intermediate results.

await alice.sync(bob);
const aliceTask = await aliceApp.tasks.find(task);
const bobTask = await bobApp.tasks.find(task);

Both records now contain inspection and maintenance. The test compares the records and checks that a second sync sends and receives no new changes.

This result follows from the field’s merge policy:

tags: t.set(t.string()).merge(AddWins)

Concurrent additions are retained. For a scalar field using Lww, competing changes resolve to one winning value. Convergence means the devices agree on the result; it does not mean every competing value remains visible.

A local action can succeed while the device is disconnected. Another participant will see it only after changes have been exchanged and processed.

For an application, distinguish:

  • Saved locally: the local action succeeded.
  • Waiting to sync: changes have not yet reached the other participants.
  • Sync or validation needs attention: show the actual failure or required decision.

A working network connection alone does not prove that all changes have arrived. Use your platform client’s reported state rather than a browser’s online flag to present progress.

The test uses real local runtimes and a test-harness exchange. It checks independent writes and convergence under the declared merge policy. It does not check mobile background execution, physical network interruption, device enrolment or a production reconnect interface. Test those journeys through your chosen platform host as part of application acceptance.