{"record":{"id":"c69a3d3621ff147c","repo":"sgl-project/sglang","slug":"invalid-rank-parameter","errorCode":null,"errorMessage":"Invalid rank parameter","messagePattern":"Invalid rank parameter","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/entrypoints/engine_info_bootstrap_server.py","lineNumber":77,"sourceCode":"                with self.lock:\n                    self.transfer_engine_info[tp_rank] = (\n                        session_id,\n                        weights_info_dict,\n                    )\n\n                logger.info(\n                    f\"Registered transfer engine info for tp_rank={tp_rank}, \"\n                    f\"session_id={session_id}\"\n                )\n                return PlainTextResponse(\"OK\")\n            except Exception as e:\n                logger.error(f\"Failed to register engine info: {e}\")\n                raise HTTPException(status_code=400, detail=str(e))\n\n        @app.get(\"/get_transfer_engine_info\")\n        def get_transfer_engine_info(rank: int):\n            if rank < 0:\n                raise HTTPException(status_code=400, detail=\"Invalid rank parameter\")\n\n            with self.lock:\n                info = self.transfer_engine_info.get(rank)\n\n            if info is None:\n                raise HTTPException(\n                    status_code=404,\n                    detail=f\"No transfer engine info for rank {rank}\",\n                )\n\n            return {\"rank\": rank, \"remote_instance_transfer_engine_info\": list(info)}\n\n        config = uvicorn.Config(app, host=host, port=port, log_level=\"warning\")\n        self._server = uvicorn.Server(config)\n        self._thread = threading.Thread(\n            target=self._server.run,\n            daemon=True,\n        )","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/engine_info_bootstrap_server.py#L59-L95","documentation":"The /get_transfer_engine_info endpoint validates its integer rank query parameter and rejects negative values with HTTP 400 'Invalid rank parameter'. Ranks are expected to be zero-based worker indices.","triggerScenarios":"GET /get_transfer_engine_info?rank=-1 (or any negative number), typically from an off-by-one bug such as rank-1 before a loop that starts at 0, or a default sentinel of -1 leaking into the URL.","commonSituations":"Client code iterating ranks with a pre-decrement or using -1 as 'unspecified' placeholder; ported scripts from 1-based indexing conventions.","solutions":["Fix the caller to pass ranks in [0, total_workers).","Use 0-based iteration: for rank in range(world_size).","Default missing rank to 0 or omit the request rather than sending -1."],"exampleFix":"# before\nr = requests.get(f\"http://host:8101/get_transfer_engine_info?rank={rank - 1}\")\n\n# after\nr = requests.get(f\"http://host:8101/get_transfer_engine_info?rank={rank}\")","handlingStrategy":"validation","validationCode":"assert isinstance(rank, int) and 0 <= rank < world_size, f\"bad rank {rank}\"\nr = requests.get(url, params={\"rank\": rank})","typeGuard":"def is_valid_rank(rank: object, world_size: int) -> bool:\n    return isinstance(rank, int) and not isinstance(rank, bool) and 0 <= rank < world_size","tryCatchPattern":"r = requests.get(url, params={\"rank\": rank})\nif r.status_code == 400:\n    raise ValueError(f\"rejected rank {rank}: {r.json()['detail']}\")","preventionTips":["Iterate ranks with range(world_size), never rank-1 pre-decrements.","Don't use -1 as an 'unset rank' sentinel in URLs."],"tags":["sglang","http-400","parameter-validation","bootstrap-server"],"backgroundTag":"invalid-parameter-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}