Skip to content

New playbook modules not discovered during hot reload without pod restart #2041

@harinik05

Description

@harinik05

Bug Description

When a new .py file is added to a git-based custom playbook repository and a config reload is triggered (via FileSystemWatcher detecting changes to the playbooks config or playbooks directory), the new module is not discovered by pkgutil.walk_packages(). The new action only becomes available after a full pod restart.

Changes to existing files work fineimportlib.reload() picks them up. Only newly added files are affected.

Root Cause

In ConfigLoader.__import_playbooks_package() (src/robusta/runner/config_loader.py), after pip install copies new files to site-packages, pkgutil.walk_packages() relies on Python's FileFinder to enumerate modules. The FileFinder caches directory listings from the initial import at process startup. Since importlib.invalidate_caches() is never called, newly installed .py files remain invisible to the finder machinery.

From the Python docs:

If you are dynamically importing a module that was created since the interpreter began execution (e.g., created a Python source file), you may need to call this function in order to notice the new module.

Steps to Reproduce

  1. Configure a git-based custom playbook repo in Robusta
  2. Let the runner start and load the initial set of actions
  3. Add a new .py file with a new action to the git repo and push
  4. Trigger a config reload (e.g., update the robusta-playbooks-config-secret)
  5. Observe that the new action is not registered — only existing actions are reloaded
  6. Restart the pod — the new action is now available

Expected Behavior

New playbook modules added to git repos should be discovered and loaded during hot reload without requiring a pod restart.

Proposed Fix

Add importlib.invalidate_caches() before the pkgutil.walk_packages() call in __import_playbooks_package().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions