fix(collab): stop /documents/:slug/ops replaying stale DB markdown into live rooms#68
Open
devYRPauli wants to merge 1 commit into
Open
fix(collab): stop /documents/:slug/ops replaying stale DB markdown into live rooms#68devYRPauli wants to merge 1 commit into
devYRPauli wants to merge 1 commit into
Conversation
…to live rooms After a non-rewrite.apply op succeeds, the route reapplied the persisted DB row into the live collab room with source 'rest-ops'. Unlike other server-side write sources, 'rest-ops' is not covered by the legacy live-apply guard (shouldBlockLegacyLiveApplySource), so a point-in-time DB snapshot could replay stale markdown over concurrent live edits that were not yet persisted. Engine-backed (non-rewrite.apply) ops now only refresh the narrow presence/cursor coupling and no longer push a broad DB snapshot into the live room; rewrite.apply continues to commit through the canonical Yjs path. This restores the collab-security invariant that /documents/:slug/ops avoids a broad DB reapply after engine-backed mutations. Fixes EveryInc#63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
POST /documents/:slug/opsreapplies the persisted DB row into the live collab room after any non-rewrite.applymutation, usingsource: 'rest-ops':Unlike every other server-side write source,
rest-opsis not covered byshouldBlockLegacyLiveApplySource, so this reapply is not blocked when a live shared doc is present. A point-in-time DB snapshot can then replay stale markdown over concurrent edits that are not yet persisted.The repo's own
collab-securityinvariant already asserts this reapply should be gone, so that check fails onmain:Fix
Engine-backed (non-
rewrite.apply) ops now only refresh the narrow presence/cursor coupling and no longer push a broad DB snapshot into the live room.rewrite.applycontinues to commit through the canonical Yjs path, and the trailingdocument.updatedbroadcast still notifies live clients. This mirrors the pattern the agent routes and bridge already follow (presence/verification sync, no broad reapply).Verification
The
collab-securityinvariant for this reapply flips from failing to passing:main):routesSource.includes("source: 'rest-ops'")istrue, assertion failssource: 'rest-ops'reapply is gone and the explanatory comment is present, assertion passestsc --noEmit -p tsconfig.server.jsonreports 0 errors before and after (no new type errors). The change is 6 insertions / 8 deletions in one file.Fixes #63