🐛 Transform every pending op by each fixup op - #718
Open
alecgibson wants to merge 1 commit into
Open
Conversation
Fixes #717 At the moment, when the server acknowledges an op carrying fixup ops, `Doc._opAcknowledged()` loops over `pendingOps` with an inner index `j`, but indexes the array with `i` — the outer loop variable, which enumerates the fixup ops instead. Since `transformX()` mutates both of its arguments in place, this isn't a harmless redundant pass. We transform `pendingOps[0]` once per pending op rather than once, and never transform `pendingOps[1]` onwards at all, so the client and the server end up disagreeing about the order of the remaining pending ops. Worse, if there are more fixup ops than pending ops, we hand `undefined` to `transformX()`, which throws a `TypeError` that escapes all the way out of `Connection.handleMessage()`. The existing tests all miss this, since they have at most one fixup op and one pending op, where `i` and `j` are both always `0`. This change indexes `pendingOps` with the inner loop variable, and renames both variables to `fixupIndex` and `pendingIndex` so the two can't be confused again. The equivalent loop in `Doc._handleOp()` was already correct. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
alecgibson
marked this pull request as ready for review
July 31, 2026 13:26
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.
Fixes #717
At the moment, when the server acknowledges an op carrying fixup ops,
Doc._opAcknowledged()loops overpendingOpswith an inner indexj, but indexes the array withi— the outer loop variable, which enumerates the fixup ops instead.Since
transformX()mutates both of its arguments in place, this isn't a harmless redundant pass. We transformpendingOps[0]once per pending op rather than once, and never transformpendingOps[1]onwards at all, so the client and the server end up disagreeing about the order of the remaining pending ops. Worse, if there are more fixup ops than pending ops, we handundefinedtotransformX(), which throws aTypeErrorthat escapes all the way out ofConnection.handleMessage().The existing tests all miss this, since they have at most one fixup op and one pending op, where
iandjare both always0.This change indexes
pendingOpswith the inner loop variable, and renames both variables tofixupIndexandpendingIndexso the two can't be confused again. The equivalent loop inDoc._handleOp()was already correct.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com