{"record":{"id":"a5259f8458270c81","repo":"sgl-project/sglang","slug":"inconsistent-receive-count-for-req-id-req-id-re","errorCode":null,"errorMessage":"Inconsistent receive_count for req_id={req_id}: registered {registered_count}, got {expected_destination_count}","messagePattern":"Inconsistent receive_count for req_id=(.+?): registered (.+?), got (.+?)","errorType":"http","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"python/sglang/srt/disaggregation/encoder/server.py","lineNumber":724,"sourceCode":"            self.req_states.pop(req_id, None)\n        await self.delivery.release(state)\n        state.embedding_data = None\n        if not state.preserve_metadata_on_release:\n            await meta_registry.discard(req_id)\n\n    async def register_embedding_destinations(\n        self,\n        req_id: str,\n        expected_destination_count: int,\n        destination_urls: Iterable[str],\n    ) -> None:\n        async with rid_lock:\n            if req_id not in rid_to_receive_endpoint:\n                rid_to_receive_endpoint[req_id] = set()\n                rid_to_receive_count[req_id] = expected_destination_count\n            registered_count = rid_to_receive_count[req_id]\n            if registered_count != expected_destination_count:\n                raise BadRequestError(\n                    f\"Inconsistent receive_count for req_id={req_id}: \"\n                    f\"registered {registered_count}, got {expected_destination_count}\"\n                )\n            rid_to_receive_endpoint[req_id].update(destination_urls)\n\n        cond = await _get_receive_condition(req_id)\n        async with cond:\n            cond.notify_all()\n\n    def _infer_embedding_dims(self) -> dict:\n        \"\"\"Infer per-modality embedding dimensions from hf_config at init time.\"\"\"\n        default = self.model_config.hidden_size\n        hf_cfg = self.model_config.hf_config\n        thinker_cfg = getattr(hf_cfg, \"thinker_config\", None)\n        dims = {\n            Modality.IMAGE: default,\n            Modality.VIDEO: default,\n            Modality.AUDIO: default,","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/disaggregation/encoder/server.py#L706-L742","documentation":"register_embedding_destinations memoizes the expected receive_count per req_id on first registration and enforces that every subsequent registration for the same req_id declares the identical count. A mismatch raises BadRequestError, guarding the refcount that controls when staged embeddings may be released.","triggerScenarios":"Decoder TP ranks registering destination URLs for the same req_id with different receive_count values — e.g. some ranks pass decoder TP size while others pass 1, or a changed TP configuration between calls; also triggered by a buggy client computing the count differently per call.","commonSituations":"Decoder tensor-parallel size changed or read inconsistently across ranks; a client bug or stale cached config causing rank-dependent counts; retrying registration after a partial failure with an updated count.","solutions":["Make all ranks compute receive_count from the same source (decoder TP size / world size) at request time","Fix or restart the component holding a stale TP configuration so all ranks agree","Do not change receive_count between retries for the same req_id; use a fresh req_id if the topology changed"],"exampleFix":"# before\nrank0.register(req_id, urls, receive_count=1)\nrank1.register(req_id, urls, receive_count=tp_size)\n# after\nall_ranks.register(req_id, urls, receive_count=tp_size)  # consistent","handlingStrategy":"validation","validationCode":"if req_id in rid_to_receive_count and rid_to_receive_count[req_id] != expected_count:\n    raise BadRequestError('count drift detected before registration')","typeGuard":null,"tryCatchPattern":"try:\n    await register_embedding_destinations(req_id, urls, count)\nexcept BadRequestError:\n    regenerate_req_id_and_replay_request()  # topology changed mid-flight","preventionTips":["Compute receive_count once from world size and broadcast it","Restart components together after changing TP size","Never vary counts across retries of the same req_id"],"tags":["validation","refcount","dp","tensor-parallel"],"backgroundTag":"inconsistent-request-metadata","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}