{"record":{"id":"7d169ee1459a0280","repo":"sgl-project/sglang","slug":"kv-canary-max-seq-len-per-req-must-be-positive-g","errorCode":null,"errorMessage":"kv-canary: max_seq_len_per_req must be positive, got {max_seq_len_per_req}","messagePattern":"kv-canary: max_seq_len_per_req must be positive, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/kv_canary/capacities.py","lineNumber":58,"sourceCode":"        ):\n            if value <= 0:\n                raise ValueError(f\"kv-canary: {name} must be positive, got {value}\")\n\n    @classmethod\n    def from_args(\n        cls,\n        *,\n        req_to_token_pool_size: int,\n        max_seq_len_per_req: int,\n        pool_slot_count: int,\n    ) -> CanaryLaunchCapacities:\n        if req_to_token_pool_size <= 0:\n            raise ValueError(\n                \"kv-canary: req_to_token_pool_size must be positive, \"\n                f\"got {req_to_token_pool_size}\"\n            )\n        if max_seq_len_per_req <= 0:\n            raise ValueError(\n                \"kv-canary: max_seq_len_per_req must be positive, \"\n                f\"got {max_seq_len_per_req}\"\n            )\n        if pool_slot_count <= 0:\n            raise ValueError(\n                f\"kv-canary: pool_slot_count must be positive, got {pool_slot_count}\"\n            )\n\n        cuda_graph_config = get_exec().graph.cuda_graph_config\n        cuda_graph_max_bs = (\n            cuda_graph_config.decode.max_bs if cuda_graph_config is not None else 0\n        ) or 0\n        if cuda_graph_max_bs < 0:\n            raise ValueError(\n                f\"kv-canary: cuda_graph_max_bs must be non-negative, got {cuda_graph_max_bs}\"\n            )\n\n        spec_num_draft_tokens = get_spec().speculative_num_draft_tokens","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/kv_canary/capacities.py#L40-L76","documentation":"from_args requires max_seq_len_per_req > 0 because the canary needs at least one token slot per request to compute write/verify capacities. A non-positive max sequence length makes per-request capacity math meaningless, so ValueError is raised at canary installation time.","triggerScenarios":"Calling install_canary/from_args with max_seq_len_per_req <= 0, e.g. server started with --max-total-tokens or context-length flags that collapse max_seq_len_per_req to 0.","commonSituations":"Over-restrictive memory flags (--max-total-tokens 0, tiny context length) combined with --kv-canary; miscomputed derived context length in custom launch scripts.","solutions":["Ensure max_seq_len_per_req is >= 1 (check --context-length and memory-related flags)","Remove flags that force the derived max sequence length to zero","Disable the canary with --kv-canary none if it is not needed"],"exampleFix":"# before\n--context-length 0 --kv-canary log\n\n# after\n--context-length 8192 --kv-canary log","handlingStrategy":"validation","validationCode":"if max_seq_len_per_req <= 0:\n    raise SystemExit(\"max_seq_len_per_req must be > 0; check --context-length\")\ncaps = CanaryLaunchCapacities.from_args(\n    max_seq_len_per_req=max_seq_len_per_req, ...\n)","typeGuard":"def is_valid_seq_len(n: int) -> bool:\n    return isinstance(n, int) and n > 0","tryCatchPattern":null,"preventionTips":["Keep --context-length positive when the canary is on","Validate derived max_seq_len in launch scripts","Add smoke tests with minimal-but-valid server args"],"tags":["kv-canary","validation","seq-len","value-error"],"backgroundTag":"config-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}