Make prewarm resync MCP tools and rebuild frozen wire cache.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-12 21:34:45 +08:00
parent 25d09d78ce
commit 3785e78a72
10 changed files with 253 additions and 110 deletions

View file

@ -28,3 +28,27 @@ def test_tool_wire_freeze_disabled_by_setting(monkeypatch) -> None:
st = dl.tool_wire_freeze_status(store=store)
assert st["enabled"] is False
assert st["frozen"] is False
def test_warm_tool_wire_cache_clears_frozen_stale_entries(monkeypatch) -> None:
"""Regression: prewarm must rebuild after MCP sync; frozen mode used to return stale wire."""
calls = {"n": 0}
def _prep(**_kwargs):
calls["n"] += 1
return [{"type": "function", "function": {"name": f"tool_{calls['n']}"}}]
monkeypatch.setattr(dl, "_prepare_llm_tools", _prep)
monkeypatch.setenv("AIA_TOOL_WIRE_FROZEN_ON_STARTUP", "1")
store = _DummyStore({"AIA_TOOL_WIRE_FROZEN_ON_STARTUP": "1"})
with dl._TOOL_WIRE_CACHE_LOCK:
dl._TOOL_WIRE_FROZEN_SIGNATURE = "rt=1|stale"
dl._TOOL_WIRE_CACHE.clear()
dl._TOOL_WIRE_CACHE["poison"] = (0.0, [{"type": "function", "function": {"name": "old"}}])
out = dl.warm_tool_wire_cache(store=store, tools=object(), base_url="", roles=["generalist", "ops"])
assert calls["n"] == 2
assert int(out.get("cache_cleared") or 0) == 1
assert "poison" not in dl._TOOL_WIRE_CACHE
st = dl.tool_wire_freeze_status(store=store)
assert st["frozen"] is True
assert st["last_warm_count"] == 2