{"record":{"id":"f8c2df41b6501598","repo":"sgl-project/sglang","slug":"kv-canary-write-offsets-len-must-be-positive-got","errorCode":null,"errorMessage":"kv-canary: write_offsets_len must be positive, got {write_offsets_len}","messagePattern":"kv-canary: write_offsets_len must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":157,"sourceCode":"    _require_dtype(req_to_token, \"req_to_token\", torch.int32)\n    _require_dtype(lut_tensor, \"lut_tensor\", torch.int64)\n    _require_dtype(\n        out_verify_offsets_scratch, \"out_verify_offsets_scratch\", torch.int64\n    )\n    _require_dtype(out_write_offsets, \"out_write_offsets\", torch.int64)\n    _require_dtype(\n        out_write_seed_slot_indices, \"out_write_seed_slot_indices\", torch.int64\n    )\n    _require_dtype(out_verify_num_valid, \"out_verify_num_valid\", torch.int32)\n    _require_dtype(out_verify_enable, \"out_verify_enable\", torch.int32)\n    _require_dtype(out_write_num_valid_reqs, \"out_write_num_valid_reqs\", torch.int32)\n\n    if bs < 0 or bs > _PLAN_BS_BLOCK_SIZE:\n        raise ValueError(\n            f\"kv-canary: offsets kernel bs must be in [0, {_PLAN_BS_BLOCK_SIZE}], got {bs}\"\n        )\n    if write_offsets_len <= 0:\n        raise ValueError(\n            f\"kv-canary: write_offsets_len must be positive, got {write_offsets_len}\"\n        )\n    if write_req_capacity < 0:\n        raise ValueError(\n            f\"kv-canary: write_req_capacity must be non-negative, got {write_req_capacity}\"\n        )\n    if verify_capacity < 0:\n        raise ValueError(\n            f\"kv-canary: verify_capacity must be non-negative, got {verify_capacity}\"\n        )\n    if req_to_token_stride0 <= 0:\n        raise ValueError(\n            f\"kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}\"\n        )\n    if lut_len < 0:\n        raise ValueError(f\"kv-canary: lut_len must be non-negative, got {lut_len}\")\n    if not isinstance(has_swa_lut, bool):\n        raise ValueError(","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L139-L175","documentation":"write_offsets_len describes the length of the write-offsets output array and must be strictly positive (it always holds at least one leading offset entry). A non-positive value means the output buffer metadata is malformed.","triggerScenarios":"Calling launch_plan_offsets_kernel with write_offsets_len <= 0, usually because write_offsets was empty or the capacity variable used to derive the length was 0/negative.","commonSituations":"Miscomputing write_offsets_len as write_req_capacity instead of write_req_capacity + 1; passing an empty write_offsets tensor.","solutions":["Allocate write_offsets with write_req_capacity + 1 elements and pass that as write_offsets_len","Verify write_req_capacity is set to the real pool capacity before deriving lengths"],"exampleFix":"// before\nwrite_offsets = torch.zeros(write_req_capacity, dtype=torch.int64, device=dev)\n// after\nwrite_offsets = torch.zeros(write_req_capacity + 1, dtype=torch.int64, device=dev)","handlingStrategy":"validation","validationCode":"assert write_offsets_len == write_req_capacity + 1 and write_offsets_len > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate write_offsets with capacity+1 elements at setup"],"tags":["kv-canary","offsets","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}