Fix PicklingError for discovered agent modules in dev mode#13
Fix PicklingError for discovered agent modules in dev mode#13mahimairaja merged 1 commit intofix/pickling-issuefrom
Conversation
Register dynamically loaded agent modules in sys.modules before execution so that multiprocessing can pickle classes defined in those modules. The LiveKit 'dev' mode uses watchfiles.arun_process() which spawns child processes via multiprocessing. When pickling an Agent subclass, Python needs to import the module by name. Without registering the module in sys.modules, the import fails with: _pickle.PicklingError: Can't pickle <class 'openrtc_discovered_*'>: import of module 'openrtc_discovered_*' failed This follows the standard importlib pattern: add the module to sys.modules before executing it (for self-reference support) and clean up on failure. Co-authored-by: Mahimai Raja J <mahimairaja3@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/pickling-issue #13 +/- ##
======================================================
+ Coverage 87.92% 88.05% +0.13%
======================================================
Files 3 3
Lines 265 268 +3
======================================================
+ Hits 233 236 +3
Misses 32 32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix PicklingError for discovered agent modules in dev mode (#13)
Problem
Running
python main.py devin the examples directory fails with:This occurs because
_load_agent_moduledynamically loads agent modules usingimportlib.utilbut never registers them insys.modules. When LiveKit'sdevmode useswatchfiles.arun_process()→multiprocessing, it needs to pickleDentalAgent. Pickling a class requires its module to be importable by name, which fails without an entry insys.modules.Fix
Register dynamically loaded agent modules in
sys.modulesbefore execution, following the standardimportlibpattern:sys.modulesbefore callingexec_module()(supports self-references during execution)sys.moduleson failure to avoid leaving partial stateTesting
All 36 existing tests pass.