Skip to content

Fix off-by-one that leaves one stale point in the graph buffer - #580

Merged
orf merged 1 commit into
orf:masterfrom
chatman-media:fix/plot-buffer-trim-off-by-one
Aug 31, 2026
Merged

Fix off-by-one that leaves one stale point in the graph buffer#580
orf merged 1 commit into
orf:masterfrom
chatman-media:fix/plot-buffer-trim-off-by-one

Conversation

@chatman-media

Copy link
Copy Markdown
Contributor

PlotData::update trims points older than the buffer window by finding the index of the last stale entry and draining 0..idx. But idx itself matched the "is stale" filter, so it never actually gets removed — every call leaves exactly one out-of-window point sitting in data. It's subtle since it's always just one point and gets re-evaluated on the next tick, but it means the graph (and the min/max bounds computed from it) is never quite trimmed to what --buffer says it should be.

Changed the drain to 0..=idx and added a test that seeds a mix of stale/fresh timestamps directly and checks none of the stale ones survive update().

drain(0..idx) skips the element at idx, but idx is the index of the last
point that's actually older than the buffer window (it matched the filter
right above). So every update() call quietly leaves exactly one out-of-window
sample sitting in the data, forever. Switched it to drain(0..=idx) and added
a test that seeds a few stale/fresh points and checks nothing older than the
window survives after update().
@orf
orf force-pushed the fix/plot-buffer-trim-off-by-one branch from cb7c0c2 to 3804071 Compare August 31, 2026 18:37
@orf
orf merged commit 2b9da23 into orf:master Aug 31, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants