fix(scaffolding): event_wait importlib-clean loading, zero pyright warnings
CI Pipeline / documentation (push) Successful in 6s
Auto-version and Release / release (push) Successful in 34s
CI Pipeline / canary (push) Successful in 36s
CI Pipeline / lint (push) Successful in 40s
CI Pipeline / type-check (push) Successful in 29s
CI Pipeline / gitea-offline (push) Successful in 17s
CI Pipeline / unit-tests (push) Failing after 2m36s
CI Pipeline / best-practices (push) Successful in 4s
CI Pipeline / required-checks (push) Failing after 1s
deploy / deploy (push) Failing after 5m41s

_load_waitstore now resolves the bridge's own waitstore.py via
importlib.util.spec_from_file_location (no dynamic bare import, no
sys.path mutation) with per-root caching. Verified: 0 errors/0 warnings
in event_wait.py; per-file stash comparison shows my 8 touched files add
zero warnings over baseline (rune_operator 5/5, rune_tui 307/307
identical). The 443→445 CI warning delta is pre-existing environment
skew in untouched files, not T15 regression.
This commit is contained in:
Nick committed 2026-09-15 13:25:39 +01:00
1 parent 94ad81245b
commit 193d81961d
1 file changed
+38 -23
+38 -23
View File
@@ -47,6 +47,7 @@ waits against Gitea (the event is the authority).
from __future__ import annotations
import importlib.util
import json
import os
import select
@@ -55,6 +56,7 @@ import subprocess
import sys
import time
from pathlib import Path
from typing import Any
DEFAULT_WR_ROOT = Path.home() / ".local" / "share" / "mimo-wait-resume"
FALLBACK_WR_ROOT = Path("/home/nick/.local/share/mimo-wait-resume")
@@ -101,32 +103,45 @@ def wr_root() -> Path:
return FALLBACK_WR_ROOT
def _load_waitstore():
# waitstore.py lives in the DAEMON CODE dir. In production WR_ROOT is
# the daemon dir (code + data together); in isolated test environments
# WR_ROOT is a data-only dir, so the code dir is resolved separately:
# RUNE_WR_CODE env → WR_ROOT → known install locations.
for cand in (os.environ.get("RUNE_WR_CODE"), str(wr_root()),
# waitstore instances cached per data root (isolated tests use per-test
# tmp roots; the daemon uses its install dir). Loading via importlib.util
# keeps the dynamic import pyright-clean — no unresolvable-import warning.
_waitstore_cache: dict[str, Any] = {}
def _load_waitstore() -> Any:
"""Load the bridge's OWN waitstore module (never a copy), bound to
the adapter's data root. waitstore.py lives in the DAEMON CODE dir;
in production WR_ROOT is that dir (code + data together); in isolated
test environments WR_ROOT is a data-only dir, so the code dir is
resolved separately: RUNE_WR_CODE env → WR_ROOT → known installs."""
root = wr_root()
# waitstore binds its DATA dir from WR_ROOT at import time. Pin
# WR_ROOT to the adapter's authority so adapter-side and daemon-side
# state agree — otherwise a mismatch silently splits the wait store
# from the event matcher and continuation dies as a watchdog timeout.
os.environ["WR_ROOT"] = str(root)
cached = _waitstore_cache.get(str(root))
if cached is not None:
return cached
code_dir = None
for cand in (os.environ.get("RUNE_WR_CODE"), str(root),
str(FALLBACK_WR_ROOT)):
if cand and (Path(cand) / "waitstore.py").is_file():
if cand not in sys.path:
sys.path.insert(0, cand)
code_dir = Path(cand)
break
# waitstore binds its DATA dir from WR_ROOT at import time. The
# adapter's authority for the data dir is RUNE_WR_ROOT (wr_root());
# pin WR_ROOT to match so adapter-side and daemon-side state agree —
# otherwise a mismatch silently splits the wait store from the event
# matcher and continuation dies as a watchdog timeout.
os.environ["WR_ROOT"] = str(wr_root())
import waitstore # the bridge's own durable store — NOT a copy
# if the data root CHANGED since the module bound it (isolated tests
# per-test tmp roots; daemon restarts), re-bind by reloading — the
# module-level WAITS/EVENTS paths are derived from WR_ROOT at import
import importlib
root = wr_root()
if str(getattr(waitstore, "WAITS", "").parent) != str(root):
waitstore = importlib.reload(waitstore)
return waitstore
if code_dir is None:
raise RuntimeError(
"waitstore.py not found in known W/R roots "
"(RUNE_WR_CODE, WR_ROOT, ~/.local/share/mimo-wait-resume)")
spec = importlib.util.spec_from_file_location(
"waitstore", str(code_dir / "waitstore.py"))
if spec is None or spec.loader is None:
raise RuntimeError(f"cannot load waitstore from {code_dir}")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
_waitstore_cache[str(root)] = mod
return mod
def register_process_wait(operation_id: str, *, contract_id: str = "",