Fix JACCL GID selection on Apple Thunderbolt RDMA (errno 22 RTR fail)
Closes #3467.
Proposed changes
Fix [jaccl] Changing queue pair to RTR failed with errno 22 on Apple Thunderbolt RDMA.
Connection::info() in rdma.cpp selects the local GID by scanning the GID table for an IPv4-mapped IPv6 GID (::ffff:x.x.x.x — the RoCE v2 standard). Apple Thunderbolt RDMA exposes only link-local IPv6 GIDs (fe80::...), so the filter never matches and gid is left uninitialized. The garbage value is propagated to the peer via the side channel, causing the kernel to reject the QP RTR transition with EINVAL.
This regression was introduced by #3412 (Jaccl refactor) when the pre-existing hardcoded query_gid(ctx, 1, 1, &gid) was replaced with the filter loop. See full root-cause analysis in the linked issue.
Changes
mlx/distributed/jaccl/lib/jaccl/rdma.cpp:
- Zero-initialize
gidto avoid undefined behavior when no GID matches. - After the IPv4-mapped scan, fall back to the first non-zero GID — preferring index 1 (matches pre-refactor behavior; index 0 on Apple TB is typically derived from a non-RDMA interface and routes elsewhere, causing errno 60 ETIMEDOUT instead of errno 22).
The IPv4-mapped path remains the preferred match, so RoCE v2 setups are unaffected.
Test plan
- 2× Mac Studio M4 Max, Thunderbolt 5 mesh, macOS 26.4.1
- Before patch:
mlx.distributed.init(backend="jaccl")→errno 22 RTR fail - After patch (preferring index 0 in fallback):
errno 60 ETIMEDOUT(wrong port — index 0 is non-RDMA on Apple) - After patch (preferring index 1 in fallback): JACCL init succeeds,
all_sumbenchmark runs, sustained tensor-parallel inference (Qwen3.6-27B-4bit) works end-to-end
Checklist
- [x] I have read the CONTRIBUTING document
- [x] I have run
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes - [ ] I have added tests that prove my fix is effective or that my feature works
- [x] I have updated the necessary documentation (if needed)
Note: no unit tests added — the GID selection is platform-dependent (Apple TB vs RoCE v2 hardware) and the tests in mlx/distributed/jaccl/lib/examples/ are runtime benchmarks rather than unit tests. Happy to add a mock-based unit test if reviewers prefer.