fix: clamp lag parameter to buffer size with warning (fixes #379)#459
Merged
pradeeban merged 1 commit intoControlCore-Project:devfrom Feb 26, 2026
Merged
Conversation
…re-Project#379) The circular buffer in plotymlag.py has a fixed size of 10. When a user sets lag >= size via tryparam, the modulo arithmetic silently wraps, producing incorrect data (e.g., lag=15 behaves like lag=5). Add input validation that clamps lag to size-1 and emits a logging.warning when the requested value exceeds the buffer capacity. This prevents silent data corruption while preserving backward compatibility and the existing circular buffer logic.
11e04a2 to
a4162b6
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.
Summary
Fixes #379 —
lagparameter inplotymlag.pysilently wraps around whenlag >= buffer size, producing incorrect data without any warning.Root Cause
The circular buffer in
plotymlag.pyuses a fixedsize = 10. The lag value is user-configurable viaconcore.tryparam("lag", 0). When a user requestslag >= size(e.g.,lag = 15), the expression(cur - lag) % sizesilently wraps due to Python's modulo arithmetic, causinglag = 15to behave identically tolag = 5. This produces wrong output data with no error or warning.Fix
lagis read fromtryparam.lag >= size, the value is clamped tosize - 1(the maximum safe lag).logging.warning()is emitted to alert the user that their requested lag was out of range.(cur - lag) % size) remains unchanged.Changes
tools/plotymlag.py: Addedimport loggingand a validation block (6 net new lines).Testing
Verified locally with multiple lag values:
py_compile).lag < 10see no change in behavior.Verification Steps for Reviewers
plotymlag.pywithlag=0→ works as before.lag=15→ observe warning message and clamped behavior (lag=9), no crash.(cur - lag) % sizelogic is untouched.logging).