-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Bug Description
WhiteBoxNetSecGame._all_actions and _registration_info are computed once during _initialize() (line 28-31 of WhiteBoxNetSecGame.py) and never regenerated when _dynamic_ip_change() is called during reset(). After a reset with dynamic IPs enabled, the entire WhiteBox action list references old/invalid IPs that no longer exist in the game. Agents operating in WhiteBox mode receive a completely stale and incorrect action space.
Additionally, even if a fix attempted to call _generate_all_actions() again after a dynamic IP change, it would crash with a KeyError on line 41:
all_ips = [self._ip_mapping[ip] for ip in self._ip_to_hostname.keys()]This is because after _dynamic_ip_change():
self._ip_to_hostnamekeys are remapped (new) IPsself._ip_mappingkeys are original IPs (never change)- Looking up a new IP in
_ip_mappingraisesKeyError
The same root cause also affects NetSecGame._get_all_local_ips() (line 1041), which crashes when a starting position uses the "all_local" keyword after a dynamic IP change.
Steps to Reproduce
- Configure a game scenario with
use_dynamic_ips: truein the task config - Start a
WhiteBoxNetSecGameserver - Connect an agent and complete an episode
- Request a reset with
randomize_topology: true - Observe that the
_all_actionslist (sent during registration) now contains IPs that no longer exist in the game - If an agent reconnects (re-registers), it still receives the stale action list
- If the starting position uses
"all_local", the game crashes withKeyErrorin_get_all_local_ips()at line 1041 ofNetSecGame.py
Expected Behavior
After a reset with dynamic IP changes:
WhiteBoxNetSecGameshould regenerate_all_actionsand_registration_infowith the new IPs so that reconnecting agents receive a valid, up-to-date action space._generate_all_actions()should work correctly with remapped IPs (the_ip_mappinglookup on line 41 needs to be fixed or bypassed since_ip_to_hostnamealready contains the current/mapped IPs)._get_all_local_ips()inNetSecGame.pyshould not crash -- it should use the IPs from_networksdirectly instead of going through_ip_mapping, since_networksis already updated with the new IPs.
Suggested fix for _generate_all_actions() line 41:
# Before (broken after dynamic IP change):
all_ips = [self._ip_mapping[ip] for ip in self._ip_to_hostname.keys()]
# After (use _ip_to_hostname keys directly -- they already contain current IPs):
all_ips = list(self._ip_to_hostname.keys())Suggested fix for _get_all_local_ips() line 1041:
# Before (broken after dynamic IP change):
local_ips.add(self._ip_mapping[ip])
# After (IPs in _networks are already current):
local_ips.add(ip)Suggested fix for WhiteBoxNetSecGame.reset():
Override reset() to regenerate _all_actions and _registration_info:
async def reset(self) -> bool:
result = await super().reset()
self._all_actions = self._generate_all_actions()
self._registration_info = {
"all_actions": json.dumps([v.as_dict for v in self._all_actions]),
} if self._all_actions is not None else {}
return resultVersion
Current main branch (commit 3943658)
Installation / Deployment Method
Running locally from source