Skip to content

The agent that grows with you

refactor(connectors): trim lazy-surface docstrings and test path setup

kshitijk4poorddc0e65958b3
diff --git a/tests/tools/test_connectors_import_deadlock.py b/tests/tools/test_connectors_import_deadlock.py
index d1631adcc96..829472a5e2e 100644
--- a/tests/tools/test_connectors_import_deadlock.py
+++ b/tests/tools/test_connectors_import_deadlock.py
@@ -21,7 +21,6 @@ REPO_ROOT = Path(__file__).resolve().parents[2]
_NO_EAGER_SUBMODULE = """
import sys
-sys.path.insert(0, REPO_ROOT)
import tools.connectors # noqa: F401
loaded = sorted(k for k in sys.modules if k.startswith("tools.connectors."))
print("\\n".join(loaded))
@@ -29,7 +28,6 @@ print("\\n".join(loaded))
_RACE = """
import importlib, sys, threading
-sys.path.insert(0, REPO_ROOT)
errors = []
ITER = 25
@@ -60,7 +58,7 @@ def _run_snippet(snippet: str) -> subprocess.CompletedProcess:
env = dict(os.environ)
env["PYTHONPATH"] = str(REPO_ROOT)
return subprocess.run(
- [sys.executable, "-c", snippet.replace("REPO_ROOT", repr(str(REPO_ROOT)))],
+ [sys.executable, "-c", snippet],
capture_output=True,
text=True,
timeout=180,
diff --git a/tools/connectors/__init__.py b/tools/connectors/__init__.py
index b558419fdc2..bea2c3d7b62 100644
--- a/tools/connectors/__init__.py
+++ b/tools/connectors/__init__.py
@@ -5,22 +5,14 @@ Siblings: ``contract`` (states, actors, transition table), ``operation`` (the re
``live`` (open operation per session), ``run`` (the lifecycle loop), ``managed`` / ``mcp``
(per-kind hooks), ``targets``, ``search``, ``dispatch``, ``gateway/`` (HTTP wire + client).
-The surface is exported lazily (PEP 562) on purpose: this package is imported concurrently
-from threads that also import its submodules directly (the tool registry's discovery scan
-imports ``tools.connectors.tool`` while the gateway's Group Chat worker imports this
-package). Eager ``from tools.connectors.<sub> import …`` lines made this module hold its own
-module lock while reaching for a submodule another thread already held, which Python 3.14
-reports as ``_frozen_importlib._DeadlockError: deadlock detected by
-_ModuleLock('tools.connectors.tool')`` and which aborts the Group Chat worker at startup. A
-package ``__init__`` that imports no submodule cannot hold that lock while waiting for one,
-so the cycle is gone. Attribute access, ``from tools.connectors import x`` and ``__all__``
-behave exactly as before.
+The surface is exported lazily (PEP 562): eager submodule imports here deadlocked the
+concurrent registry scan and the Group Chat worker (see test_connectors_import_deadlock.py).
"""
import importlib
# name -> module owning it: the single source of truth for __all__ and __getattr__.
-_LAZY_EXPORTS: "dict[str, str]" = {
+_LAZY_EXPORTS: dict[str, str] = {
"CONNECTOR_BATCH_SENTINEL": "tools.connectors.gateway.names",
"MANAGE_CONNECTIONS_SCHEMA": "tools.connectors.tool",
"connector_describe": "tools.connectors.gateway.bridge",
@@ -36,12 +28,7 @@ __all__ = sorted(_LAZY_EXPORTS)
def __getattr__(name: str):
- """Resolve the public surface on first use (PEP 562).
-
- Deliberately no eager import: see the module docstring for the import-deadlock this
- prevents. Module-level ``__getattr__`` is only called for names not already bound, so
- each submodule is imported at most once per process.
- """
+ """Resolve and cache a public name on first access (PEP 562)."""
module_name = _LAZY_EXPORTS.get(name)
if module_name is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -50,5 +37,5 @@ def __getattr__(name: str):
return value
-def __dir__() -> "list[str]":
+def __dir__() -> list[str]:
return sorted(set(globals()) | set(__all__))