Repository navigation
Conversation
…s true A gap points back to the last item before it. Once that item leaves the buffer the tail could land inside the gap, so has_latest_at() was true there while get_latest_at() read the item's old slot, which holds either the tick that reused it or the evicted item. Move the tail on to the next item whenever it advances. push() only checks when the overflow moved the tail.
louisbels
force-pushed
the
fix/history-buffer-evicted-gap
branch
from
November 26, 2026 22:24
7770488 to
a50fcdb
Compare
get_latest_at() returned null where has_latest_at() was trueThis branch has not been deployed
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.
We got this on a client while it was merging a state from the host:
It comes from
_PerObjectHistory.ensure_snapshot(), which checkshas_latest_at(tick)and then duplicatesget_latest_at(tick). In_HistoryBufferthe two can disagree. A tick with no data points to the last tick written before it, and when that one is pushed out of the buffer, the empty ticks after it stay in with nothing to point to.With the default capacity of 64,
set_at(54, ...)thenset_at(118, ...)is enough: 118 takes the slot of 54, and for ticks 55 to 117has_latest_at()is true whileget_latest_at()returns null. A plainpush()can get there too.For us it was most likely a client that stalled for about two seconds while loading, then received a state for one of those ticks.
The fix moves the tail forward to the next tick that has data whenever it advances, so those empty ticks are no longer part of the buffer.
pop()gets the same treatment, there the empty ticks still returned the popped item. I added a test forset_at(),push()andpop(), and one that does random writes and checks that every tick with a latest returns it. Tests pass on 4.2.2 and 4.7.