{"record":{"id":"c2f93fb61e4e44f4","repo":"Panniantong/Agent-Reach","slug":"chunk-generation-safety-limit-is-max-chunks-seg","errorCode":null,"errorMessage":"chunk generation safety limit is {MAX_CHUNKS}; segment duration {segment_seconds}s could create {possible_chunks} chunks","messagePattern":"chunk generation safety limit is (.+?); segment duration (.+?)s could create (.+?) chunks","errorType":"exception","errorClass":"TranscribeError","httpStatus":null,"severity":"error","filePath":"agent_reach/transcribe.py","lineNumber":319,"sourceCode":"            \"-ar\",\n            \"16000\",\n            \"-b:a\",\n            \"32k\",\n            str(dst),\n        ]\n    )\n    return dst\n\n\ndef chunk_audio(src: Path, out_dir: Path, segment_seconds: int = CHUNK_SECONDS) -> List[Path]:\n    \"\"\"Split src into segments. Re-encodes each segment so cuts align to keyframes.\"\"\"\n    if segment_seconds <= 0:\n        raise TranscribeError(\"chunk segment duration must be positive\")\n    possible_chunks = (\n        MAX_AUDIO_SECONDS + segment_seconds - 1\n    ) // segment_seconds\n    if possible_chunks > MAX_CHUNKS:\n        raise TranscribeError(\n            f\"chunk generation safety limit is {MAX_CHUNKS}; \"\n            f\"segment duration {segment_seconds}s could create \"\n            f\"{possible_chunks} chunks\"\n        )\n    _require(\"ffmpeg\")\n    pattern = out_dir / \"chunk_%03d.m4a\"\n    _run(\n        [\n            \"ffmpeg\",\n            \"-loglevel\",\n            \"error\",\n            \"-y\",\n            \"-i\",\n            str(src),\n            \"-t\",\n            str(MAX_AUDIO_SECONDS),\n            \"-f\",\n            \"segment\",","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/transcribe.py#L301-L337","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Use segment_seconds >= 600 (the CHUNK_SECONDS default is exactly 600 and is the intended minimum)","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","Keep the default entirely: chunk_audio(src, out_dir)"],"exampleFix":"# before\nchunk_audio(src, out_dir, segment_seconds=120)  # safety limit is 24\n\n# after: default 600s segments; size is already controlled by 32kbps bitrate\nchunks = chunk_audio(src, out_dir)  # or segment_seconds=600","handlingStrategy":"validation","validationCode":"CHUNK_SECONDS, MAX_CHUNKS = 600, 24\n\ndef segment_within_budget(segment_seconds: int) -> bool:\n    return segment_seconds >= 1 and (14400 + segment_seconds - 1) // segment_seconds <= MAX_CHUNKS","typeGuard":null,"tryCatchPattern":"from agent_reach.transcribe import TranscribeError\ntry:\n    chunk_audio(src, out_dir, segment_seconds=seg)\nexcept TranscribeError as e:\n    if \"chunk generation safety limit\" in str(e):\n        return chunk_audio(src, out_dir, segment_seconds=CHUNK_SECONDS)  # smallest legal\n    raise","preventionTips":["Treat 600s as the minimum segment size, not a tuning knob downward","Control chunk size via bitrate (already 32kbps), not segment length","Compute ceil-div against MAX_CHUNKS before calling with custom values"],"tags":["validation","chunking","safety-limit","ffmpeg"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}