fix: prevent infinite loop in chunk_video when overlap >= chunk_duration#40
Merged
ssrajadh merged 1 commit intossrajadh:masterfrom Apr 12, 2026
Merged
Conversation
…ite loop When overlap >= chunk_duration, step = chunk_duration - overlap is <= 0. The while loop in chunk_video never advances start, spawning ffmpeg processes indefinitely and filling /tmp. Add a guard at the top of chunk_video() that raises ValueError immediately, and a matching click.BadParameter check in the CLI index command so users get a clear error message before any video processing begins.
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.
Bug
In
sentrysearch/chunker.py, thechunk_videofunction computes:When
overlap >= chunk_duration,stepis<= 0. The loop condition iswhile start < duration, butstart += stepnever increasesstart, so the loop runs forever — spawning a newffmpegprocess on every iteration and filling/tmpuntil disk space is exhausted or the process is killed.Reproduction
sentrysearch index ./footage --chunk-duration 5 --overlap 5 # hangs indefinitely, spawns ffmpeg processes, fills /tmpAny value where
--overlap >= --chunk-durationtriggers this (e.g.--chunk-duration 5 --overlap 6).Fix
Add an early guard in
chunk_video()that raisesValueErrorbefore any file I/O or ffmpeg invocations:Also add a
click.BadParametercheck at the top of theindexCLI command so the user gets a clear, immediate error message before any video processing begins.Changes
sentrysearch/chunker.py: validateoverlap < chunk_durationat the start ofchunk_video()sentrysearch/cli.py: validate the same constraint in theindexcommand and surface it as a CLI error