fix: validate chunk_size and overlap to reject non-positive values#7789
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
| if (chunkSize !== undefined && chunkSize <= 0) { | ||
| throw new Error('chunk_size must be at least 1.'); | ||
| } |
There was a problem hiding this comment.
🟡 Validation in analyzeKeyframesForAsset uses <= 0 instead of < 1, allowing fractional chunkSize values that produce empty chunks
The validation at line 133 checks chunkSize <= 0, but the documented and intended minimum is 1 (matching the run() validation at line 289 which checks < 1, and the JSON schema which specifies minimum: 1). A fractional value like chunkSize = 0.5 passes the <= 0 check but causes buildChunks to produce empty chunks because keyframes.slice(i, i + 0.5) truncates to keyframes.slice(i, i) → an empty array.
Root Cause and Impact
analyzeKeyframesForAsset is an exported public function called both from run() and directly from assistant/src/memory/job-handlers/media-processing.ts:66. While current callers pass undefined (which defaults to 10), any future direct caller passing a fractional value between 0 and 1 (exclusive) would bypass validation and trigger empty-chunk processing.
The run() entry point correctly validates with chunkSizeInput < 1 at line 289, but the core function's own guard is weaker. Since the PR's stated goal is to "prevent empty-chunk behavior," the validation should be consistent: chunkSize < 1 instead of chunkSize <= 0.
Impact: Empty chunks passed to analyzeChunk() would send API requests with zero images, wasting API calls and potentially causing downstream errors.
| if (chunkSize !== undefined && chunkSize <= 0) { | |
| throw new Error('chunk_size must be at least 1.'); | |
| } | |
| if (chunkSize !== undefined && chunkSize < 1) { | |
| throw new Error('chunk_size must be at least 1.'); | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
Addresses review feedback on #7787. Validates chunk_size >= 1 and overlap >= 0 at both the tool run() entry point and the core analyzeKeyframesForAsset() function, preventing empty-chunk behavior when chunk_size=0 passes through nullish coalescing.