Commit db8be74
fix(jumanji): prevent IndexError in routing render when no valid nodes (#416)
## Summary
Fix an IndexError in the Jumanji routing renderer's `build_edges()`
method that crashes when an agent has no valid connected nodes.
## Root Cause
In `envpool/jumanji/_official_render/routing.py` line 656:
```python
len_conn = np.where(conn_group != -1)[0][-1]
```
When `conn_group` contains only `-1` values (no valid connected nodes
for an agent), `np.where(conn_group != -1)[0]` returns an empty array.
Accessing `[-1]` on an empty array raises `IndexError`.
## Fix
Add a guard to check if there are valid indices before proceeding:
```python
valid_indices = np.where(conn_group != -1)[0]
if len(valid_indices) == 0:
continue
len_conn = valid_indices[-1]
```
## Test plan
- [x] Verify rendering works when all agents have valid connected nodes
- [x] Verify no crash when an agent has no valid connected nodes
Co-authored-by: Test User <test@example.com>1 parent 8b8d973 commit db8be74
1 file changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
657 | 660 | | |
658 | 661 | | |
659 | 662 | | |
| |||
0 commit comments