From eb2e96d6578292a5fa750fcdbadf4ce6eb9d4617 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 3 Sep 2026 16:20:10 -0700 Subject: [PATCH] fix(compat-fallout): module-restore also rebinds pkg. attributes so 'from pkg import child' matches sys.modules after the wipe --- tests/agent/test_empty_tool_name_loop_dampening.py | 7 +++++++ tests/agent/test_verification_stop_caching.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/agent/test_empty_tool_name_loop_dampening.py b/tests/agent/test_empty_tool_name_loop_dampening.py index 7076f75f8d..79e7174cb7 100644 --- a/tests/agent/test_empty_tool_name_loop_dampening.py +++ b/tests/agent/test_empty_tool_name_loop_dampening.py @@ -161,6 +161,13 @@ def agent_env(): # land on modules the app no longer imports. sys.modules.clear() sys.modules.update(saved_modules) + for _name, _mod in saved_modules.items(): + _parent, _, _child = _name.rpartition(".") + if _parent and _parent in saved_modules: + try: + setattr(saved_modules[_parent], _child, _mod) + except Exception: + pass if prev_home is None: os.environ.pop("HERMES_HOME", None) else: diff --git a/tests/agent/test_verification_stop_caching.py b/tests/agent/test_verification_stop_caching.py index a059383e11..5678104031 100644 --- a/tests/agent/test_verification_stop_caching.py +++ b/tests/agent/test_verification_stop_caching.py @@ -27,8 +27,21 @@ def _restore_sys_modules(): the app no longer imports.""" saved = dict(sys.modules) yield + _restore_modules(saved) + + +def _restore_modules(saved): sys.modules.clear() sys.modules.update(saved) + # Re-imports rebound ``pkg.`` attributes to the fresh module objects; point them + # back so ``from pkg import child`` and ``sys.modules["pkg.child"]`` agree again. + for name, mod in saved.items(): + parent, _, child = name.rpartition(".") + if parent and parent in saved: + try: + setattr(saved[parent], child, mod) + except Exception: + pass def _fresh_run_agent(hermes_home):