Skip to content

The agent that grows with you

fix(background-review): inherit and freeze empty parent tools list for cache parity (#103579)

0xAlyDev06e59f2815b1
diff --git a/agent/background_review.py b/agent/background_review.py
index 21bd7915bbe..fd77d63fc3a 100644
--- a/agent/background_review.py
+++ b/agent/background_review.py
@@ -864,7 +864,7 @@ def _inherit_parent_tool_surface(review_agent: Any, agent: Any) -> None:
rebuild and do not clobber the inherited tools (#103579).
"""
parent_tools = getattr(agent, "tools", None)
- if not isinstance(parent_tools, (list, tuple)) or not parent_tools:
+ if not isinstance(parent_tools, (list, tuple)):
return
review_agent.tools = copy.deepcopy(list(parent_tools))
review_agent.valid_tool_names = {
diff --git a/tests/run_agent/test_background_review_cache_parity.py b/tests/run_agent/test_background_review_cache_parity.py
index f3714339096..92959c9c0b4 100644
--- a/tests/run_agent/test_background_review_cache_parity.py
+++ b/tests/run_agent/test_background_review_cache_parity.py
@@ -453,3 +453,43 @@ def test_review_fork_inherited_tools_survive_compaction_refresh():
}
+def test_unrouted_review_fork_inherits_empty_tool_surface():
+ """Empty parent tools[] is a valid snapshot and must be copied and frozen (#103579).
+
+ If no tools pass availability when the parent is constructed (parent.tools = []),
+ the unrouted fork must inherit an empty list and freeze _tool_snapshot_generation.
+ This guarantees late MCP/plugin tools discovered during fork construction or
+ mid-review compaction do not break cache parity against the parent's empty surface.
+ """
+ import run_agent
+ from agent.background_review import build_cache_parity_fork
+ from tools.mcp_tool_agent import refresh_agent_mcp_tools
+
+ agent = _make_agent_stub(run_agent.AIAgent)
+ agent.tools = []
+
+ _BaseRecorder = _make_recorder_class()
+
+ class _RecorderWithLateTool(_BaseRecorder):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ # Simulate a late tool appearing in the constructor result before inheritance
+ self.tools = [{"type": "function", "function": {"name": "newly_available"}}]
+ self.valid_tool_names = {"newly_available"}
+
+ with patch.object(run_agent, "AIAgent", _RecorderWithLateTool):
+ fork, _rt, routed = build_cache_parity_fork(agent, max_iterations=5)
+ assert not routed
+ assert fork.tools == []
+ assert fork.tools is not agent.tools
+ assert fork.valid_tool_names == set()
+ assert fork._tool_snapshot_generation == 2_147_483_647
+
+ # Compaction refresh must refuse rebuild on frozen snapshot
+ added = refresh_agent_mcp_tools(fork, content_aware=True)
+ assert added == set()
+ assert fork.tools == []
+ assert fork.valid_tool_names == set()
+
+
+