{"record":{"id":"0189c318e7e52c1b","repo":"sgl-project/sglang","slug":"kv-canary-launch-canary-plan-kernels-verify-capac","errorCode":null,"errorMessage":"kv-canary: launch_canary_plan_kernels verify_capacity={verify_capacity} does not match verify_plan_out.verify_slot_indices.shape[0]={plan_verify_capacity}","messagePattern":"kv-canary: launch_canary_plan_kernels verify_capacity=(.+?) does not match verify_plan_out\\.verify_slot_indices\\.shape\\[0\\]=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/api.py","lineNumber":127,"sourceCode":"    bs = int(req_pool_indices.shape[0])\n    if bs > _PLAN_BS_BLOCK_SIZE:\n        raise ValueError(\n            f\"kv-canary: launch_canary_plan_kernels supports at most bs={_PLAN_BS_BLOCK_SIZE} reqs per launch, \"\n            f\"got bs={bs}. Bump _PLAN_BS_BLOCK_SIZE if real workloads need this.\"\n        )\n    if swa_window_size > 0 and full_to_swa_index_mapping is None:\n        raise ValueError(\n            \"kv-canary: launch_canary_plan_kernels requires full_to_swa_index_mapping when swa_window_size > 0\"\n        )\n\n    device = verify_plan_out.verify_slot_indices.device\n    verify_offsets_scratch = torch.empty(\n        _PLAN_BS_BLOCK_SIZE + 1, dtype=torch.int64, device=device\n    )\n\n    plan_verify_capacity = int(verify_plan_out.verify_slot_indices.shape[0])\n    if verify_capacity != plan_verify_capacity:\n        raise ValueError(\n            f\"kv-canary: launch_canary_plan_kernels verify_capacity={verify_capacity} does not match \"\n            f\"verify_plan_out.verify_slot_indices.shape[0]={plan_verify_capacity}\"\n        )\n\n    write_plan_out.write_offsets.zero_()\n\n    launch_plan_offsets_kernel(\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        full_to_swa_index_mapping=full_to_swa_index_mapping,\n        out_verify_offsets_scratch=verify_offsets_scratch,\n        out_write_offsets=write_plan_out.write_offsets,\n        out_write_seed_slot_indices=write_plan_out.write_seed_slot_indices,\n        out_verify_num_valid=verify_plan_out.verify_num_valid,\n        out_verify_enable=verify_plan_out.enable,\n        out_write_num_valid_reqs=write_plan_out.write_num_valid_reqs,","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/api.py#L109-L145","documentation":"The verify capacity scalar passed by the caller must exactly equal the first dimension of verify_plan_out.verify_slot_indices. The plan kernels write into preallocated output buffers whose sizes were derived from that tensor, so a mismatch would cause out-of-bounds or silently wrong plans.","triggerScenarios":"Calling launch_canary_plan_kernels where verify_capacity != verify_plan_out.verify_slot_indices.shape[0], e.g. capacity computed from a different pool than the one backing verify_slot_indices.","commonSituations":"Mixing capacities from the write pool and verify pool, or resizing the verify slot buffer after computing verify_capacity; version changes that changed which pool the verify buffer comes from.","solutions":["Set verify_capacity = int(verify_plan_out.verify_slot_indices.shape[0]) at the call site","Audit the buffer allocation code to ensure verify_slot_indices is sized by the same pool capacity used for verify_capacity"],"exampleFix":"// before\nverify_capacity = write_pool_capacity\nlaunch_canary_plan_kernels(..., verify_capacity=verify_capacity, ...)\n// after\nverify_capacity = int(verify_plan_out.verify_slot_indices.shape[0])\nlaunch_canary_plan_kernels(..., verify_capacity=verify_capacity, ...)","handlingStrategy":"validation","validationCode":"verify_capacity = int(verify_plan_out.verify_slot_indices.shape[0])\nassert verify_capacity >= 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive capacities from the output buffer shapes rather than independent pool variables","Keep a single source of truth for verify capacity"],"tags":["kv-canary","capacity-mismatch","argument-validation"],"backgroundTag":"buffer-size-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}