{"record":{"id":"3024eeb0edb54b7a","repo":"sgl-project/sglang","slug":"kv-canary-kv-canary-must-be-one-of-none-log-raise","errorCode":null,"errorMessage":"kv-canary: kv_canary must be one of none/log/raise, got {mode_raw!r}","messagePattern":"kv-canary: kv_canary must be one of none/log/raise, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/kv_canary/config.py","lineNumber":66,"sourceCode":"            ForwardBatch.init_new) and compare against the canary's stored tokens at verify time.\n            Independent of ``enable_write_input_assert``.\n        stats_print_every_n_steps: 0 disables periodic stats logging; positive N prints\n            \"canary protected N tokens, ran M sweep passes, K violations so far\" every N forward steps.\n    \"\"\"\n\n    mode: CanaryMode\n    ring_capacity: int\n    sweep_interval: int\n    real_kv_hash_mode: RealKvHashMode\n    enable_write_input_assert: bool\n    enable_verify_token_assert: bool\n    stats_print_every_n_steps: int\n\n    @classmethod\n    def from_env(cls, server_args: ServerArgs) -> CanaryConfig:\n        mode_raw = server_args.kv_canary.strip().lower()\n        if mode_raw not in (\"none\", \"log\", \"raise\"):\n            raise ValueError(\n                f\"kv-canary: kv_canary must be one of none/log/raise, got {mode_raw!r}\"\n            )\n\n        real_kv_raw = server_args.kv_canary_real_data.strip().upper()\n\n        return cls(\n            mode=CanaryMode(mode_raw),\n            ring_capacity=envs.SGLANG_KV_CANARY_RING_CAPACITY.get(),\n            sweep_interval=server_args.kv_canary_sweep_interval,\n            real_kv_hash_mode=RealKvHashMode[real_kv_raw],\n            enable_write_input_assert=envs.SGLANG_KV_CANARY_ENABLE_WRITE_INPUT_ASSERT.get(),\n            enable_verify_token_assert=envs.SGLANG_KV_CANARY_ENABLE_VERIFY_TOKEN_ASSERT.get(),\n            stats_print_every_n_steps=envs.SGLANG_KV_CANARY_STATS_PRINT_EVERY_N_STEPS.get(),\n        )\n","sourceCodeStart":48,"sourceCodeEnd":81,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/kv_canary/config.py#L48-L81","documentation":"CanaryConfig.from_env parses the --kv-canary CLI value (trimmed and lowercased) and only accepts the modes 'none', 'log', or 'raise'. Any other string raises ValueError with the offending value shown via repr.","triggerScenarios":"Passing --kv-canary <anything-else> (e.g. 'off', 'warn', 'True', '1', or a typo like 'rasie'); the value is stripped and lowercased but still must equal one of the three exact mode names.","commonSituations":"Typos or wrong vocabulary on the command line; scripts porting from another tool where the flag accepts boolean-ish values; assuming any truthy string enables the canary.","solutions":["Use exactly one of: --kv-canary none, --kv-canary log, or --kv-canary raise","Check spelling (common typo: 'rasie'); the parser is case-insensitive but exact-match on mode name","Omit the flag entirely if the default (none) is acceptable"],"exampleFix":"# before\n--kv-canary warn\n\n# after\n--kv-canary log","handlingStrategy":"type-guard","validationCode":"raw = server_args.kv_canary.strip().lower()\nif raw not in (\"none\", \"log\", \"raise\"):\n    raise SystemExit(f\"--kv-canary must be none|log|raise, got {raw!r}\")\ncfg = CanaryConfig.from_env(server_args)","typeGuard":"def is_valid_canary_mode(v: str) -> bool:\n    return isinstance(v, str) and v.strip().lower() in (\"none\", \"log\", \"raise\")","tryCatchPattern":"try:\n    cfg = CanaryConfig.from_env(server_args)\nexcept ValueError as e:\n    if 'kv_canary must be one of' in str(e):\n        print('--kv-canary accepts only none|log|raise'); raise SystemExit(2)\n    raise","preventionTips":["Remember the exact vocabulary: none | log | raise (case-insensitive)","Add argparse choices=['none','log','raise'] in wrapper scripts","Double-check spelling (e.g. 'rasie') when copying commands"],"tags":["kv-canary","config","cli-args","enum-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}