{"record":{"id":"804df4dd181ecb17","repo":"xai-org/x-algorithm","slug":"async-emb-received-an-invalid-rank-or-world-size","errorCode":null,"errorMessage":"async_emb received an invalid rank or world size","messagePattern":"async_emb received an invalid rank or world size","errorType":"exception","errorClass":"std::invalid_argument","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/cuda/async_emb/src/async_emb_comm.cc","lineNumber":231,"sourceCode":"    }\n  }\n  if (result != ncclSuccess) {\n    LOG(ERROR) << \"ncclCommFinalize failed: \" << ncclGetErrorString(result);\n    abortCommunicator(\"ncclCommFinalize failed\");\n    comm_ = nullptr;\n    return;\n  }\n\n  result = ncclCommDestroy(comm_);\n  if (result != ncclSuccess) {\n    LOG(ERROR) << \"ncclCommDestroy failed: \" << ncclGetErrorString(result);\n  }\n  comm_ = nullptr;\n}\n\nstd::vector<std::vector<uint8_t>> AsyncEmbContext::reset(int rank, int world_size) {\n  if (world_size <= 0 || rank < 0 || rank >= world_size) {\n    throw std::invalid_argument(\"async_emb received an invalid rank or world size\");\n  }\n  if (world_size != world_size_) {\n    throw std::invalid_argument(\n        \"async_emb world size changed from \" + std::to_string(world_size_) + \" to \" +\n        std::to_string(world_size)\n    );\n  }\n  if ((world_size & (world_size - 1)) != 0) {\n    throw std::invalid_argument(\"async_emb currently requires power-of-two EP\");\n  }\n\n  rank_ = rank;\n  initialized_ = false;\n  std::vector<std::vector<uint8_t>> bootstrap(world_size);\n  if (rank != 0) {\n    return bootstrap;\n  }\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/cuda/async_emb/src/async_emb_comm.cc#L213-L249","documentation":"AsyncEmbContext::reset validates its rank/world_size arguments: world_size must be positive, rank must be in [0, world_size). Any violation throws invalid_argument before any NCCL work starts.","triggerScenarios":"Calling reset(rank, world_size) with world_size<=0, rank<0, or rank>=world_size — e.g. passing world_size where rank is expected, or using rank from a launcher that numbers ranks 1..N instead of 0..N-1.","commonSituations":"Argument-order swaps when wiring torch.distributed.get_rank()/get_world_size(); MPI-style 1-based ranks; world_size read as 0 because dist.init_process_group had not run yet.","solutions":["Verify rank and world_size come from the same initialized process group and are 0-based rank, 1-based world size.","Check for swapped arguments at the call site.","Log rank/world_size immediately before calling reset to catch 0/-1 sentinel values."],"exampleFix":"# before (swapped)\nctx.reset(world_size=dist.get_world_size(), rank=dist.get_rank())\n\n# after\nrank, world_size = dist.get_rank(), dist.get_world_size()\nassert 0 <= rank < world_size\nctx.reset(rank, world_size)","handlingStrategy":"validation","validationCode":"if (world_size <= 0 || rank < 0 || rank >= world_size)\n    throw std::invalid_argument(\"bad rank/world_size\");\nctx.reset(rank, world_size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive rank/world_size from one initialized process group only.","Prefer named parameters or a struct to avoid argument-order swaps."],"tags":["validation","rank","world-size","distributed","async-emb"],"backgroundTag":"invalid-argument-validation","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}