From e4f920ab0961bdaee7bee7f94c057ed5521a9800 Mon Sep 17 00:00:00 2001 From: harinik05 Date: Thu, 2 Apr 2026 23:41:52 -0700 Subject: [PATCH 1/2] Fix new playbook modules not discovered during hot reload When new .py files are added to a playbook repo and a config reload is triggered, pkgutil.walk_packages() fails to discover them because Python's FileFinder caches directory listings from the initial import. Existing file changes are picked up by importlib.reload(), but new modules remain invisible until the process restarts. Add importlib.invalidate_caches() before the package walk so that newly installed modules are visible to the finder machinery. Co-Authored-By: Claude Opus 4.6 --- src/robusta/runner/config_loader.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/robusta/runner/config_loader.py b/src/robusta/runner/config_loader.py index cbf72b8c1..43d36d173 100644 --- a/src/robusta/runner/config_loader.py +++ b/src/robusta/runner/config_loader.py @@ -184,6 +184,12 @@ def install_package(cls, pkg_path: str, build_isolation: bool) -> str: @classmethod def __import_playbooks_package(cls, actions_registry: ActionsRegistry, package_name: str): logging.info(f"Importing actions package {package_name}") + # Invalidate caches so that newly added modules (new .py files) are + # discoverable by pkgutil.walk_packages via the FileFinder. Without + # this, Python's cached directory listings cause new files installed + # since the interpreter started to be invisible to walk_packages, + # even though changes to *existing* files are picked up by reload(). + importlib.invalidate_caches() # Reload is required for modules that are already loaded pkg = importlib.reload(importlib.import_module(package_name)) playbooks_modules = [name for _, name, _ in pkgutil.walk_packages(path=pkg.__path__)] From dac6300ec46a512495c8c271fd33b903c1b3131d Mon Sep 17 00:00:00 2001 From: harinik05 Date: Thu, 2 Apr 2026 23:45:23 -0700 Subject: [PATCH 2/2] Shorten inline comment for invalidate_caches call Co-Authored-By: Claude Opus 4.6 --- src/robusta/runner/config_loader.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/robusta/runner/config_loader.py b/src/robusta/runner/config_loader.py index 43d36d173..c9f4b1515 100644 --- a/src/robusta/runner/config_loader.py +++ b/src/robusta/runner/config_loader.py @@ -184,11 +184,7 @@ def install_package(cls, pkg_path: str, build_isolation: bool) -> str: @classmethod def __import_playbooks_package(cls, actions_registry: ActionsRegistry, package_name: str): logging.info(f"Importing actions package {package_name}") - # Invalidate caches so that newly added modules (new .py files) are - # discoverable by pkgutil.walk_packages via the FileFinder. Without - # this, Python's cached directory listings cause new files installed - # since the interpreter started to be invisible to walk_packages, - # even though changes to *existing* files are picked up by reload(). + # Clear stale FileFinder caches so walk_packages discovers new .py files importlib.invalidate_caches() # Reload is required for modules that are already loaded pkg = importlib.reload(importlib.import_module(package_name))