Skip to content

Commit 5ae9d2b

Browse files
committed
feat: fix uv-ffi per-interpreter .so loading and daemon IPC for managed workers
- _vendor/uv_ffi/__init__.py: replace static import with _load_native() that globs the running interpreter's own site-packages for the correct .so, falling back to vendored only for the native interpreter; exposes _loaded_so_path for identity logging - worker_daemon.py: pass OMNIPKG_ENV_ID_OVERRIDE to all managed worker subprocesses so DaemonClient resolves the native daemon's socket path instead of computing a dead per-interpreter hash — fixes start_omnipkg_op and end_omnipkg_op IPC being silently dropped for all non-native interpreters - fs_watcher.py: MtimeFallbackWatcher now takes a fresh snapshot baseline at op START and diffs against post-op state in end_omnipkg_op; surgical patch_site_packages_cache with parsed name+version instead of full invalidate; per-interpreter [pyX.Y] labels on all log lines; skip ~temp rename artifacts in culprit scan - core.py: import uv_ffi module instead of bare run function so each managed worker loads its own interpreter's .so; OMNIPKG_DEBUG-gated _dbg_print; socket path and start_op result logged for IPC diagnosis All adopted interpreters (3.9, 3.10, 3.12, 3.13, 3.14) now correctly signal op START/END to the native daemon, get their cache patched in the right Rust worker, and show zero external culprits on install verification. Modified: • src/omnipkg/_vendor/uv_ffi/__init__.py (+53/-28 lines) • src/omnipkg/core.py (+20/-5 lines) • src/omnipkg/isolation/fs_watcher.py (+202/-67 lines) • src/omnipkg/isolation/worker_daemon.py (+1/-0 lines) • pyproject.toml (+1/-1 lines) [gitship-generated]
1 parent 4f31d52 commit 5ae9d2b

5 files changed

Lines changed: 271 additions & 95 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ backend-path = ["."]
66

77
[project]
88
name = "omnipkg"
9-
version = "3.0.1"
9+
version = "3.0.2"
1010
authors = [
1111
{ name = "1minds3t", email = "1minds3t@proton.me" },
1212
]

src/omnipkg/_vendor/uv_ffi/__init__.py

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
11
"""
22
uv_ffi — thin wrapper around the PyO3 native extension.
3-
run(cmd) -> (rc, installed, removed, err)
4-
installed: list of (name, version) tuples
5-
removed: list of (name, version) tuples
6-
err: error string (empty on success)
73
"""
8-
try:
9-
# Prefer the properly installed wheel
10-
from uv_ffi.uv_ffi import (
11-
run as _run_native,
12-
get_site_packages_cache,
13-
invalidate_site_packages_cache,
14-
patch_site_packages_cache,
15-
clear_registry_cache,
16-
)
17-
except ImportError:
18-
# Fall back to vendored .so
19-
import os as _os, sys as _sys
20-
_sys.path.insert(0, _os.path.join(_os.path.dirname(__file__), '_native'))
21-
from uv_ffi import (
22-
run as _run_native,
23-
get_site_packages_cache,
24-
invalidate_site_packages_cache,
25-
patch_site_packages_cache,
26-
clear_registry_cache,
4+
import sys as _sys
5+
import os as _os
6+
7+
def _load_native():
8+
_here = _os.path.dirname(__file__)
9+
_native_dir = _os.path.join(_here, '_native')
10+
11+
import sysconfig as _sc
12+
import glob as _glob
13+
_tag = _sc.get_config_var('EXT_SUFFIX') or ''
14+
_versioned = _os.path.join(_native_dir, f'uv_ffi{_tag}')
15+
_abi3 = _os.path.join(_native_dir, 'uv_ffi.abi3.so')
16+
_is_vendored_native = _os.path.exists(_versioned) or _os.path.exists(_abi3)
17+
18+
# Check if this interpreter has its OWN uv_ffi installed — glob for any .so/.pyd
19+
_site_uv_ffi_dir = _os.path.join(_sc.get_path('purelib'), 'uv_ffi')
20+
_site_sos = (
21+
_glob.glob(_os.path.join(_site_uv_ffi_dir, 'uv_ffi*.so')) +
22+
_glob.glob(_os.path.join(_site_uv_ffi_dir, 'uv_ffi*.pyd'))
2723
)
24+
_sys.stderr.flush()
25+
26+
if _site_sos:
27+
_site_so = _site_sos[0]
28+
import importlib.util as _ilu
29+
_spec = _ilu.spec_from_file_location("uv_ffi", _site_so)
30+
_mod = _ilu.module_from_spec(_spec)
31+
_spec.loader.exec_module(_mod)
32+
_sys.stderr.flush()
33+
return _mod
34+
35+
if _is_vendored_native:
36+
_so = _versioned if _os.path.exists(_versioned) else _abi3
37+
import importlib.util as _ilu
38+
_spec = _ilu.spec_from_file_location("uv_ffi._native", _so)
39+
_mod = _ilu.module_from_spec(_spec)
40+
_spec.loader.exec_module(_mod)
41+
_sys.stderr.flush()
42+
return _mod
43+
44+
raise ImportError(f'uv_ffi: no .so found for {_sys.executable} (tag={_tag}, site={_sc.get_path("purelib")})')
45+
46+
_native = _load_native()
47+
_loaded_so_path = getattr(_native, '__file__', 'unknown')
48+
49+
50+
run = _native.run
51+
get_site_packages_cache = _native.get_site_packages_cache
52+
invalidate_site_packages_cache = _native.invalidate_site_packages_cache
53+
patch_site_packages_cache = _native.patch_site_packages_cache
54+
clear_registry_cache = _native.clear_registry_cache
55+
2856

2957
def run(cmd: str) -> tuple:
30-
"""Call uv FFI directly — returns (rc, installed, removed, err).
31-
Gracefully handles old 3-tuple .so builds by padding err=''."""
32-
result = _run_native(cmd)
58+
result = _native.run(cmd)
3359
if len(result) == 3:
3460
return (result[0], result[1], result[2], '')
3561
return result
@@ -43,8 +69,7 @@ def run(cmd: str) -> tuple:
4369
__version__ = "unknown"
4470

4571
__all__ = [
46-
"run",
47-
"run_capture",
72+
"run", "run_capture",
4873
"get_site_packages_cache",
4974
"invalidate_site_packages_cache",
5075
"patch_site_packages_cache",

src/omnipkg/core.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16052,6 +16052,9 @@ def _run_pip_install(
1605216052

1605316053
🔥 CRITICAL FIX: Added --no-cache-dir to prevent /tmp bloat from pip's cache!
1605416054
"""
16055+
_dbg_flag = os.environ.get("OMNIPKG_DEBUG") == "1"
16056+
def _dbg_print(msg, **kwargs):
16057+
if _dbg_flag: print(f"[DEBUG-CORE] {msg}", flush=True, **kwargs)
1605516058
if not packages:
1605616059
return 0, {"stdout": "", "stderr": ""}
1605716060

@@ -16082,6 +16085,10 @@ def _run_pip_install(
1608216085

1608316086
# ── UV INSTALL: FFI → daemon → subprocess → pip ──────────────
1608416087
# Cache uv_exe and cache_dir on self — never pay for shutil.which() twice
16088+
_target_py = self.config.get("python_executable", sys.executable)
16089+
_ffi_cache_attr = f"_uv_ffi_run_{_target_py.replace('/', '_').replace('.', '_')}"
16090+
if hasattr(self, _ffi_cache_attr):
16091+
self._uv_ffi_run = getattr(self, _ffi_cache_attr)
1608516092
if not hasattr(self, "_uv_exe_cached"):
1608616093
import shutil as _shutil_init
1608716094
_exe = self.config.get("uv_executable") or _shutil_init.which("uv") or ""
@@ -16107,8 +16114,11 @@ def _run_pip_install(
1610716114
os.environ["UV_TMPDIR"] = _tf.gettempdir()
1610816115
# Pre-import and cache FFI + failure detector — never pay import cost on hot path
1610916116
try:
16110-
from omnipkg._vendor.uv_ffi import run as _ffi_run
16111-
self._uv_ffi_run = _ffi_run
16117+
import omnipkg._vendor.uv_ffi as _uv_ffi_mod
16118+
self._uv_ffi_run = _uv_ffi_mod.run
16119+
self._uv_ffi_so_path = getattr(_uv_ffi_mod, '_loaded_so_path', 'unknown')
16120+
_dbg_print(f"[UV-FFI-IDENTITY] loaded .so: {self._uv_ffi_so_path}", file=sys.stderr)
16121+
_dbg_print(f"[UV-FFI-IDENTITY] worker python: {sys.executable}", file=sys.stderr)
1611216122
except ImportError:
1611316123
self._uv_ffi_run = None
1611416124
try:
@@ -16168,7 +16178,7 @@ def _run_pip_install(
1616816178
else:
1616916179
_uv_packages.append(_p)
1617016180
_uv_args += _uv_packages
16171-
_dbg(f"[WALL-CORE] args-build+exists: {(time.perf_counter()-_t_wrapper_entry)*1000:.3f}ms")
16181+
_dbg_print(f"[WALL-CORE] args-build+exists: {(time.perf_counter()-_t_wrapper_entry)*1000:.3f}ms")
1617216182
# ── PATH 1: FFI in-process ─────────────────────────────────
1617316183
if self._uv_ffi_run is not None:
1617416184
daemon_client = None
@@ -16190,9 +16200,11 @@ def _run_pip_install(
1619016200

1619116201
from omnipkg.isolation.worker_daemon import DaemonClient
1619216202
daemon_client = DaemonClient(auto_start=False)
16193-
daemon_client.start_omnipkg_op()
16203+
_dbg_print(f"[FS-WATCHER-CLIENT] socket_path={__import__('omnipkg.isolation.worker_daemon', fromlist=['']).DEFAULT_SOCKET}")
16204+
_start_result = daemon_client.start_omnipkg_op()
16205+
_dbg_print(f"[FS-WATCHER-CLIENT] start_op result={_start_result} for {_sp_path}")
1619416206
except Exception as e:
16195-
_dbg(f"[FS-WATCHER-CLIENT] Failed to signal start_op: {e}")
16207+
_dbg_print(f"[FS-WATCHER-CLIENT] Failed to signal start_op: {e}")
1619616208
daemon_client = None
1619716209

1619816210
try:
@@ -16202,7 +16214,9 @@ def _run_pip_install(
1620216214
_ffi_cmd = " ".join(_uv_args)
1620316215
import time as _t_imp
1620416216
_t_pre_ffi = _t_imp.perf_counter()
16217+
_py_target = next((a for i, a in enumerate(_uv_args) if _uv_args[i-1] == "--python"), "NOT SET")
1620516218
safe_print(f"[UV-PATH] FFI in-process: uv {_ffi_cmd}", file=sys.stderr)
16219+
_dbg_print(f"[UV-FFI-IDENTITY] .so={getattr(self, '_uv_ffi_so_path', 'cached')} | worker={sys.executable} | targeting --python={_py_target}", file=sys.stderr)
1620616220
_t0 = _t_imp.perf_counter()
1620716221

1620816222
# ── START CAPTURE (fd-level, catches Rust writes) ──
@@ -16289,6 +16303,7 @@ def _run_pip_install(
1628916303
try:
1629016304
from omnipkg.isolation.worker_daemon import DaemonClient
1629116305
_dc = DaemonClient(auto_start=False)
16306+
_dbg_print(f"[FS-WATCHER-CLIENT] socket_path={__import__('omnipkg.isolation.worker_daemon', fromlist=['']).DEFAULT_SOCKET}")
1629216307
_req = {
1629316308
"type": "run_uv",
1629416309
"uv_exe": uv_exe,

0 commit comments

Comments
 (0)