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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Properly restores the expected return structure.
The change correctly restores the original behavior by returning the entire
samplesarray without slicing it, while still including thesamplesCountascount. This fixes the breakage mentioned in PR #819 where consumers of this function expected the full unsliced array.🏁 Script executed:
Length of output: 985
🏁 Script executed:
Length of output: 2523
Update downstream consumers to use
countinstead of the array’s capacityRestoring the full
samplesarray alongsidecountis correct, but all of the following consumers still useflightSamples.samples.length(the pre-allocated buffer size) rather thanflightSamples.count, which will pull in uninitialized zeros past the real data. Please update these sites to usecount:– FFT normalization:
– Points-per-segment cap:
– Power spectral density call:
– FFT-window loop boundary:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai , How can we retain
samples : samples.slice(0, samplesCount),and fix any surrounding code that may not have accounted for such?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@nerdCopter, yes, we can definitely retain the slicing operation
samples.slice(0, samplesCount)and fix the surrounding code. This is actually a cleaner approach as it ensures that only valid data is passed around.Here are the changes you would need to make to keep the slicing:
Keep the original slicing in
_getFlightSamplesFreq:No other changes are needed! When you slice the array,
flightSamples.samples.lengthwill correctly be equal toflightSamples.count, which is the desired behavior.This approach has several advantages:
Since your PR is reverting a breaking change, keeping the slicing behavior while ensuring the correct structure (including both
samplesandcountproperties) should resolve the issue without introducing new problems.🏁 Script executed:
Length of output: 982
@nerdCopter Yes, retaining
samples : samples.slice(0, samplesCount)is definitely the cleaner approach! After analyzing the code, this appears to be the originally intended pattern.Looking at the search results, I see code that uses
flightSamples.samples.lengthin three places:this._normalizeFft(fftOutput, flightSamples.samples.length)pointsPerSegment = Math.min(pointsPerSegment, flightSamples.samples.length)for (let fftChunkIndex = 0; ... < flightSamples.samples.length; ...)When you use slice,
samples.lengthwill equalcount, which is exactly what these functions expect. Without the slice, these functions would process the entire preallocated array including unused elements.I also noticed that
_getFlightSamplesFreqVsX()already follows this pattern:No other code changes should be needed - just restore the
.slice(0, samplesCount)in the return statement, and everything should work correctly.🧬 Code Graph Analysis Results
Relevant snippets from
src/graph_spectrum_calc.js(lines relevant tosamples : samples.slice(0, samplesCount),and surrounding code):Float64Arraysized for the maximum analyser length and black box rate.samplesCount.samplesarray (which may be larger thansamplesCount) and the count.samples : samples.slice(0, samplesCount),which is a common pattern to return only the valid portion of the array.samplesarray without slicing, which may cause consumers to process trailing zero or uninitialized data beyondsamplesCount.samples.slice(0, samplesCount)instead of the full array, and ensuring all callers handle the sliced array accordingly.samplesCountand returns slices of the arrays up tosamplesCount._getFlightSamplesFreqas well.samplesto be sliced to the actual count.samples: samples.slice(0, samplesCount)andvsValuessliced similarly._getFlightSamplesFreq()and usesflightSamples.samplesdirectly._getFlightSamplesFreq()returns the full preallocated array without slicing,flightSamples.samples.lengthwill be the max length, not the actual count._getFlightSamplesFreq()is changed to returnsamples.slice(0, samplesCount), this function will correctly process only valid data._hanningWindowis called withflightSamples.countas size, so it applies only to valid samples.dataLoadFrequency, this function uses_getFlightSamplesFreq(false)and then usesflightSamples.samples.length._getFlightSamplesFreqreturns the full preallocated array,samples.lengthis max length, not actual count._getFlightSamplesFreqto return sliced array fixes this.pointsPerSegmentis capped byflightSamples.samples.length, so if length is too large, it may cause issues.Summary of relevant code context:
_getFlightSamplesFreqcurrently returns the full preallocatedsamplesarray and a separatecount.samples : samples.slice(0, samplesCount),which means returning only the valid portion of the samples array._getFlightSamplesFreqVsXalready use this pattern._getFlightSamplesFreq(e.g.,dataLoadFrequency,dataLoadPSD) use.samples.lengthto determine data length, so returning the sliced array aligns with their expectations._getFlightSamplesFreqto returnsamples: samples.slice(0, samplesCount)and updating all callers to expect this sliced array will ensure consistent and correct processing of sample data.No other files or snippets from the provided possibly relevant code snippets appear directly related to the handling or slicing of
samplesarrays ingraph_spectrum_calc.js.✏️ Learnings added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The all looks good, but fft call hangs...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you find solution, make PR and we close this one. Google AI failing me as well.

Google AI said this, but AI has lead me in wrong directions before, so take with grain-of-salt.
And so far, AI prompting cannot properly craft a proper fix without introducing further bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe quickest to revert #819 , but i''m going offline until tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#819only changed 3 lines (rest was refactoring)sampleCountwould handle it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, i have some solution. Will push it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check new psd code to work without #819 if i will not find normal solution