{"record":{"id":"b85047f626c3a8b1","repo":"sgl-project/sglang","slug":"missing-adaptive-runtime-state-for-steps-speculat","errorCode":null,"errorMessage":"Missing adaptive runtime state for steps={speculative_num_steps}","messagePattern":"Missing adaptive runtime state for steps=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/speculative/adaptive_runtime_state.py","lineNumber":131,"sourceCode":"    def activate_step_by_batch(self, batch_size: int) -> None:\n        target = self.params.get_steps_for_batch(batch_size)\n        if target != self.worker.speculative_num_steps:\n            self._activate(target)\n\n    def on_verify_complete(\n        self, num_correct_drafts_per_req: list[int], batch_size: int\n    ) -> None:\n        \"\"\"Feed verify results; switch runtime state if EMA warrants it.\"\"\"\n        new_step = self.params.on_verify_complete(\n            num_correct_drafts_per_req, batch_size\n        )\n        if new_step is not None:\n            self._activate(new_step)\n\n    def _activate(self, speculative_num_steps: int) -> None:\n        state = self._states.get(speculative_num_steps)\n        if state is None:\n            raise ValueError(\n                f\"Missing adaptive runtime state for steps={speculative_num_steps}\"\n            )\n        self.worker.apply_runtime_state(state)\n","sourceCodeStart":113,"sourceCodeEnd":135,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/speculative/adaptive_runtime_state.py#L113-L135","documentation":"AdaptiveRuntimeState._activate looks up a runtime state by speculative step count and finds none registered. The adaptive spec-decoding runtime must have states pre-created for every candidate step value before activation.","triggerScenarios":"Calling activate/apply paths with a speculative_num_steps that was never registered in _states — e.g. a config lists candidate_steps [1,3,7] but the scheduler later requests steps=5.","commonSituations":"Mismatch between speculative_adaptive_config candidate_steps and the actual steps chosen at runtime; partially initialized worker; adding a new step count without rebuilding states (init_states not called after config change).","solutions":["Ensure speculative_adaptive_config's candidate_steps covers every step value the runtime can select","Call init_states (full re-initialization) after changing candidate steps so all states are pre-built","Check for stale configs on the worker vs scheduler side"],"exampleFix":"# before\n{\"1\": {\"candidate_steps\": [1, 3]}}\n# after\n{\"1\": {\"candidate_steps\": [1, 3, 5, 7]}}  # include 5 if runtime may select it","handlingStrategy":"validation","validationCode":"allowed = set(candidate_steps_from_config)\nassert requested_steps in allowed, f'steps={requested_steps} not in {sorted(allowed)}'","typeGuard":null,"tryCatchPattern":"catch ValueError from _activate and trigger init_states rebuild once, then retry","preventionTips":["Keep candidate_steps exhaustive over selectable step counts","Re-init states after any adaptive-config change"],"tags":["sglang","speculative-decoding","adaptive-runtime","state-management"],"backgroundTag":"state-not-initialized","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}