Skip to content

The agent that grows with you

test: cover concurrent plugin loads and persistence-isolated fork compaction

Tekniuma1a8a0320d80
diff --git a/tests/agent/test_pre_compress_checkpoint_contract.py b/tests/agent/test_pre_compress_checkpoint_contract.py
index 7544e8b9e83..69cce6f17c1 100644
--- a/tests/agent/test_pre_compress_checkpoint_contract.py
+++ b/tests/agent/test_pre_compress_checkpoint_contract.py
@@ -595,3 +595,18 @@ def test_capability_refusal_names_the_config_key_to_change():
assert msg.startswith("BLOCKED_MISSING_PREREQUISITE")
assert "compression.checkpoint_required" in msg
assert "false" in msg.lower()
+
+
+def test_persistence_isolated_fork_skips_the_checkpoint_gate_but_durable_agents_do_not():
+ """Review and /btw forks discard their transcript, so there is nothing to checkpoint.
+
+ ``build_cache_parity_fork`` builds with ``skip_memory=True`` and no session DB,
+ then re-enables compression; failing closed there aborted every fork compaction.
+ """
+ messages = [{"role": "user", "content": "evidence"}]
+ fork = SimpleNamespace(_persist_disabled=True, _session_db=None, _memory_manager=None)
+ assert _pre_compress_memory_context(fork, messages, True) == ""
+
+ durable = SimpleNamespace(_persist_disabled=False, _session_db=None, _memory_manager=None)
+ with pytest.raises(CompressionCheckpointUnavailable):
+ _pre_compress_memory_context(durable, messages, True)
diff --git a/tests/plugins/test_plugin_loader.py b/tests/plugins/test_plugin_loader.py
index 1ed3e8e1a41..34915b624a9 100644
--- a/tests/plugins/test_plugin_loader.py
+++ b/tests/plugins/test_plugin_loader.py
@@ -4,6 +4,8 @@ from __future__ import annotations
import logging
import sys
+import threading
+from types import SimpleNamespace
from plugins.plugin_loader import load_plugin_module
@@ -68,3 +70,43 @@ def test_successful_sibling_remains_available_on_loaded_module(tmp_path):
for name in tuple(sys.modules):
if name == module_name or name.startswith(f"{module_name}."):
sys.modules.pop(name, None)
+
+
+def test_concurrent_load_waits_for_the_first_load_to_finish(tmp_path):
+ """A second caller must never receive the half-built shell published mid-load."""
+ plugin_dir = tmp_path / "plugin"
+ plugin_dir.mkdir()
+ gate_name = "_test_plugin_loader_race_gate"
+ gate = SimpleNamespace(entered=threading.Event(), release=threading.Event())
+ sys.modules[gate_name] = gate
+ (plugin_dir / "slow.py").write_text(
+ f"import sys\ngate = sys.modules[{gate_name!r}]\n"
+ "gate.entered.set()\ngate.release.wait(10)\n",
+ encoding="utf-8",
+ )
+ (plugin_dir / "__init__.py").write_text("def register(ctx):\n pass\n", encoding="utf-8")
+ module_name = "test_plugin_loader_package.concurrent_load"
+ results = {}
+
+ def load(key):
+ mod = load_plugin_module(module_name, plugin_dir, parents=(), logger=logging.getLogger(__name__))
+ results[key] = hasattr(mod, "register")
+
+ first = threading.Thread(target=load, args=("first",))
+ second = threading.Thread(target=load, args=("second",))
+ try:
+ first.start()
+ assert gate.entered.wait(5)
+ second.start()
+ second.join(0.5)
+ gate.release.set()
+ first.join(10)
+ second.join(10)
+
+ assert results == {"first": True, "second": True}
+ finally:
+ gate.release.set()
+ sys.modules.pop(gate_name, None)
+ for name in tuple(sys.modules):
+ if name == module_name or name.startswith(f"{module_name}."):
+ sys.modules.pop(name, None)