Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(ragfs): 仅加载 abi3 binding 产物 (#1756)

Qin Haojie6aa62c1b8725
diff --git a/Makefile b/Makefile
index 869095450..a74178c29 100644
--- a/Makefile
+++ b/Makefile
@@ -103,19 +103,20 @@ build: check-deps check-pip
cd crates/ragfs-python && $$MATURIN_CMD build --release --out "$$TMPDIR" 2>&1; \
cd ../..; \
mkdir -p openviking/lib; \
+ rm -f openviking/lib/ragfs_python*.so openviking/lib/ragfs_python*.pyd openviking/lib/ragfs_python*.dylib; \
echo "import zipfile, glob, shutil, os, sys" > /tmp/extract_ragfs.py; \
echo "whls = glob.glob(os.path.join('$$TMPDIR', 'ragfs_python-*.whl'))" >> /tmp/extract_ragfs.py; \
echo "assert whls, 'maturin produced no wheel'" >> /tmp/extract_ragfs.py; \
echo "with zipfile.ZipFile(whls[0]) as zf:" >> /tmp/extract_ragfs.py; \
echo " for name in zf.namelist():" >> /tmp/extract_ragfs.py; \
echo " bn = os.path.basename(name)" >> /tmp/extract_ragfs.py; \
- echo " if bn.startswith('ragfs_python') and (bn.endswith('.so') or bn.endswith('.pyd')):" >> /tmp/extract_ragfs.py; \
+ echo " if bn.startswith('ragfs_python.abi3.') and (bn.endswith('.so') or bn.endswith('.pyd')):" >> /tmp/extract_ragfs.py; \
echo " dst = os.path.join('openviking', 'lib', bn)" >> /tmp/extract_ragfs.py; \
echo " with zf.open(name) as src, open(dst, 'wb') as f: f.write(src.read())" >> /tmp/extract_ragfs.py; \
echo " os.chmod(dst, 0o755)" >> /tmp/extract_ragfs.py; \
echo " print(f' [OK] ragfs-python: extracted {bn} -> {dst}')" >> /tmp/extract_ragfs.py; \
echo " sys.exit(0)" >> /tmp/extract_ragfs.py; \
- echo "print('[Warning] No ragfs_python .so/.pyd found in wheel')" >> /tmp/extract_ragfs.py; \
+ echo "print('[Warning] No ragfs_python abi3 .so/.pyd found in wheel')" >> /tmp/extract_ragfs.py; \
echo "sys.exit(1)" >> /tmp/extract_ragfs.py; \
$(PYTHON) /tmp/extract_ragfs.py; \
rm -f /tmp/extract_ragfs.py; \
diff --git a/openviking/pyagfs/__init__.py b/openviking/pyagfs/__init__.py
index e24b8e481..565796b5f 100644
--- a/openviking/pyagfs/__init__.py
+++ b/openviking/pyagfs/__init__.py
@@ -7,7 +7,6 @@ import importlib.util
import logging
import os
import sys
-import sysconfig
from pathlib import Path
from .client import AGFSClient, FileHandle
@@ -49,20 +48,16 @@ def _find_ragfs_so():
Returns the path to the ``.so`` / ``.dylib`` / ``.pyd`` file, or *None*.
"""
try:
- ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") or ".so"
- # Exact match first: ragfs_python.cpython-312-darwin.so or ragfs_python.abi3.so
- exact = _LIB_DIR / f"ragfs_python{ext_suffix}"
- if exact.exists():
- return str(exact)
- # Try abi3 suffix explicitly first (stable ABI)
+ # The ragfs-python crate is built with PyO3's stable ABI. Do not load
+ # cpython-specific artifacts from older source-checkout builds.
abi3_suffix = ".abi3.so"
if sys.platform == "win32":
abi3_suffix = ".abi3.pyd"
abi3_exact = _LIB_DIR / f"ragfs_python{abi3_suffix}"
if abi3_exact.exists():
return str(abi3_exact)
- # Glob fallback: ragfs_python.cpython-*, ragfs_python.abi3.*, ragfs_python.*.pyd
- for pattern in ("ragfs_python.cpython-*", "ragfs_python.abi3.*", "ragfs_python.*"):
+ # Glob fallback handles platform-tagged abi3 artifacts if any.
+ for pattern in ("ragfs_python.abi3.*",):
matches = glob.glob(str(_LIB_DIR / pattern))
if matches:
return matches[0]
diff --git a/setup.py b/setup.py
index 9b580102d..f24c3024e 100644
--- a/setup.py
+++ b/setup.py
@@ -323,7 +323,7 @@ class OpenVikingBuildExt(build_ext):
if result.stderr:
print(result.stderr.decode("utf-8", errors="replace"))
- # Extract the native .so/.pyd from the built wheel.
+ # Extract the stable-ABI native extension from the built wheel.
whl_files = list(Path(tmpdir).glob("ragfs_python-*.whl"))
if not whl_files:
message = "maturin produced no wheel for ragfs-python."
@@ -333,12 +333,18 @@ class OpenVikingBuildExt(build_ext):
return
ragfs_lib_dir.mkdir(parents=True, exist_ok=True)
+ for stale_artifact in ragfs_lib_dir.glob("ragfs_python*.so"):
+ stale_artifact.unlink()
+ for stale_artifact in ragfs_lib_dir.glob("ragfs_python*.pyd"):
+ stale_artifact.unlink()
+ for stale_artifact in ragfs_lib_dir.glob("ragfs_python*.dylib"):
+ stale_artifact.unlink()
+
extracted = False
with zipfile.ZipFile(str(whl_files[0])) as zf:
for name in zf.namelist():
basename = Path(name).name
- # Match: ragfs_python.cpython-312-darwin.so, ragfs_python.abi3.so, ragfs_python.cp312-win_amd64.pyd, etc.
- if basename.startswith("ragfs_python") and (
+ if basename.startswith("ragfs_python.abi3.") and (
basename.endswith(".so") or basename.endswith(".pyd")
):
target_path = ragfs_lib_dir / basename
@@ -351,7 +357,7 @@ class OpenVikingBuildExt(build_ext):
break
if not extracted:
- message = "Could not find ragfs_python .so/.pyd in built wheel."
+ message = "Could not find ragfs_python abi3 .so/.pyd in built wheel."
if require_ragfs_artifact:
raise RuntimeError(message)
print(f"[Warning] {message}")
diff --git a/tests/misc/test_pyagfs_loader.py b/tests/misc/test_pyagfs_loader.py
new file mode 100644
index 000000000..c13f9a525
--- /dev/null
+++ b/tests/misc/test_pyagfs_loader.py
@@ -0,0 +1,24 @@
+from pathlib import Path
+
+
+def test_pyagfs_loader_prefers_abi3_artifact(monkeypatch, tmp_path: Path):
+ import openviking.pyagfs as pyagfs
+
+ cpython_artifact = tmp_path / "ragfs_python.cpython-312-darwin.so"
+ abi3_artifact = tmp_path / "ragfs_python.abi3.so"
+ cpython_artifact.write_bytes(b"old")
+ abi3_artifact.write_bytes(b"new")
+
+ monkeypatch.setattr(pyagfs, "_LIB_DIR", tmp_path)
+ assert pyagfs._find_ragfs_so() == str(abi3_artifact)
+
+
+def test_pyagfs_loader_ignores_cpython_specific_artifact(monkeypatch, tmp_path: Path):
+ import openviking.pyagfs as pyagfs
+
+ cpython_artifact = tmp_path / "ragfs_python.cpython-312-darwin.so"
+ cpython_artifact.write_bytes(b"old")
+
+ monkeypatch.setattr(pyagfs, "_LIB_DIR", tmp_path)
+
+ assert pyagfs._find_ragfs_so() is None