Panniantong/Agent-Reach · error · TranscribeError

chunk generation safety limit is {MAX_CHUNKS}; segment durat

Error message

chunk generation safety limit is {MAX_CHUNKS}; segment duration {segment_seconds}s could create {possible_chunks} chunks

What it means

Raised by chunk_audio (transcribe.py:315-323) when ceil(MAX_AUDIO_SECONDS / segment_seconds) exceeds MAX_CHUNKS (24). With MAX_AUDIO_SECONDS = 14400s, any segment_seconds < 600 produces more than 24 potential chunks and is rejected before ffmpeg runs. This keeps the number of provider API calls per job bounded.

Source

Thrown at agent_reach/transcribe.py:319

            "-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",
            str(src),
            "-t",
            str(MAX_AUDIO_SECONDS),
            "-f",
            "segment",

View on GitHub (pinned to 93ae1d18c3)

Solutions

  1. Use segment_seconds >= 600 (the CHUNK_SECONDS default is exactly 600 and is the intended minimum)
  2. If chunks are too large at 600s, reduce the audio bitrate upstream instead — compress_audio already targets 32kbps, which makes 10-min chunks ~2.4 MB, far under the 24 MiB cap
  3. Keep the default entirely: chunk_audio(src, out_dir)

Example fix

# before
chunk_audio(src, out_dir, segment_seconds=120)  # safety limit is 24

# after: default 600s segments; size is already controlled by 32kbps bitrate
chunks = chunk_audio(src, out_dir)  # or segment_seconds=600
Defensive patterns

Strategy: validation

Validate before calling

CHUNK_SECONDS, MAX_CHUNKS = 600, 24

def segment_within_budget(segment_seconds: int) -> bool:
    return segment_seconds >= 1 and (14400 + segment_seconds - 1) // segment_seconds <= MAX_CHUNKS

Try / catch

from agent_reach.transcribe import TranscribeError
try:
    chunk_audio(src, out_dir, segment_seconds=seg)
except TranscribeError as e:
    if "chunk generation safety limit" in str(e):
        return chunk_audio(src, out_dir, segment_seconds=CHUNK_SECONDS)  # smallest legal
    raise

Prevention

When it happens

Trigger: chunk_audio(src, out_dir, segment_seconds=300) -> 14400/300 = 48 > 24 -> raise. Any value below 600 seconds trips it; 600 exactly is the smallest allowed value (14400/600 = 24, not > 24).

Common situations: Callers shrinking segments hoping to duck under the 24 MiB per-chunk Whisper limit, or copying a 5-minute segment size from another pipeline into this one; tuning attempts after seeing per-chunk size errors.

Related errors


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