Skip to content

Fix new playbook modules not discovered during hot reload#2042

Merged
arikalon1 merged 3 commits intorobusta-dev:masterfrom
harinik05:fix/invalidate-import-caches-for-new-playbook-modules
Apr 15, 2026
Merged

Fix new playbook modules not discovered during hot reload#2042
arikalon1 merged 3 commits intorobusta-dev:masterfrom
harinik05:fix/invalidate-import-caches-for-new-playbook-modules

Conversation

@harinik05
Copy link
Copy Markdown
Contributor

@harinik05 harinik05 commented Apr 3, 2026

Summary

  • Add importlib.invalidate_caches() in ConfigLoader.__import_playbooks_package() before pkgutil.walk_packages() so that newly added .py files in playbook repos are discoverable during hot reload

Fixes #2041

Problem

When new .py files are added to a git-based custom playbook repo and a config reload is triggered, pkgutil.walk_packages() does not discover them because Python's FileFinder caches directory listings from the initial import. Changes to existing files work fine via importlib.reload(), but new modules remain invisible until a full pod restart.

Fix

A single call to importlib.invalidate_caches() before the package walk clears the stale FileFinder directory cache, allowing newly installed modules to be found.

Test plan

  • Deploy runner with a git-based custom playbook repo
  • Add a new .py action file to the repo and push
  • Trigger a config reload (e.g., touch the playbooks config secret)
  • Verify the new action is registered without a pod restart
  • Verify existing action modifications still reload correctly

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 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5cee40ac-cc2e-4b63-8e23-89dd7c365373

📥 Commits

Reviewing files that changed from the base of the PR and between 79c5495 and dac6300.

📒 Files selected for processing (1)
  • src/robusta/runner/config_loader.py

Walkthrough

A single call to importlib.invalidate_caches() is added at the start of the __import_playbooks_package method to ensure Python's file finder cache is cleared before discovering playbook modules. This enables pkgutil.walk_packages() to detect newly added .py files during hot reload.

Changes

Cohort / File(s) Summary
Cache Invalidation for Module Discovery
src/robusta/runner/config_loader.py
Added importlib.invalidate_caches() call at the beginning of __import_playbooks_package to ensure newly added .py files in playbook repositories are discovered during config reload without requiring pod restart.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing discovery of new playbook modules during hot reload via importlib.invalidate_caches().
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, fix, and providing a test plan for validating the new playbook module discovery during hot reload.
Linked Issues check ✅ Passed The code change directly addresses issue #2041 by adding importlib.invalidate_caches() before pkgutil.walk_packages() to clear FileFinder cache, enabling discovery of newly added .py files during config hot reload.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to the stated objective: only adding importlib.invalidate_caches() call in __import_playbooks_package() without modifying other functionality or introducing unrelated changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 3, 2026

CLA assistant check
All committers have signed the CLA.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@Avi-Robusta Avi-Robusta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great work

@arikalon1 arikalon1 merged commit 85eb2b5 into robusta-dev:master Apr 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New playbook modules not discovered during hot reload without pod restart

4 participants