Skip to content

fix: handle incompatible operation lengths during client synchronization#92

Merged
MrSurana merged 12 commits intomainfrom
fix/SUPP-1996
Mar 31, 2026
Merged

fix: handle incompatible operation lengths during client synchronization#92
MrSurana merged 12 commits intomainfrom
fix/SUPP-1996

Conversation

@khush2706
Copy link
Copy Markdown

@khush2706 khush2706 commented Mar 11, 2026

Description

Issue
Windows dictation/IME input in Monaco intermittently caused Firepad to throw OT validation errors such as:

The base length of the second operation has to be the target length of the first operation
sendOperation() called with invalid operation
This broke collaboration sync for affected typing sessions.

Root Cause
MonacoAdapter converts Monaco content-change events into OT operations.
For some IME/dictation change batches, the generated operation did not exactly represent the actual document transition (previous content -> current content). Once that malformed operation entered the OT pipeline, compose/merge invariants failed and eventually surfaced as invalid outgoing operations in the Firebase adapter.

In short: the failure was caused by incorrect operation construction from certain Monaco IME change batches, not by Firebase itself.

Fix
Hardened MonacoAdapter operation generation with validation + fallback:

  • Build operations from Monaco change batches as before.
  • Validate the generated operation by applying it to previous content and verifying it matches the editor’s current content.
  • If validation fails (or change-batch conversion throws), fall back to a robust diff-based operation built from full previous/current content (common prefix/suffix + middle replace).
  • Preserve inverse operation generation for undo/redo compatibility.
  • Avoid mutating Monaco’s incoming changes array by sorting a copy (Array.from(changes).sort(...)).

Result
IME/dictation edits now always produce valid OT operations, preventing downstream compose/send invariant failures and keeping collaborative sync stable.

@MrSurana MrSurana self-requested a review March 24, 2026 07:10
@khush2706 khush2706 requested a review from devsebastian March 27, 2026 05:05
package.json Outdated
"name": "@hackerrank/firepad",
"description": "Collaborative text editing powered by Firebase",
"version": "0.8.5",
"version": "0.8.5-alpha",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@devsebastian I can change the version name to 0.8.6, is that fine?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Will have to keep this as -alpha, getting this error otherwise

Comment on lines +16 to +17
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

are these required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, was getting this error otherwise

@MrSurana MrSurana merged commit f49ef15 into main Mar 31, 2026
1 check passed
@MrSurana MrSurana deleted the fix/SUPP-1996 branch March 31, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants