{"record":{"id":"571e1263d3dc22e0","repo":"vllm-project/vllm","slug":"invalid-request-format-need-rank-and-keys","errorCode":null,"errorMessage":"Invalid request format: need 'rank' and 'keys'","messagePattern":"Invalid request format: need 'rank' and 'keys'","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"vllm/distributed/kv_transfer/kv_connector/v1/hf3fs/hf3fs_metadata_server.py","lineNumber":303,"sourceCode":"        if role == \"worker\" and num_pages > 0:\n            self.state.initialize_rank(rank, num_pages)\n            return self._json_response(\n                {\"message\": f\"Rank {rank} initialized with {num_pages} pages\"}\n            )\n        else:\n            raise HTTPException(\n                status_code=400, detail=\"Invalid initialization parameters\"\n            )\n\n    async def batch_allocate_pages_for_keys(self, request: Request):\n        \"\"\"Allocate one page for each key on a specific rank.\"\"\"\n        data = await self._read_json(request)\n        rank = data.get(\"rank\")\n        keys = data.get(\"keys\", [])\n\n        # Validate input format\n        if rank is None or not isinstance(keys, list):\n            raise HTTPException(\n                status_code=400, detail=\"Invalid request format: need 'rank' and 'keys'\"\n            )\n\n        try:\n            # Perform allocation\n            results = self.state.allocate_pages_for_keys(rank, keys)\n\n            # Convert results to response format\n            response = {\"rank\": rank, \"results\": list(results.items())}\n            return self._json_response(response)\n        except Exception as e:\n            raise HTTPException(\n                status_code=500, detail=f\"Allocation failed: {str(e)}\"\n            ) from e\n\n    async def confirm_write_for_keys(self, request: Request):\n        \"\"\"Confirm write operations for keys.\"\"\"\n        data = await self._read_json(request)","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/distributed/kv_transfer/kv_connector/v1/hf3fs/hf3fs_metadata_server.py#L285-L321","documentation":"The batch page-allocation endpoint requires a JSON body containing 'rank' (non-null) and 'keys' (a list). Missing rank, or keys that is not a list (e.g. a string or dict), yields HTTP 400 with this message.","triggerScenarios":"POSTing to the allocation endpoint with rank omitted/null, or keys absent / passed as a non-list JSON value.","commonSituations":"Client sends an empty keys value of the wrong type, serializes keys as a comma-separated string, or the JSON body is malformed so .get() returns defaults.","solutions":["Include both fields: {'rank': <int>, 'keys': [<str>, ...]}","Client-side validate before the request: rank is not None and isinstance(keys, list)","Log the exact request body on 400 to catch serialization bugs"],"exampleFix":"# before\nrequests.post(url, json={'keys': 'blk1,blk2'})  # rank missing, keys is str\n\n# after\nrequests.post(url, json={'rank': 1, 'keys': ['blk1', 'blk2']})","handlingStrategy":"validation","validationCode":"assert rank is not None and isinstance(keys, list)\nrequests.post(f'{server}/allocate', json={'rank': rank, 'keys': keys})","typeGuard":"def valid_alloc_payload(payload: dict) -> bool:\n    return payload.get('rank') is not None and isinstance(payload.get('keys'), list)","tryCatchPattern":"resp = requests.post(url, json=payload)\nif resp.status_code == 400 and 'rank' in resp.text:\n    raise SystemExit(f'Malformed allocate request: {payload}')","preventionTips":["Type-check request payloads client-side before POSTing","Serialize keys as a real JSON list, never a string"],"tags":["kv-transfer","hf3fs","metadata-server","http-400","validation","vllm"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}