You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reject stale document saves instead of overwriting another editor #200
area: docs-featureThe docs product and its editorarea: realtimeThe socket, the hub, scopes and fan-outbugSomething is brokenp1 highBlocks real work, fix this weekpoints: 5Fibonacci estimate: 5readyScoped, agreed, and safe to pick upschema changeAdds, drops or alters a table. Migrations are applied by hand before the code shipssize: mediumA day or two. One surface, no new model
Two clients can still save the full document body over each other. Serializing autosaves within one tab and keeping document history do not reject a stale save from another tab. The agreed scope is conflict detection; collaborative editing, Yjs and cursor presence are outside this issue.
Add a document revision and require the client to submit the revision it edited. Check it atomically on the server, reject a stale save without overwriting current content, and show the conflict while preserving the local draft. Cover two clients saving from the same revision, a normal save, retry/reload behavior, permissions and the conflict UI.
Start with packages/core/src/content/doc-service.ts, the shared document validator and route, and apps/web/src/features/docs/use-autosave.ts. Related: #199.
Re-scoping to the smaller alternative and treating it as a p1 bug: a revision on doc, a save whose base revision is stale is refused, and the editor shows the other person's changes instead of overwriting them. That stops the data loss today. Full collaborative editing over Yjs stays out of this issue; if someone wants it, open a design issue for the transport and persistence questions above.
changed the title [-]Two people editing the same doc lose each other's work[/-][+]Reject stale document saves instead of overwriting another editor[/+]on Sep 22, 2026
Taking this one. The rescoped shape is clear: the doc carries a revision, the editor sends the revision its draft was built on, and a save whose base is stale is refused instead of overwriting the other tab's body.
Plan:
revision column on doc + migration, bumped only when the body changes, so a rename does not refuse an in-flight body save.
baseRevision on the shared doc update validator; a compare-and-swap WHERE id = ? AND revision = ? inside updateDoc, with the stale case returning a conflict that carries the current revision.
doc-surface / use-autosave send the base revision the draft was built on and show the conflict while keeping the local draft in the editor, with an explicit "load their version" action.
Tests: two clients saving from the same revision (second refused, stored body intact), a normal save advancing the revision, a save without a base still working, plus the web-side conflict notice.
This is implemented in #571, following the rescoped shape on this thread.
doc.revision with migration 0032, advanced only when the body changes, so a rename does not refuse an in-flight body save.
updateDoc takes baseRevision and puts it in the update's own WHERE, so the compare and the write are one statement. A stale base changes no row and answers conflict with details: { reason: 'stale_revision', revision }.
The editor sends the revision its draft was built on, keeps the draft when the save is refused, and shows the notice with a Load their version action.
restoreDocVersion advances the revision when the restored content differs.
Core tests cover the two-client race, the normal save, the retry, the rename, a save with no base, and the restore. The core suite needs bun run db:test-setup, which this box cannot run (no Docker, no Postgres), so CI is their first run. The web docs suite passes locally with the four new hook tests.
area: docs-featureThe docs product and its editorarea: realtimeThe socket, the hub, scopes and fan-outbugSomething is brokenp1 highBlocks real work, fix this weekpoints: 5Fibonacci estimate: 5readyScoped, agreed, and safe to pick upschema changeAdds, drops or alters a table. Migrations are applied by hand before the code shipssize: mediumA day or two. One surface, no new model
Activity
imshashank commentedon Sep 6, 2026
Re-scoping to the smaller alternative and treating it as a p1 bug: a revision on
doc, a save whose base revision is stale is refused, and the editor shows the other person's changes instead of overwriting them. That stops the data loss today. Full collaborative editing over Yjs stays out of this issue; if someone wants it, open a design issue for the transport and persistence questions above.[-]Two people editing the same doc lose each other's work[/-][+]Reject stale document saves instead of overwriting another editor[/+]ayam04 commentedon Oct 17, 2026
Taking this one. The rescoped shape is clear: the doc carries a
revision, the editor sends the revision its draft was built on, and a save whose base is stale is refused instead of overwriting the other tab's body.Plan:
revisioncolumn ondoc+ migration, bumped only when the body changes, so a rename does not refuse an in-flight body save.baseRevisionon the shared doc update validator; a compare-and-swapWHERE id = ? AND revision = ?insideupdateDoc, with the stale case returning a conflict that carries the current revision.doc-surface/use-autosavesend the base revision the draft was built on and show the conflict while keeping the local draft in the editor, with an explicit "load their version" action.Tests: two clients saving from the same revision (second refused, stored body intact), a normal save advancing the revision, a save without a base still working, plus the web-side conflict notice.
ayam04 commentedon Nov 8, 2026
This is implemented in #571, following the rescoped shape on this thread.
doc.revisionwith migration0032, advanced only when the body changes, so a rename does not refuse an in-flight body save.updateDoctakesbaseRevisionand puts it in the update's ownWHERE, so the compare and the write are one statement. A stale base changes no row and answersconflictwithdetails: { reason: 'stale_revision', revision }.restoreDocVersionadvances the revision when the restored content differs.Core tests cover the two-client race, the normal save, the retry, the rename, a save with no base, and the restore. The core suite needs
bun run db:test-setup, which this box cannot run (no Docker, no Postgres), so CI is their first run. The web docs suite passes locally with the four new hook tests.