{"record":{"id":"8390bfa174313ae0","repo":"sgl-project/sglang","slug":"prefetch-threshold-must-be-int-got-type-prefetch","errorCode":null,"errorMessage":"prefetch_threshold must be int, got {type(prefetch_threshold).__name__}","messagePattern":"prefetch_threshold must be int, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/hiradix_cache.py","lineNumber":765,"sourceCode":"                raise e\n\n        defaults = PrefetchTimeoutConfig()\n        prefetch_threshold = extra_config.pop(\"prefetch_threshold\", 256)  # tokens\n        prefetch_timeout_base = extra_config.pop(\n            \"prefetch_timeout_base\", defaults.base\n        )  # seconds\n        prefetch_timeout_per_ki_token = extra_config.pop(\n            \"prefetch_timeout_per_ki_token\", defaults.per_ki_token\n        )  # seconds per 1024 tokens\n        prefetch_timeout_max = extra_config.pop(\n            \"prefetch_timeout_max\", defaults.max\n        )  # seconds, upper bound for the linear timeout\n        hicache_storage_pass_prefix_keys = extra_config.pop(\n            \"hicache_storage_pass_prefix_keys\", False\n        )\n\n        if not isinstance(prefetch_threshold, int):\n            raise ValueError(\n                f\"prefetch_threshold must be int, got {type(prefetch_threshold).__name__}\"\n            )\n        if not isinstance(prefetch_timeout_base, (int, float)):\n            raise ValueError(\n                f\"prefetch_timeout_base must be number, got {type(prefetch_timeout_base).__name__}\"\n            )\n        if not isinstance(prefetch_timeout_per_ki_token, (int, float)):\n            raise ValueError(\n                f\"prefetch_timeout_per_ki_token must be number, got {type(prefetch_timeout_per_ki_token).__name__}\"\n            )\n        if not isinstance(prefetch_timeout_max, (int, float)):\n            raise ValueError(\n                f\"prefetch_timeout_max must be number, got {type(prefetch_timeout_max).__name__}\"\n            )\n        if not isinstance(hicache_storage_pass_prefix_keys, bool):\n            raise ValueError(\n                \"hicache_storage_pass_prefix_keys must be bool, got \"\n                f\"{type(hicache_storage_pass_prefix_keys).__name__}\"","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/hiradix_cache.py#L747-L783","documentation":"After parsing the storage backend extra config (JSON string or toml/yaml file), HiRadixCache validates that prefetch_threshold is an int; YAML/TOML files can produce floats (e.g. 2.0) or strings (\"2\"), and this check rejects anything that is not exactly isinstance(int). Note bool is a subclass of int in Python, but floats/strings fail.","triggerScenarios":"A .yaml/.toml extra-config file containing prefetch_threshold: 2.0 (YAML parses to float), prefetch_threshold: \"2\" (quoted string), or a JSON string with \"prefetch_threshold\": 1.5.","commonSituations":"Writing the extra config by hand in YAML where 2.0 is natural; copy-pasting values from docs that use floats; tools serializing numbers as floats; passing a string value from an env var.","solutions":["Change the value to a plain integer literal: prefetch_threshold: 2 (no decimal point, no quotes)","If editing YAML, ensure the key isn't quoted and has no trailing .0","Re-run and confirm the rest of the timeout fields also satisfy their (int, float) checks"],"exampleFix":"# before (hicache.yaml)\nprefetch_threshold: 2.0\n\n# after\nprefetch_threshold: 2","handlingStrategy":"type-guard","validationCode":"assert isinstance(cfg.get(\"prefetch_threshold\", 2), int) and not isinstance(cfg.get(\"prefetch_threshold\", 2), bool), \"prefetch_threshold must be a plain int\"","typeGuard":"def is_int_not_bool(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Write YAML numeric fields without decimals or quotes","Validate parsed extra-config types before launching the server"],"tags":["hicache","config-validation","prefetch","type-error"],"backgroundTag":"config-type-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}