fix(delta): add content-based validation to block-level operations (prevents silent overwrites) - #3404
Open
handnewb wants to merge 2 commits into
Open
Conversation
handnewb
force-pushed
the
fix/delta-block-expected-content-validation
branch
from
August 11, 2026 21:24
3b994b4 to
2d63951
Compare
ReplaceBlockOp and RemoveBlockOp now accept an optional expected_block field. When provided, the operation is only applied if the current block at the target index serialises to the same JSON as expected_block. This protects against LLM-computed index drift: a wrong-but-in-range index would previously silently overwrite or remove an unrelated block. The operation is now skipped with a clear reason logged, and the document stays intact. The change is backward-compatible: when expected_block is None (the default, and the only shape old LLM prompts produce), the existing range-only validation is preserved unchanged. Closes vectorize-io#3273.
handnewb
force-pushed
the
fix/delta-block-expected-content-validation
branch
from
August 11, 2026 21:28
2d63951 to
6c21369
Compare
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
Fixes #3273: In delta-mode mental-model refresh,
ReplaceBlockOpandRemoveBlockOptargeted blocks by LLM-computed integer index with range-only validation. A wrong-but-in-range index silently overwrote or removed an unrelated block, and the refresh committed it as success.Root Cause
The
apply_operationsfunction validated only that the index was within[0, len(blocks))— no content check. If the LLM's computed index drifted (e.g., because the document changed since the LLM last saw it, or the LLM miscounted), the operation corrupted the document silently.Solution
New
expected_blockfield onReplaceBlockOpandRemoveBlockOp:Noneby default (fully backward compatible)section.blocks[index]serialises to the same JSON asexpected_block_blocks_equal()helper compares viamodel_dump_json()Impact
expected_blocksee no behavior changeskippedlist) now surfaces drift events for debuggingexpected_blockfor full protection