{"record":{"id":"548b0edd023ac9fd","repo":"sgl-project/sglang","slug":"kv-canary-bs-bs-exceeds-write-req-capacity-wri","errorCode":null,"errorMessage":"kv-canary: bs={bs} exceeds write_req_capacity={write_req_capacity}","messagePattern":"kv-canary: bs=(.+?) exceeds write_req_capacity=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":210,"sourceCode":"    )\n    _require_len(out_write_offsets, \"out_write_offsets\", write_offsets_len)\n    _require_len(\n        out_write_seed_slot_indices,\n        \"out_write_seed_slot_indices\",\n        write_req_capacity,\n    )\n    _require_len(out_verify_num_valid, \"out_verify_num_valid\", 1)\n    _require_len(out_verify_enable, \"out_verify_enable\", 1)\n    _require_len(out_write_num_valid_reqs, \"out_write_num_valid_reqs\", 1)\n    _require_1d(lut_tensor, \"lut_tensor\")\n\n    if write_offsets_len != write_req_capacity + 1:\n        raise ValueError(\n            f\"kv-canary: write_offsets_len must equal write_req_capacity + 1, got \"\n            f\"{write_offsets_len} and {write_req_capacity}\"\n        )\n    if bs > write_req_capacity:\n        raise ValueError(\n            f\"kv-canary: bs={bs} exceeds write_req_capacity={write_req_capacity}\"\n        )\n    if req_to_token_stride0 != int(req_to_token.stride(0)):\n        raise ValueError(\n            f\"kv-canary: req_to_token_stride0={req_to_token_stride0} does not match \"\n            f\"req_to_token.stride(0)={int(req_to_token.stride(0))}\"\n        )\n\n    _require_same_device(\n        out_verify_offsets_scratch,\n        \"out_verify_offsets_scratch\",\n        (\n            (req_pool_indices, \"req_pool_indices\"),\n            (prefix_lens, \"prefix_lens\"),\n            (extend_seq_lens, \"extend_seq_lens\"),\n            (req_to_token, \"req_to_token\"),\n            (lut_tensor, \"lut_tensor\"),\n            (out_write_offsets, \"out_write_offsets\"),","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L192-L228","documentation":"The offsets kernel writes one offset per request, so the batch size cannot exceed the write-request capacity of the output buffers. bs > write_req_capacity would overflow the write_offsets/plan buffers.","triggerScenarios":"Calling launch_plan_offsets_kernel with a bs larger than write_req_capacity — e.g. a scheduler batch that grew past the plan buffer's capacity.","commonSituations":"Running batch grows after the plan buffers were allocated for a smaller max; chunked-prefill misconfiguration inflating batch size; capacity reduced by other pools.","solutions":["Clamp/chunk the launch so bs <= write_req_capacity, splitting into multiple launches","Grow write_req_capacity (and the buffers sized capacity+1) to cover the max running batch"],"exampleFix":"// before\nlaunch_plan_offsets_kernel(bs=len(reqs), write_req_capacity=cap, ...)\n// after\nassert len(reqs) <= cap\nlaunch_plan_offsets_kernel(bs=len(reqs), write_req_capacity=cap, ...)","handlingStrategy":"validation","validationCode":"assert bs <= write_req_capacity, f\"bs={bs} > write_req_capacity={write_req_capacity}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size plan buffers for max running batch; chunk launches when the batch grows"],"tags":["kv-canary","capacity","bounds-check"],"backgroundTag":"batch-size-exceeds-limit","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}