Skip to content

The agent that grows with you

fix(skills): the background-review fork never receives a skill_view dedup stub

panyaozhenbc471d68b8f0
diff --git a/tests/tools/test_skill_view_dedup.py b/tests/tools/test_skill_view_dedup.py
index 8234f6a39cf..bc0a9a6709b 100644
--- a/tests/tools/test_skill_view_dedup.py
+++ b/tests/tools/test_skill_view_dedup.py
@@ -88,6 +88,47 @@ class TestSkillViewDedup:
r2 = json.loads(_skill_view_with_bump(args, task_id=None))
assert "Step one" in r2.get("content", "")
+ def test_background_review_has_its_own_dedup_namespace(self, skills_home):
+ from tools.skill_provenance import (
+ reset_current_write_origin,
+ set_current_write_origin,
+ )
+
+ _view("demo-dedup-skill")
+
+ token = set_current_write_origin("background_review")
+ try:
+ review = _view("demo-dedup-skill")
+ finally:
+ reset_current_write_origin(token)
+
+ assert review["success"] is True
+ assert "Step one" in review.get("content", "")
+ assert review.get("dedup") is None
+ assert review.get("content_returned") is None
+ # The real read marks the file, so the fork's read-before-write guard now admits the patch.
+ from tools.skill_manager_guards import _background_review_has_read
+ assert _background_review_has_read(skills_home / "skills" / "demo-dedup-skill" / "SKILL.md")
+
+ def test_background_review_does_not_pollute_foreground_cache(self, skills_home):
+ from tools.skill_provenance import (
+ reset_current_write_origin,
+ set_current_write_origin,
+ )
+
+ token = set_current_write_origin("background_review")
+ try:
+ _view("demo-dedup-skill")
+ finally:
+ reset_current_write_origin(token)
+
+ foreground = _view("demo-dedup-skill")
+ assert "Step one" in foreground.get("content", "")
+
+ repeat = _view("demo-dedup-skill")
+ assert repeat.get("dedup") is True
+ assert repeat.get("content_returned") is False
+
def test_compression_hook_importable(self):
# conversation_compression imports this lazily; keep the seam stable.
from tools.skills_tool import reset_skill_view_dedup as f
diff --git a/tools/skills_tool.py b/tools/skills_tool.py
index c46796b32e3..6f77d36ef3f 100644
--- a/tools/skills_tool.py
+++ b/tools/skills_tool.py
@@ -695,13 +695,18 @@ def _skill_view_with_bump(args, **kw):
session returns a short stub (cache cleared on context compression)."""
name = args.get("name", "")
task_id = kw.get("task_id")
- if (stub := _check_skill_view_dedup(task_id, name, args.get("file_path"))) is not None:
+ # The background-review fork shares the parent's task_id (prefix-cache parity), so its views
+ # would hit stubs for content that is in the PARENT's context, not the fork's — and the stub
+ # path never marks the read the fork's write guard requires (#95976). No dedup in the fork.
+ from tools.skill_provenance import is_background_review
+ dedup_task_id = None if is_background_review() else task_id
+ if (stub := _check_skill_view_dedup(dedup_task_id, name, args.get("file_path"))) is not None:
return stub
result = skill_view(name, file_path=args.get("file_path"), task_id=task_id)
with suppress(Exception):
parsed = json.loads(result)
if isinstance(parsed, dict) and parsed.get("success"):
- _record_skill_view(task_id, name, args.get("file_path"), parsed)
+ _record_skill_view(dedup_task_id, name, args.get("file_path"), parsed)
if resolved := parsed.get("name") or name: # qualified forms return the canonical name
from tools.skill_usage import bump_use, bump_view
bump_view(str(resolved))