Repository navigation
Remove a block only as it was read, and name the copy when copy-block fails - #126
Merged
Merged
Conversation
removeBlock cascades, so a child added between a command's read and its delete went with the block. LogseqAPI.remove_block now takes a required expect_tree: the tree hash of the block as the caller read it, or None for a block nobody read a subtree of (strictinsert's stand-in). With a hash it reads the block with its children again past the cache, right before the delete, and raises BlockChanged when the tree is another and BlockNotFound when the block is gone. No default, so a new caller cannot skip the check by forgetting it. remove-block and the page's property block in remove-property pass the hash of their read; copy-block passes None until it gets its own check.
copy-block writes the copy block by block and removes the source last, with no rollback. A failure after the copy's root landed left a copy in the target that a caller could not find (the error object had only writes_landed), and a retry made a second one. The command now registers copied_id and "The copy is <uuid>." with output.on_failure as soon as the root is proven; the two ways a failure is reported (a refused or unproven write, and a connection failure) add them to the error object and the message. A root that did not land names nothing.
copy-block --remove reads the source once, copies it block by block and then removes it, and the removal cascades: a child added under the source while the copy ran was deleted, missing from the copy, and the command reported success. Reproduced against the test double. The removal now passes the tree hash of the state that was copied, so the API refuses with block_changed when anything under the source changed, removing nothing; the copy is named in copied_id. A source deleted elsewhere during the copy is a move done: exit 0 with source_gone, since a failure would invite cleaning up the only version left. docs/safety.md replaces the known gap with what stays open: the requests between the last read and the delete, a copy that breaks off, and a ref set during the copy.
muellerei
force-pushed
the
fix/copy-block-remove-reread
branch
from
October 13, 2026 13:35
dae1f96 to
ce29d89
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.
Closes #125.
Summary
Every removal of a block a command read now checks that the block is still what was read.
copy-block --removechecks against the state it copied.expect_treehas no default, so every caller says what it read:output.on_failureis read by both failure paths (a refused or unproven write, and a connection failure), so the command needs notryper kind of failure. A refusal from the removal no longer says "repeat": a retry makes a second copy.Evidence
"blocks": 4, the source gone, the copy without the fourth child. A source deleted during the copy: exit 0,"action": "moved", no hint.remove-blockon a block deleted between its read and its delete: exit 0, reported removed.After:
test_a_child_added_during_the_copy_is_not_removed: exit 1,block_changed,copied_id= the copy's root, the fourth child still under the source.test_a_source_deleted_during_the_copy_is_a_move_done: exit 0,source_gone: true.test_remove_block_keeps_a_child_made_between_read_and_deleteandtest_remove_property_keeps_a_property_block_that_got_a_child:block_changed, nothing removed.remove_block, comparing with a fresh read instead of the copied state, not registeringcopied_id, and not catchingBlockNotFoundincopy-blockeach make their tests fail.ruff checkclean.Merge Danger
Door: two-way
No data or format changes. Reverting restores the old removal.
Blast Radius: removals
remove-blockchanges behaviour: it refuses withblock_changedwhen anything under the block changed since its read, and reports a block gone by then asblock_not_found(exit 1) where it used to report it removed. Every removal costs one moregetBlock. The window between that read andremoveBlockstays (the editor check, with a block open also its read of the subtree), since the API has no compare-and-swap;docs/safety.mdsays so. A root placed before the empty blocks at the end of a page (keep_empty_blocks_last) whose place could not be proven is not named incopied_id.