{"record":{"id":"385b109bc10f7f48","repo":"sgl-project/sglang","slug":"rank-consensus-got-unexpected-keyword-argument-s","errorCode":null,"errorMessage":"rank_consensus() got unexpected keyword argument(s): {list(kwargs)}","messagePattern":"rank_consensus\\(\\) got unexpected keyword argument\\(s\\): (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/rank_consensus_checker.py","lineNumber":77,"sourceCode":"    def foo():\n        return 1\n\n    * Assert for part of the results are same.\n    @rank_consensus(same_results = [\"result.some_field\"]\n    def foo():\n        return SomeObject()\n\n    @rank_consensus(same_results = [\"result.field\", \"len(result.field2)\"]\n    def foo():\n        return SomeObject()\n\n    * Assert the function is called by all ranks and all parameters and results are the same.\n    @rank_consensus(same_params = True, same_results = True)\n    def foo():\n        return 1\n    \"\"\"\n    if kwargs:\n        raise TypeError(\n            f\"rank_consensus() got unexpected keyword argument(s): \" f\"{list(kwargs)}\"\n        )\n\n    params_selector = _normalize_selector(same_params, \"same_params\")\n    results_selector = _normalize_selector(same_results, \"same_results\")\n\n    def decorator(func: Callable) -> Callable:\n        # This decorator function called at import time.  So it should be zero runtime overhead\n        # when the consensus checker is disabled.\n        if not envs.SGLANG_ENABLE_RANK_CONSENSUS_CHECKER.get():\n            return func\n\n        # Unwrap static/class-method descriptors so we always operate on the\n        # raw function. We remember the descriptor type so we can re-wrap the\n        # result and the class-body descriptor protocol keeps working.\n        if isinstance(func, (classmethod, staticmethod)):\n            raw_func = func.__func__\n            descriptor_type = type(func)","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/rank_consensus_checker.py#L59-L95","documentation":"The rank_consensus decorator factory accepts only positional usage — rank_consensus(func) — and no keyword arguments; any kwargs trigger this TypeError. Configuration is done via the decorator's own named parameters (same_params, same_results), not via call-time kwargs.","triggerScenarios":"Writing @rank_consensus(check=True) or calling rank_consensus(fn, foo=1) — i.e. passing unexpected keyword arguments to the decorator factory itself.","commonSituations":"Developers assuming the checker takes options at decoration time like other decorators, or copy-pasting from a different consensus helper's API.","solutions":["Use only the supported parameters: @rank_consensus(same_params=..., same_results=...)","If decorating directly without options, write @rank_consensus (no parens)","Check the decorator signature in rank_consensus_checker.py for supported knobs"],"exampleFix":"# before\n@rank_consensus(mode='strict')\ndef check(): ...\n# after\n@rank_consensus(same_params=True, same_results=True)\ndef check(): ...","handlingStrategy":"type-guard","validationCode":"import inspect\nallowed = set(inspect.signature(rank_consensus).parameters) - {'kwargs'}\nassert set(kwargs) <= set()","typeGuard":"null","tryCatchPattern":"try:\n    rank_consensus(fn, **opts)\nexcept TypeError as e:\n    if 'unexpected keyword' in str(e):\n        rank_consensus(fn)  # decorate without options","preventionTips":["Read the decorator signature before passing options","Only use same_params/same_results as decorator-time named args","Pin decorator usage patterns in a shared internal helper"],"tags":["decorator","distributed","rank-consensus","api-misuse","sglang"],"backgroundTag":"invalid-decorator-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}