Add explicit mechanism for preventing the submission of dangerous SharedTree commits #23276
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.
Description
Currently, if the application of a local commit crashes a SharedTree client, that client will crash before sending the op to other clients, which prevents them from crashing in turn. This is good, but the way that it is currently achieved is somewhat obfuscated, relies on bizarre event ordering guarantees, and is preventing some future features from being possible.
More specifically, the checkout currently updates its forest in response to its branch's
"beforeChange"
event. This is because op submission happens in response to the"afterChange"
event, so if the checkout crashes during"beforeChange"
, we won't progress to"afterChange"
. However, that means that when the end user of SharedTree receives a"nodeChanged"
or"treeChanged"
event, it will be in the context of the"beforeChange"
event - so the forest will be updated according to their change, but the commit graph will not. Therefore, they cannot (sanely) do operations that affect the commit graph - like forking or merging their branches - in an event handler. This PR moves the forest update to the"afterChange"
event, so that the commit graph is updated before the user's event handler is called. It does this by adding an explicit mechanism to the checkout for monitoring when commits have been "validated" - and SharedTree then uses this to determine when they should be submitted to other clients.SharedTreeCore
now attempts to submit commits during"beforeChange"
, not"afterChange"
, but is intercepted bySharedTree
and then delayed until after validation.This PR also does a smattering of other related cleanup, including:
"beforeBatch"
and"afterBatch"
to suit their usage and adding documentation.SharedTreeBranchChange
and improving the documentation.merge
operation ofSharedTreeBranch
as well as for a cached property in the rebase logic.load
function. While still ugly, it is at least straightforward, and it combines with and cleans up the existing "on load" functionsetTipRevisionForLoadedData()
.