Fix off-by-one in remove_artifacts zeros mode leaving last artifact sample un-zeroed#4445
Draft
Fix off-by-one in remove_artifacts zeros mode leaving last artifact sample un-zeroed#4445
remove_artifacts zeros mode leaving last artifact sample un-zeroed#4445Conversation
…egression test Co-authored-by: alejoe91 <17097257+alejoe91@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove artifacts recording not used in Kilosort
Fix off-by-one in Mar 16, 2026
remove_artifacts zeros mode leaving last artifact sample un-zeroed
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.
RemoveArtifactsRecordingSegment.get_traces(zeros mode) had an off-by-one in the boundary branch where the artifact start falls at or before the chunk start. The last sample of the artifact window was never zeroed, causing sorters to detect spurious spikes right at the end of blanked periods.Root cause
In
get_traces,trigis the trigger offset relative tostart_frame. Whentrig - pad[0] <= 0(artifact starts at/before chunk boundary) the code used:while the normal (interior) case correctly used
trig + pad[1] + 1. Additionally, the guard on the interior case used> 0instead of>= 0, pushing thetrig - pad[0] == 0situation into the buggy branch unnecessarily.Fix
Test
Added
test_remove_artifacts_zeros_boundary: requests a window slightly wider than the artifact so the boundary branch is exercised, then asserts every sample in[trigger - ms_before, trigger + ms_after](inclusive) is zero. The existing tests never caught this because they requested windows exactly matching the artifact width, which fell into the full-window-zero branch instead.Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.