sgl-project/sglang · error · HTTPException

Invalid rank parameter

Error message

Invalid rank parameter

What it means

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.

Source

Thrown at python/sglang/srt/entrypoints/engine_info_bootstrap_server.py:77

                with self.lock:
                    self.transfer_engine_info[tp_rank] = (
                        session_id,
                        weights_info_dict,
                    )

                logger.info(
                    f"Registered transfer engine info for tp_rank={tp_rank}, "
                    f"session_id={session_id}"
                )
                return PlainTextResponse("OK")
            except Exception as e:
                logger.error(f"Failed to register engine info: {e}")
                raise HTTPException(status_code=400, detail=str(e))

        @app.get("/get_transfer_engine_info")
        def get_transfer_engine_info(rank: int):
            if rank < 0:
                raise HTTPException(status_code=400, detail="Invalid rank parameter")

            with self.lock:
                info = self.transfer_engine_info.get(rank)

            if info is None:
                raise HTTPException(
                    status_code=404,
                    detail=f"No transfer engine info for rank {rank}",
                )

            return {"rank": rank, "remote_instance_transfer_engine_info": list(info)}

        config = uvicorn.Config(app, host=host, port=port, log_level="warning")
        self._server = uvicorn.Server(config)
        self._thread = threading.Thread(
            target=self._server.run,
            daemon=True,
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Fix the caller to pass ranks in [0, total_workers).
  2. Use 0-based iteration: for rank in range(world_size).
  3. Default missing rank to 0 or omit the request rather than sending -1.

Example fix

# before
r = requests.get(f"http://host:8101/get_transfer_engine_info?rank={rank - 1}")

# after
r = requests.get(f"http://host:8101/get_transfer_engine_info?rank={rank}")
Defensive patterns

Strategy: validation

Validate before calling

assert isinstance(rank, int) and 0 <= rank < world_size, f"bad rank {rank}"
r = requests.get(url, params={"rank": rank})

Type guard

def is_valid_rank(rank: object, world_size: int) -> bool:
    return isinstance(rank, int) and not isinstance(rank, bool) and 0 <= rank < world_size

Try / catch

r = requests.get(url, params={"rank": rank})
if r.status_code == 400:
    raise ValueError(f"rejected rank {rank}: {r.json()['detail']}")

Prevention

When it happens

Trigger: 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.

Common situations: Client code iterating ranks with a pre-decrement or using -1 as 'unspecified' placeholder; ported scripts from 1-based indexing conventions.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/c69a3d3621ff147c. Report an issue: GitHub.