{"record":{"id":"27214a6ff37ca360","repo":"sgl-project/sglang","slug":"the-length-of-cache-salt-should-be-equal-to-the-ba","errorCode":null,"errorMessage":"The length of cache_salt should be equal to the batch size.","messagePattern":"The length of cache_salt should be equal to the batch size\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/io_struct.py","lineNumber":808,"sourceCode":"                    \"The length of extra_key should be equal to the batch size.\"\n                )\n            if any(not isinstance(value, str) for value in self.extra_key):\n                raise ValueError(\"Every extra_key should be a string.\")\n            self.extra_key = [value or None for value in self.extra_key]\n            self.extra_key = self.extra_key * self.parallel_sample_num\n        else:\n            raise ValueError(\"extra_key should be a list or a string.\")\n\n    def _normalize_cache_salt(self, num):\n        \"\"\"Normalize cache_salt for batch processing.\"\"\"\n        if self.cache_salt is None:\n            return\n        if isinstance(self.cache_salt, str):\n            value = self.cache_salt or None\n            self.cache_salt = [value] * num\n        elif isinstance(self.cache_salt, list):\n            if len(self.cache_salt) != self.batch_size:\n                raise ValueError(\n                    \"The length of cache_salt should be equal to the batch size.\"\n                )\n            if any(not isinstance(value, str) for value in self.cache_salt):\n                raise ValueError(\"Every cache_salt should be a string.\")\n            self.cache_salt = [value or None for value in self.cache_salt]\n            self.cache_salt = self.cache_salt * self.parallel_sample_num\n        else:\n            raise ValueError(\"cache_salt should be a list or a string.\")\n\n    def _normalize_bootstrap_params(self, num):\n        \"\"\"Normalize bootstrap parameters for batch processing.\"\"\"\n        # Normalize bootstrap_host\n        if self.bootstrap_host is None:\n            self.bootstrap_host = [None] * num\n        elif not isinstance(self.bootstrap_host, list):\n            self.bootstrap_host = [self.bootstrap_host] * num\n        elif isinstance(self.bootstrap_host, list):\n            self.bootstrap_host = self.bootstrap_host * self.parallel_sample_num","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/io_struct.py#L790-L826","documentation":"Raised when cache_salt is provided as a list whose length differs from batch_size. cache_salt prefixes the radix cache key to separate cache namespaces, and each request in a batch needs exactly one salt.","triggerScenarios":"GenerateReqInput(text=[...3 items...], cache_salt=['s1','s2']) — list of 2 for batch of 3.","commonSituations":"Reusing a single-element salt list for multi-request batches; dynamic batch assembly where the salt list is built separately from the prompts.","solutions":["Pass cache_salt as a single str to apply to all requests","Or build a list with exactly batch_size strings, one per request"],"exampleFix":"// before\nGenerateReqInput(text=['a','b','c'], cache_salt=['s1','s2'])\n// after\nGenerateReqInput(text=['a','b','c'], cache_salt='s1')","handlingStrategy":"validation","validationCode":"if isinstance(cache_salt, list):\n    assert len(cache_salt) == len(text) or len(cache_salt) == len(input_ids)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to a single str salt for uniform batches","Derive the salt list from the same loop that builds prompts"],"tags":["sglang","cache-salt","batching","input-validation"],"backgroundTag":"request-input-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}