{"record":{"id":"8b1e78a70540015b","repo":"Hmbown/CodeWhale","slug":"overlap-must-be-smaller-than-max-chars","errorCode":null,"errorMessage":"overlap must be smaller than max_chars","messagePattern":"overlap must be smaller than max_chars","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crates/tui/src/repl/runtime.rs","lineNumber":897,"sourceCode":"        snippet_start = max(0, start - 120)\n        snippet_end = min(len(_context), end + 120)\n        hits.append({\n            \"index\": i,\n            \"start\": start,\n            \"end\": end,\n            \"match\": m.group(0),\n            \"snippet\": _context[snippet_start:snippet_end],\n        })\n    return hits\n\ndef chunk(max_chars=20000, overlap=0):\n    \"\"\"Return full-coverage input chunks with index/start/end/text fields.\"\"\"\n    max_chars = int(max_chars)\n    overlap = max(0, int(overlap))\n    if max_chars <= 0:\n        raise ValueError(\"max_chars must be > 0\")\n    if overlap >= max_chars:\n        raise ValueError(\"overlap must be smaller than max_chars\")\n    chunks = []\n    start = 0\n    idx = 0\n    total = len(_context)\n    while start < total:\n        end = min(total, start + max_chars)\n        chunks.append({\"index\": idx, \"start\": start, \"end\": end, \"text\": _context[start:end]})\n        idx += 1\n        if end >= total:\n            break\n        start = end - overlap\n    return chunks\n\ndef chunk_context(max_chars=20000, overlap=0):\n    \"\"\"Compatibility alias for chunk().\"\"\"\n    return chunk(max_chars=max_chars, overlap=overlap)\n\ndef chunk_coverage(chunks):","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/repl/runtime.rs#L879-L915","documentation":"chunk() requires the overlap between consecutive chunks to be strictly smaller than max_chars; overlap >= max_chars would make chunks never advance and loop forever. The function clamps negative overlap to 0, then raises this ValueError when overlap is still too large.","triggerScenarios":"Calling chunk(max_chars=1000, overlap=1000) or any overlap >= max_chars after the int/max(0,...) coercion, e.g. chunk(max_chars=100, overlap=500).","commonSituations":"Configuring overlap as a fraction but passing it as a raw value (0.5 vs half of max_chars); copying an overlap from a differently-sized chunking config; generated code that sets overlap equal to max_chars.","solutions":["Lower overlap so it is strictly less than max_chars (e.g. overlap = max_chars // 10)","Raise max_chars if the desired overlap is genuinely large","Clamp in caller code: overlap = min(overlap, max_chars - 1)"],"exampleFix":"// before\nchunk(max_chars=1000, overlap=1000)\n// after\nchunk(max_chars=1000, overlap=100)","handlingStrategy":"validation","validationCode":"overlap = Math.max(0, Math.trunc(overlap));\nif (overlap >= maxChars) overlap = Math.max(0, maxChars - 1);","typeGuard":"const validChunking = (mc, ov) => Number.isInteger(mc) && mc > 0 && Number.isInteger(ov) && ov >= 0 && ov < mc;","tryCatchPattern":"try { return chunk(maxChars, overlap); } catch (e) { if (String(e).includes(\"overlap must be\")) { return chunk(maxChars, Math.floor(maxChars / 10)); } throw e; }","preventionTips":["Express overlap as a fraction of max_chars and compute it at call time","Validate chunk/overlap pairs together, not as independent config values","Remember negative overlap is silently clamped to 0 — only the >= max_chars case throws"],"tags":["python","validation","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}