Panniantong/Agent-Reach · error · TranscribeError

chunk segment duration must be positive

Error message

chunk segment duration must be positive

What it means

Raised by chunk_audio (transcribe.py:311-314) when the caller passes segment_seconds <= 0. The value feeds ffmpeg's -segment_time, which requires a positive duration; the Python-side check gives a clear error before spawning ffmpeg with a nonsensical argument.

Source

Thrown at agent_reach/transcribe.py:314

            "-t",
            str(MAX_AUDIO_SECONDS),
            "-vn",
            "-ac",
            "1",
            "-ar",
            "16000",
            "-b:a",
            "32k",
            str(dst),
        ]
    )
    return dst


def chunk_audio(src: Path, out_dir: Path, segment_seconds: int = CHUNK_SECONDS) -> List[Path]:
    """Split src into segments. Re-encodes each segment so cuts align to keyframes."""
    if segment_seconds <= 0:
        raise TranscribeError("chunk segment duration must be positive")
    possible_chunks = (
        MAX_AUDIO_SECONDS + segment_seconds - 1
    ) // segment_seconds
    if possible_chunks > MAX_CHUNKS:
        raise TranscribeError(
            f"chunk generation safety limit is {MAX_CHUNKS}; "
            f"segment duration {segment_seconds}s could create "
            f"{possible_chunks} chunks"
        )
    _require("ffmpeg")
    pattern = out_dir / "chunk_%03d.m4a"
    _run(
        [
            "ffmpeg",
            "-loglevel",
            "error",
            "-y",
            "-i",

View on GitHub (pinned to 93ae1d18c3)

Solutions

  1. Pass a positive segment length, or omit it to use the 600s default: chunk_audio(src, out_dir)
  2. If computing segment_seconds dynamically, clamp: max(1, computed)
  3. Validate config before the call: if cfg.segment_seconds <= 0: use CHUNK_SECONDS

Example fix

# before
segment = total_bytes // expected_chunks  # -> 0
chunk_audio(src, out_dir, segment_seconds=segment)

# after
segment = max(1, total_bytes // expected_chunks) if expected_chunks else CHUNK_SECONDS
chunk_audio(src, out_dir, segment_seconds=segment)
Defensive patterns

Strategy: validation

Validate before calling

def valid_segment_seconds(value: int) -> bool:
    return isinstance(value, int) and value > 0

Try / catch

from agent_reach.transcribe import TranscribeError
try:
    chunk_audio(src, out_dir, segment_seconds=seg)
except TranscribeError as e:
    if "must be positive" in str(e):
        return chunk_audio(src, out_dir)  # fall back to the 600s default
    raise

Prevention

When it happens

Trigger: Calling chunk_audio(src, out_dir, segment_seconds=0) or a negative value, usually because a computed segment size (e.g. size // duration) divided down to zero, or a config default of 0 was never overridden. The public transcribe() never triggers this — it uses the CHUNK_SECONDS=600 default.

Common situations: Custom callers tuning chunk length from user config where a missing setting defaults to 0; integer division of small sizes by large counts producing 0; test fixtures passing 0 to mean 'default'.

Related errors


AI-assisted analysis of Panniantong/Agent-Reach@93ae1d18c3 (2026-08-14). Data as JSON: /api/errors/c15c2027a5d9abe2. Report an issue: GitHub.