fix: serialize single-block mutations per content path - #58
Open
nileshgulia1 wants to merge 2 commits into
Open
Conversation
Add a module-level per-path concurrency queue and wrap the read-modify-write sequences in plone_add_single_block, plone_remove_single_block, and plone_update_single_block. This prevents lost updates when multiple MCP clients (same or different users) concurrently edit blocks on the same page, because the second caller now reads the state produced by the first caller instead of overwriting it. Plone's own @lock mechanism is respected but not acquired by the MCP, so Volto users are not blocked during short MCP operations.
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.
Serialize single-block mutations per content path
Fixes lost-update races in
plone_add_single_block,plone_remove_single_block, andplone_update_single_blockwhen two operations run concurrently on the same content item.Problem
Each single-block tool performs a read-modify-write against Plone: GET the content, mutate
blocks/blocks_layout, then PATCH. When two callers operate on the same path concurrently (multiple MCP clients in HTTP mode, parallel tool calls in one session), both read the same snapshot and the last PATCH overwrites the earlier change — a block is silently lost.Fix
Introduce a module-level per-path serialization queue (
src/utils/concurrency-queue.ts). Operations for the same normalized path are chained so a later operation only starts after the previous one has settled; rejected operations do not block the queue.Verification
plone_remove_single_blockcalls on the same path and asserts the surviving state contains neither block.