Skip to content

id(web): apply collab steps against a document model before storing - #16787

Merged
developing-today-fleet[bot] merged 1 commit into
mainfrom
xaltha/1618-collab-apply-validation
Nov 29, 2026
Merged

developing-today-fleet[bot] merged 1 commit into
mainfrom
xaltha/1618-collab-apply-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Final stage of #1618 (slices 1–10 validated steps in isolation; this slice validates them against the document itself).

What

Document now carries a DocModel: a token model (open/close/text/leaf tokens with mark types) of the base document, evolved only by accepted steps. try_apply_steps replays each batch through check_steps_in_doc, which runs the existing per-step validation and then applies the step to the model, mirroring prosemirror-transform's Step.apply / prosemirror-model's replace machinery (oracle-verified against prosemirror-model 1.25.13 / transform 1.10.4, the versions the editor ships):

  • replace: the open-depth equation against the positions' real depths, join compatibility (compatibleContent) where slice chains meet document nodes — including the cross-depth case where the prepared slice joins through the from side's ancestors — and full validContent checks (content expression with counts/order, plus child marks vs the parent's mark set) on every rebuilt node;
  • structure: true replaces refuse when the range contains content (contentBetween token rule);
  • replaceAround: gap flatness, Slice.insertAt/canReplace fit of the gap content, then the composite replace;
  • addMark/removeMark: the model tracks marks exactly as the mark steps rewrite them (parent mark-set admission for addMark; slice-wide stripping for removeMark);
  • addNodeMark/removeNodeMark: routed through the replace machinery with the rebuilt empty-content node, so a mark on a top-level block is refused by the document node's empty mark set;
  • attr: nodeAt existence, text-node refusal, and declared-attr type checks (heading level / ordered_list order numeric, image src a string).

A refused step stores nothing, broadcasts nothing, and leaves version, content size and model untouched — so acceptance criteria 1 and 2 of #1618 are now met: steps are validated against the server's actual document state (base doc + accepted steps), and a step that does not parse or does not apply is refused.

Tests

Eight new unit tests in collab_steps.rs port the oracle probe cases (each refusal paired with valid controls), plus model-equality assertions for mark steps and step-by-step batch semantics. Existing collab suites unchanged.

Closes #1618

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-29T13:12:39Z",
    "session_id": null,
    "lane": null,
    "host": "htch-runtime",
    "worktree": "/home/hatch/workspace/github-work/w0647-l03",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/hatch/workspace/github-work/w0647-l03",
      "repo": "developing-today/code",
      "branch": "xaltha/1618-collab-apply-validation",
      "sha": "c7aaf47075cdaeb9fe9785b544e4ab4530fceb10"
    },
    "auth_subject": "xaltha",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…1618)

The collab server now keeps a token model of the document — the
base document plus every accepted step — and replays each step
against it the way ProseMirror's Step.apply would, refusing what
every receiving client would refuse: open depths that do not line
up with the replaced range, joins between incompatible node
types, rebuilt nodes whose content (or whose children's marks)
their type does not admit, structure replaces over content,
replaceAround gaps that are not flat or whose content does not
fit, and attr/node-mark steps naming no node, a text node, or a
wrongly-typed attr value. This completes the acceptance criteria
of #1618: a step that does not parse or does not apply is refused
with no Ack, nothing stored or broadcast, and the version frozen.
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac47dc4f-83c8-4dc7-8f6c-a9e9fc760496
Commits

Reviewing files that changed from the base of the PR and between 083cb2a and c7aaf47.

Files selected for processing: 2

  • pkgs/id/crates/id-web/src/collab.rs
  • pkgs/id/crates/id-web/src/collab_steps.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

id(web): collab server stores and broadcasts steps it never validates — one bad step poisons the document's history and loops every client

1 participant