fix(id-allocation): Schedule a flush when submitting ID Allocation op before replaying pending states #24683
+65
−34
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
Fixes AB#39398
In
ContainerRuntime
, we submit to theOutbox
directly fromreplayPendingStates
, and so we should also callscheduleFlush
to ensure that op doesn't get stuck in the Outbox. Being "stuck in the Outbox" is a problem because it's assumed that all ops in a batch come during the same JS turn and have the same reference sequence number, and this will violate that invariant.That one-line change is accompanied by some refactoring so we don't have to consider Immediate mode at that callsite (
scheduleFlush
handles it now).In-Depth
In the typical case, calling
PendingStateManager.replayPendingStates
will trigger another op(s) to submit which will schedule the flush. But here's a counterexample:This will result in the replay flow, and we will submit an ID Allocation op, but there's nothing else to resubmit. This op will be "stuck" in the Outbox.
In the current code, this is kind of ok, because ID Allocation ops don't make the container dirty, and it's ok to drop that op. BUT, as mentioned above, it can easily violate the invariant that all ops in a batch have the same reference sequence number, because that "old" op will be included in the next batch, which could be some time later after new ops have been processed (which advances the refSeq). See the unit test added here.