{"record":{"id":"25a193de82c0171b","repo":"sgl-project/sglang","slug":"kv-canary-verify-capacity-must-be-non-negative-g","errorCode":null,"errorMessage":"kv-canary: verify_capacity must be non-negative, got {verify_capacity}","messagePattern":"kv-canary: verify_capacity must be non-negative, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":165,"sourceCode":"    )\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(\n            f\"kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).__name__}\"\n        )\n    if has_swa_lut and lut_len <= 0:\n        raise ValueError(\"kv-canary: lut_len must be positive when has_swa_lut is True\")\n    if not has_swa_lut and lut_len != 0:\n        raise ValueError(\"kv-canary: lut_len must be 0 when has_swa_lut is False\")\n\n    _require_len(req_pool_indices, \"req_pool_indices\", bs)","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L147-L183","documentation":"The verify-pool capacity passed to the offsets kernel must be non-negative; negative capacity cannot describe any pool and would corrupt the kernel's bounds computations.","triggerScenarios":"Calling launch_plan_offsets_kernel with verify_capacity < 0, typically from a pool-size calculation that underflowed or an uninitialized value.","commonSituations":"Spec-decode verify pool sized as (total - write_capacity) that underflows; a config typo yielding negative pool size.","solutions":["Derive verify_capacity from verify_plan_out buffers or pool config and clamp at 0","Log pool sizes at startup to catch negative capacities early"],"exampleFix":"// before\nverify_capacity = total - write_capacity\n// after\nverify_capacity = int(verify_slot_indices.shape[0])  # or max(0, total - write_capacity)","handlingStrategy":"validation","validationCode":"verify_capacity = max(0, int(verify_capacity))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log pool capacities at startup and assert non-negative"],"tags":["kv-canary","capacity","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}