{"record":{"id":"3fb52eff0ebba271","repo":"sgl-project/sglang","slug":"invalid-join-mode-mode","errorCode":null,"errorMessage":"Invalid join mode: {mode}","messagePattern":"Invalid join mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/interpreter.py","lineNumber":1073,"sourceCode":"            src_vars = self.src_state.stream_executor.variables\n            src_var_set = set(src_vars.keys())\n            for child_state in self.states:\n                child_state.stream_executor.sync()\n                child_vars = child_state.stream_executor.variables\n                new_vars = set(child_vars.keys()) - src_var_set\n\n                for k in new_vars:\n                    if k in src_vars:\n                        src_vars[k].append(child_vars[k])\n                    else:\n                        src_vars[k] = [child_vars[k]]\n        elif mode == \"concate_and_append\":\n            # Concatenate and append KV cache\n            self.src_state += SglConcateAndAppend(self.states)\n            # Need a sync here. Otherwise, `states` can be deleted.\n            self.src_state.stream_executor.sync()\n        else:\n            raise ValueError(f\"Invalid join mode: {mode}\")\n\n        for s in self.states:\n            s.stream_executor.end()\n\n    def __getitem__(self, i: int):\n        return self.states[i]\n\n    def __setitem__(self, i: int, value):\n        assert self.states[i] == value\n\n    def __iadd__(self, other):\n        if isinstance(other, Callable):\n            # lambda function\n            for i in range(len(self.states)):\n                self.states[i] += other(i)\n        elif isinstance(other, SglExpr):\n            for i in range(len(self.states)):\n                self.states[i] += other","sourceCodeStart":1055,"sourceCodeEnd":1091,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/interpreter.py#L1055-L1091","documentation":"Raised by the forked-state collection's join() when `mode` is not one of the supported join modes ('concate_and_append' for KV-cache concatenation, and the string-concat mode handled above). It guards against silently discarding forked branches due to a typo'd mode name.","triggerScenarios":"Calling states.join(mode=\"concat\") or any misspelling/unsupported mode; passing a mode string introduced in a different sglang version.","commonSituations":"Typos like 'concatenate_and_append' vs 'concate_and_append'; code written against newer API run on older sglang; programmatic mode selection with unvalidated input.","solutions":["Use exactly the supported mode strings, e.g. mode=\"concate_and_append\" for KV-cache join","Check the installed sglang version's interpreter.py for the accepted modes","Validate mode against an allowlist before calling join"],"exampleFix":"# before\njoined = forked.join(mode=\"concat_and_append\")\n# after\njoined = forked.join(mode=\"concate_and_append\")","handlingStrategy":"validation","validationCode":"VALID_JOIN_MODES = {\"concate_and_append\", \"variable_append\"}  # check your version's interpreter.py\nif mode not in VALID_JOIN_MODES:\n    raise ValueError(f\"mode must be one of {VALID_JOIN_MODES}\")\njoined = forked.join(mode=mode)","typeGuard":"def is_join_mode(m: str) -> bool:\n    return isinstance(m, str) and m in {\"concate_and_append\", \"variable_append\"}","tryCatchPattern":"try:\n    joined = forked.join(mode=mode)\nexcept ValueError as e:\n    if \"Invalid join mode\" in str(e):\n        joined = forked.join(mode=\"concate_and_append\")\n    else:\n        raise","preventionTips":["Copy mode strings from the installed sglang's interpreter.py, not from memory","Keep join-mode constants in one place in your codebase","Add a smoke test covering each join mode you use after upgrading sglang"],"tags":["validation","fork-join","dsl","enum-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}