Skip to content

docs(openspec): propose data node and value operations - #211

Open
gohabereg wants to merge 4 commits into
docs/openspec-fix-ot-client-convergencefrom
docs/openspec-add-data-node-operations
Open

gohabereg wants to merge 4 commits into
docs/openspec-fix-ot-client-convergencefrom
docs/openspec-add-data-node-operations

Conversation

@gohabereg

Copy link
Copy Markdown
Member

What

Planning only: the add-data-node-operations OpenSpec change. It is stacked on #210, so review that one first.

Why

Data-node and value changes (DataNodeAddedEvent, DataNodeRemovedEvent, ValueModifiedEvent) stay local today: they aren't sent to collaborators and can't be undone. The v3 List tool depends on all of them, because it stores items as one flat array: items: [{ content, depth, checked? }]. Tab and checkbox toggles are updateValue, Enter inserts an array element, and a Backspace merge removes one.

What changes (summary)

  • Model
    • Explicit createDataNode dispatches synchronously, with the author's userId. Today the event has none.
    • Data nodes created while a block is being built are marked isInitialization. Undo and collaboration skip them; adapters still get them, so data-first rendering keeps working.
    • modifyData handles DataIndex.
    • insertData on an existing object key replaces the node.
  • Collaboration
    • The three events become Insert/Delete (payload: [subtree]) and Modify (payload / prevPayload).
    • New transformer rules for array positions: numeric key segments are array indices. Data and text operations inside a shifted element are re-keyed; operations inside a deleted element become Neutral.
    • Same-position ties and same-key conflicts use the explicit transform order from docs(openspec): propose fix for OT client/server divergence #210.
  • Undo works in both the core and collaboration managers once the model replays these changes.

Out of scope

🤖 Generated with Claude Code

Sync and undo for DataNodeAdded/DataNodeRemoved/ValueModified, with
array-position transform rules. Depends on fix-ot-client-convergence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gohabereg
gohabereg force-pushed the docs/openspec-add-data-node-operations branch from e6d4bd2 to cf3df7f Compare October 17, 2026 18:11
### D6. Same-key conflicts that do not shift

- **Modify vs. Modify, same block and key.** Last-writer-wins in server order: `op` becomes `Neutral` iff `against` comes later (`againstIsLater`). Otherwise `op` is kept and applied after `against`. This is the rule `fix-ot-client-convergence` sets for values.
- **Insert vs. Insert on the same object key** (last segment not an integer). The same rule as Modify. With replace-on-insert (D4), the later write in server order wins on the server and on every client, exactly as for values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For concurrent inserts at meta ({url: 'a'}) and meta.url ('b'), processing meta first leaves the server at b, but its broadcast overwrites the second client's pending b with a. Define ancestor/descendant conflicts for replace-on-insert as well as exact-key ties.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a concurrent Insert at meta ({url: 'a'}) and a Delete at meta, processing the Insert first leaves the server without meta, but the deleting client re-creates it from the broadcast. A write must also beat a Delete, or a text operation, at its own key, not only under it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a case for each combination

gohabereg and others added 2 commits November 20, 2026 22:57
Address review on add-data-node-operations:

- D6 only resolved writes on the exact same key. A concurrent insert at
  `meta` and at `meta.url` diverged between the server and the client
  that sent `meta.url`. A write that replaces a key now wins over any
  operation under that key in either order, as deleting it would.
- UndoRedoManager transforms every stack entry against the same remote
  operation, although only the newest entry was recorded in the current
  document, so a second undo can delete a remote element (or remote text,
  which already happens today). D8 rebases the stacks from the newest
  entry to the oldest, carrying the remote operation back past each one.
- Task 4.6 adds its cases to the convergence spec that
  fix-ot-client-convergence now creates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gohabereg
gohabereg requested a review from Reversean November 20, 2026 23:07
Address review on add-data-node-operations: a concurrent Insert and
Delete at the same object key diverged, because D5 kept the Insert
against the Delete but nothing neutralized the Delete against the
Insert. The same gap let a text edit at a replaced key diverge.

At the same object key, a write (Insert or Modify) now wins over a
Delete or text operation in both directions, so D5's exception keeps a
Modify too. D6 is restated by depth: the shallower key wins, two writes
at the same key stay last-writer-wins, and array positions follow D5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants