# Testing for lost edits after a LiveView reconnect

A LiveView reconnect can bring back an old draft while the server loads a teammate's newer edit. If Save checks against the version the server just loaded, the old draft can pass the optimistic lock check.

We test for this in Kogen Studio, the multiplayer workspace we're building for our software factory. An overwritten edit there can change the instructions an agent gets on its next task. In this test, someone else has already saved when the draft comes back:

```elixir
render_hook(project_view, "recover_contexts", %{
  "project" => "Offline project draft",
  "versions" => %{"project" => "0"}
})

refused = submit(project_view, "project", "Offline project draft")
assert refused.status == "Not saved: changed by someone else"
assert refused.current == "Competing project"
assert refused.draft == "Offline project draft"
```

The draft carries the version it started from. Save checks that version against the database, so Studio can keep the draft and show the teammate's saved edit when they conflict.

If you use LiveView's built-in form recovery, a hidden field lets you recover that version along with the text.

https://hexdocs.pm/phoenix_live_view/form-bindings.html#recovery-following-crashes-or-disconnects

---

Created by: almirsarajcic
Date: November 29, 2026
URL: https://elixirdrops.net/d/vg43bMm9
