{"record":{"id":"1de5051db9714292","repo":"sgl-project/sglang","slug":"kv-canary-write-req-capacity-must-be-non-negative","errorCode":null,"errorMessage":"kv-canary: write_req_capacity must be non-negative, got {write_req_capacity}","messagePattern":"kv-canary: write_req_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":161,"sourceCode":"    )\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(\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\")","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L143-L179","documentation":"The write-request capacity must be non-negative; a negative value would make buffer sizing and bounds checks in the offsets kernel meaningless and indicates corrupted capacity plumbing.","triggerScenarios":"Calling launch_plan_offsets_kernel with write_req_capacity < 0, e.g. from subtracting free slots and underflowing, or from an uninitialized -1 sentinel.","commonSituations":"Capacity computed as (free - pending) underflowing when more requests are in flight than slots; passing a 'not set' sentinel like -1 instead of a real capacity.","solutions":["Compute write_req_capacity from the actual write pool size, clamped at 0","Replace -1 sentinel values with the real capacity or 0"],"exampleFix":"// before\nwrite_req_capacity = pool_size - num_running  # can go negative\n// after\nwrite_req_capacity = max(0, pool_size - num_running)","handlingStrategy":"validation","validationCode":"write_req_capacity = max(0, int(write_req_capacity))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp capacity arithmetic at 0","Never use -1 sentinels for capacities"],"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"}