fix: crash-proof concurrent PT editing over the SDK operational patch channel (stacks #2974 + #2975 + #2977)#2978
Draft
snorrees wants to merge 11 commits into
Draft
fix: crash-proof concurrent PT editing over the SDK operational patch channel (stacks #2974 + #2975 + #2977)#2978snorrees wants to merge 11 commits into
snorrees wants to merge 11 commits into
Conversation
Guard updateBlock keyed unsets against the live engine tree and widen the updateValue try/catch so a stale-key removal degrades to a safe re-sync instead of an unhandled rejection that freezes the sync actor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…f paths arrayifyPath returns null instead of throwing on unexpected diff-patch paths (e.g. array slices from clearing multiple marks); convertPatches drops unconvertible ops and flags the batch incomplete; applySync then falls back to an authoritative full value update / resync. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Credits #2974 for the engine routing fix and documents our residual (updateValue try/catch widening + arrayifyPath/slice resilience).
…remote patches as data patches
…nc + plugin resilience
…pair-divergence # Conflicts: # packages/plugin-sdk-value/src/plugin.sdk-value.tsx # packages/plugin-sdk-value/src/plugin.value-sync.browser.test.tsx
Remote patch batches were applied best-effort, one op at a time: a concurrent client's operational patch that unsets a span _key this editor already changed throws `node was not found` inside apply-operation, and the batch was applying partially — diverging the editors. Under the operational patch channel (#2977) this crashes on concurrent formatting. Make a remote patch batch atomic: if any op throws, roll the whole batch back to the pre-batch value and let the whole-value sync reconcile — never a crash, never a half-applied tree. applyPatch stops swallowing errors so the batch handler can see the failure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 97ae00e The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 803.6 KB | +3.6 KB, +0.4% |
| Internal (gzip) | 153.9 KB | +635 B, +0.4% |
| Bundled (raw) | 1.41 MB | +3.6 KB, +0.2% |
| Bundled (gzip) | 318.2 KB | +653 B, +0.2% |
| Import time | 99ms | +3ms, +2.8% |
@portabletext/editor/behaviors
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 2ms | +0ms, +0.2% |
@portabletext/editor/plugins
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 894 B | - |
| Bundled (raw) | 2.5 KB | - |
| Bundled (gzip) | 827 B | - |
| Import time | 7ms | -0ms, -0.0% |
@portabletext/editor/selectors
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 81.2 KB | - |
| Internal (gzip) | 14.9 KB | - |
| Bundled (raw) | 76.9 KB | - |
| Bundled (gzip) | 13.8 KB | - |
| Import time | 8ms | -0ms, -1.0% |
@portabletext/editor/traversal
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 28.1 KB | - |
| Internal (gzip) | 5.6 KB | - |
| Bundled (raw) | 28.1 KB | - |
| Bundled (gzip) | 5.5 KB | - |
| Import time | 6ms | -0ms, -3.3% |
@portabletext/editor/utils
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 29.7 KB | - |
| Internal (gzip) | 6.2 KB | - |
| Bundled (raw) | 27.4 KB | - |
| Bundled (gzip) | 5.9 KB | - |
| Import time | 6ms | -0ms, -2.4% |
🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./utils · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @portabletext/markdown
Compared against main (46133acc)
| Metric | Value | vs main (46133ac) |
|---|---|---|
| Internal (raw) | 53.8 KB | - |
| Internal (gzip) | 9.8 KB | - |
| Bundled (raw) | 348.9 KB | - |
| Bundled (gzip) | 96.3 KB | - |
| Import time | 38ms | +0ms, +0.7% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
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.
Summary
Combined fix for concurrent Portable Text editing over the SDK operational patch
channel. It stacks four changes as individual merges (attribution preserved; each
underlying PR remains independently mergeable to
main):apply-operation.tsspan.marks/block.markDefsremote patches as data patches on the root blocksync-machine.ts+ pluginplugin.sdk-value.tsxremote-patches.ts/applyPatch.tsThe load-bearing new piece is the atomic rollback. The operational channel (#2977)
applies incoming remote patches best-effort, one op at a time; when a concurrent
client's patch unsets a span
_keythis editor already changed,apply-operationthrows
node was not foundduring application — before #2977's plugin-side repaircan run — so the plugin fix alone still crashes. Making the batch atomic (roll the
whole batch back and let the whole-value sync reconcile) removes the crash at the
layer where it actually happens.
Verified — real-dataset, two-session concurrency matrix (
@sanity/sdk-react@2.17.0)bold-same-range,link-same-rangeformat-vs-typelink-overlap-rangenode was not foundcrash is eliminated across all trials; same-rangeformatting returns to SAFE.
link-overlap-range: two clients annotating the sameoverlapping text simultaneously still corrupt the document (orphan mark + duplicated
text). The operational patches merge at Content Lake with no rebase, so the bad
merge is server-side — no editor/plugin change undoes it. Separately, feat(plugin-sdk-value): sync through operational patches instead of whole-value diffs #2977's repair
can hit
Maximum call stack size exceededon this case (an unbounded repair loop).This is the remaining operational-rebase work and is the SDK layer's to own; it
should be tracked as a distinct issue.
@sanity/mutator(Studio) is the reference.Tests
SAFE / silent-loss / corrupt / crash): available in the
sanity-labspte-sdk-concurrent-reprorepo (CONCURRENCY-HARNESS.md).Status
Draft. It is not a complete concurrent-editing fix — it makes the operational
channel crash-free and safe for typing + same-range formatting, and pins the
overlapping-annotation corruption as the open server-side rebase problem. Do not
merge over the individual PRs; this is the combined test/ship surface.
🤖 Generated with Claude Code