Commit bdfe080
committed
feat(loader, daemon): Implement strict ABI contamination tracking and worker isolation
This commit introduces a comprehensive overhaul of the worker daemon and loader to prevent ABI (Application Binary Interface) conflicts and ensure process isolation, dramatically improving stability when switching between versions of C-extension-heavy packages like TensorFlow, NumPy, and PyTorch.
Previously, reusing a worker process that had already loaded an ABI package (e.g., `numpy==1.24.3`) for a task requiring an incompatible version (e.g., `numpy==2.0.0`) could lead to segmentation faults or silent data corruption, as the OS linker would not reload the underlying `.so` file. This change implements a robust system to detect, manage, and prevent this "ABI contamination."
**Key Changes & Improvements:**
* **ABI Contamination Tracking & Eviction:**
* Workers now track whether they have loaded an ABI-sensitive package (like TensorFlow, JAX, NumPy, etc.) and report this "contaminated" state back to the daemon.
* The daemon will now automatically evict contaminated workers instead of returning them to the idle pool, ensuring a fresh, clean process is always used for tasks that could have conflicting ABI requirements.
* **Robust JAX/TensorFlow Dependency Hot-Patching:**
* The worker now intelligently detects broken or partially-initialized imports (specifically the `tensorflow -> jax -> ml_dtypes` conflict).
* Instead of failing, it now purges the broken module and injects a functional stub in its place, allowing TensorFlow 2.13+ to load successfully even with an older `ml_dtypes` present in the environment.
* **Centralized & Atomic Filesystem Locking:**
* Replaced all manual `shutil.move` and disparate `filelock` logic with a new centralized, re-entrant locking mechanism (`fs_lock_queue`).
* All package "cloaking" and "uncloaking" operations are now atomic and process-safe, eliminating filesystem race conditions between concurrent loaders.
* **Proactive ABI Conflict Delegation:**
* The `omnipkgLoader` can now detect a potential ABI conflict *before* activating a package (e.g., sees `numpy.core._multiarray_umath` is already mapped).
* It raises a `ProcessCorruptedException`, which is caught to automatically delegate the task to a clean, ephemeral daemon worker (`run_once` mode), seamlessly avoiding the in-process crash.
* **Massive Daemon Performance Boost (Overlay Fast Path):**
* Nested `omnipkgLoader` calls inside a daemon worker now use a highly optimized "fast path."
* It bypasses all filesystem cloaking and locking, simply swapping `sys.path` entries in-memory. This reduces nested activation overhead from 100+ms to <1ms.
* **Enhanced Cleanup and Diagnostics:**
* The loader's exit (`__exit__`) logic is now far more aggressive, performing deep scans for "zombie" modules and stale bubble paths left in `sys.path` to ensure a clean state.
* Added a new `_prof` helper and enhanced test output for better timing and debugging of worker initialization.
Modified:
• src/omnipkg/core.py (+31/-12 lines)
• src/omnipkg/isolation/patchers.py (+1/-1 lines)
• src/omnipkg/isolation/worker_daemon.py (+164/-23 lines)
• src/omnipkg/loader.py (+1856/-455 lines)
• src/tests/test_tensorflow_switching.py (+18/-4 lines)
[gitship-generated]1 parent 41271d8 commit bdfe080
5 files changed
Lines changed: 2082 additions & 507 deletions
File tree
- src
- omnipkg
- isolation
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
94 | 104 | | |
95 | 105 | | |
96 | 106 | | |
| |||
5825 | 5835 | | |
5826 | 5836 | | |
5827 | 5837 | | |
5828 | | - | |
5829 | | - | |
| 5838 | + | |
5830 | 5839 | | |
5831 | 5840 | | |
5832 | 5841 | | |
5833 | | - | |
| 5842 | + | |
5834 | 5843 | | |
| 5844 | + | |
5835 | 5845 | | |
5836 | 5846 | | |
5837 | 5847 | | |
| |||
17126 | 17136 | | |
17127 | 17137 | | |
17128 | 17138 | | |
17129 | | - | |
| 17139 | + | |
17130 | 17140 | | |
17131 | | - | |
| 17141 | + | |
17132 | 17142 | | |
17133 | | - | |
| 17143 | + | |
17134 | 17144 | | |
17135 | 17145 | | |
17136 | 17146 | | |
| |||
17139 | 17149 | | |
17140 | 17150 | | |
17141 | 17151 | | |
17142 | | - | |
| 17152 | + | |
| 17153 | + | |
| 17154 | + | |
| 17155 | + | |
| 17156 | + | |
| 17157 | + | |
| 17158 | + | |
| 17159 | + | |
17143 | 17160 | | |
17144 | | - | |
17145 | | - | |
| 17161 | + | |
| 17162 | + | |
| 17163 | + | |
| 17164 | + | |
17146 | 17165 | | |
17147 | 17166 | | |
17148 | 17167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
614 | | - | |
| 614 | + | |
0 commit comments