Skip to content

fix: prevent infinite loop in chunk_video when overlap >= chunk_duration#40

Merged
ssrajadh merged 1 commit intossrajadh:masterfrom
sjhddh:fix/chunk-video-infinite-loop
Apr 12, 2026
Merged

fix: prevent infinite loop in chunk_video when overlap >= chunk_duration#40
ssrajadh merged 1 commit intossrajadh:masterfrom
sjhddh:fix/chunk-video-infinite-loop

Conversation

@sjhddh
Copy link
Copy Markdown
Contributor

@sjhddh sjhddh commented Apr 12, 2026

Bug

In sentrysearch/chunker.py, the chunk_video function computes:

step = chunk_duration - overlap

When overlap >= chunk_duration, step is <= 0. The loop condition is while start < duration, but start += step never increases start, so the loop runs forever — spawning a new ffmpeg process on every iteration and filling /tmp until disk space is exhausted or the process is killed.

Reproduction

sentrysearch index ./footage --chunk-duration 5 --overlap 5
# hangs indefinitely, spawns ffmpeg processes, fills /tmp

Any value where --overlap >= --chunk-duration triggers this (e.g. --chunk-duration 5 --overlap 6).

Fix

Add an early guard in chunk_video() that raises ValueError before any file I/O or ffmpeg invocations:

if overlap >= chunk_duration:
    raise ValueError(
        f"overlap ({overlap}s) must be less than chunk_duration ({chunk_duration}s). "
        "When overlap >= chunk_duration the step between chunks is <= 0, "
        "causing an infinite loop."
    )

Also add a click.BadParameter check at the top of the index CLI command so the user gets a clear, immediate error message before any video processing begins.

Changes

  • sentrysearch/chunker.py: validate overlap < chunk_duration at the start of chunk_video()
  • sentrysearch/cli.py: validate the same constraint in the index command and surface it as a CLI error

…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.
@ssrajadh ssrajadh merged commit d6623c5 into ssrajadh:master Apr 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants