The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
review-fix(cache): re-planning an unmarked skill split marks the scaffold, not the tail
Tekniuma0e066d61443
diff --git a/agent/prompt_caching.py b/agent/prompt_caching.pyindex fcf759d6ff7..2cdbc33f756 100644--- a/agent/prompt_caching.py+++ b/agent/prompt_caching.py@@ -343,7 +343,10 @@ def apply_anthropic_cache_control(marker = _build_marker(cache_ttl)for i, msg in enumerate(messages):- if isinstance(msg, dict) and ("cache_control" in msg or _has_part_marker(msg.get("content"))):+ # Same gate as build_prompt_cache_plan: an UNMARKED skill split (outside the marker+ # window on the previous request) carries no marker, and left as two parts the new+ # breakpoint would land on its volatile tail instead of the scaffold.+ if isinstance(msg, dict) and ("cache_control" in msg or isinstance(msg.get("content"), list)):messages[i] = strip_anthropic_cache_control([dict(msg)])[0]breakpoints_used = 0diff --git a/tests/agent/test_prompt_cache_boundary.py b/tests/agent/test_prompt_cache_boundary.pyindex 74e209eedb0..21635978c84 100644--- a/tests/agent/test_prompt_cache_boundary.py+++ b/tests/agent/test_prompt_cache_boundary.py@@ -23,6 +23,7 @@ from agent.prompt_cache_boundary import (register_stable_prefix,)from agent.prompt_caching import (+ _has_part_marker,apply_anthropic_cache_control,build_prompt_cache_plan,strip_anthropic_cache_control,@@ -214,6 +215,23 @@ class TestRequestLocalSplit:assert stripped == originalassert apply_anthropic_cache_control(copy.deepcopy(stripped)) == first_wire+ def test_unmarked_split_re_entering_the_window_marks_the_scaffold(self):+ """Re-applying the planner to its own output (MoA reference trim, re-decoration) must+ treat an unmarked [scaffold, tail] split like the canonical string: the breakpoint goes+ on the scaffold, never on the volatile tail."""+ scaffold = "stable scaffold\n\n" + _SINGLE_SKILL_INSTRUCTION+ register_stable_prefix(scaffold)+ original = [{"role": "user", "content": scaffold + "ticket=one"}]+ original += [{"role": role, "content": f"turn {i}"} for i in range(4) for role in ("assistant", "user")]++ unmarked = apply_anthropic_cache_control(copy.deepcopy(original))+ assert not _has_part_marker(unmarked[0]["content"])++ again = apply_anthropic_cache_control(copy.deepcopy(unmarked[:3]))+ assert again == apply_anthropic_cache_control(copy.deepcopy(original[:3]))+ assert again[0]["content"][0]["cache_control"] == MARKER+ assert "cache_control" not in again[0]["content"][1]+def test_strip_flattens_even_after_the_prefix_was_evicted(self):"""Mid-turn failover re-decorates a request built many messages ago(#72626). If flattening depended on the registry still holding the