{"record":{"id":"23f24766ecda7758","repo":"sgl-project/sglang","slug":"kv-canary-expected-input-tensors-are-required-whe","errorCode":null,"errorMessage":"kv-canary: expected input tensors are required when enable_write_input_assert=True","messagePattern":"kv-canary: expected input tensors are required when enable_write_input_assert=True","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/write.py","lineNumber":203,"sourceCode":"    \"\"\"\n    canary_buf = context.canary_buf\n    real_kv_sources = context.real_kv_sources\n    if len(real_kv_sources) > consts.MAX_REAL_KV_SOURCES:\n        raise ValueError(\n            f\"kv-canary: at most {consts.MAX_REAL_KV_SOURCES} RealKvSource entries supported by the CUDA ABI, \"\n            f\"got {len(real_kv_sources)}\"\n        )\n\n    _assert_contiguous(canary_buf, \"canary_buf\")\n    _assert_contiguous(plan.write_offsets, \"plan.write_offsets\")\n    _assert_contiguous(plan.write_seed_slot_indices, \"plan.write_seed_slot_indices\")\n    _assert_contiguous(plan.write_num_valid_reqs, \"plan.write_num_valid_reqs\")\n    _assert_contiguous(input_ids, \"input_ids\")\n    _assert_contiguous(positions, \"positions\")\n    _assert_contiguous(out_cache_loc, \"out_cache_loc\")\n    if enable_write_input_assert:\n        if expected_input_tokens is None or expected_input_positions is None:\n            raise ValueError(\n                \"kv-canary: expected input tensors are required when enable_write_input_assert=True\"\n            )\n        _assert_contiguous(expected_input_tokens, \"expected_input_tokens\")\n        _assert_contiguous(expected_input_positions, \"expected_input_positions\")\n    else:\n        if expected_input_tokens is not None or expected_input_positions is not None:\n            raise ValueError(\n                \"kv-canary: expected input tensors must be None when enable_write_input_assert=False\"\n            )\n    _assert_contiguous(context.violation_ring, \"violation_ring\")\n    _assert_contiguous(context.violation_write_index, \"violation_write_index\")\n    _assert_contiguous(context.slot_run_counter, \"slot_run_counter\")\n    _assert_contiguous(context.kernel_run_counter, \"kernel_run_counter\")\n    _assert_contiguous(\n        context.enable_chain_position_assert, \"enable_chain_position_assert\"\n    )\n\n    padded_bufs, source_params = _build_real_kv_source_abi(","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/write.py#L185-L221","documentation":"When enable_write_input_assert=True the write kernel optionally cross-checks the incoming input_ids/positions against caller-supplied expected tensors; both expected_input_tokens and expected_input_positions must then be provided. Omitting them leaves the assert mode unusable, so the launcher raises.","triggerScenarios":"Calling launch_canary_write_kernel(..., enable_write_input_assert=True) with expected_input_tokens=None or expected_input_positions=None (only one or neither supplied).","commonSituations":"Enabling the assert flag from config but forgetting to thread the expected tensors through a wrapper; refactoring call sites where the assert was previously off.","solutions":["Pass both expected_input_tokens and expected_input_positions when enable_write_input_assert=True","If you do not need the cross-check, set enable_write_input_assert=False and pass neither tensor","Check wrapper signatures for a default of None silently dropping the tensors"],"exampleFix":"# before\nlaunch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=True)\n# after\nlaunch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=True,\n    expected_input_tokens=exp_tokens, expected_input_positions=exp_positions)","handlingStrategy":"validation","validationCode":"if enable_write_input_assert:\n    assert expected_input_tokens is not None and expected_input_positions is not None","typeGuard":"def assert_inputs_consistent(flag: bool, t, p) -> bool:\n    return (flag and t is not None and p is not None) or (not flag and t is None and p is None)","tryCatchPattern":null,"preventionTips":["Derive flag and tensors from one config branch","Write a tiny wrapper that fills defaults so callers cannot half-specify"],"tags":["kv-canary","argument-validation","assert-mode"],"backgroundTag":"missing-required-parameter","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}