fix(prompt-caching): align _can_carry_marker with last-part-dict marking
Follow-up to the salvaged #57845 fix. _can_carry_marker used any(isinstance(part, dict)) but _apply_cache_marker only marks the LAST content part, so a list whose last element is a non-dict passed the carrier gate yet received no marker — wasting one of the four breakpoints. Tighten the predicate to require content[-1] to be a dict (mirroring the apply logic) and add a regression test. Flagged by a 3-agent review.
This commit is contained in:
@@ -65,7 +65,11 @@ def _can_carry_marker(msg: dict, native_anthropic: bool) -> bool:
|
||||
if content is None or content == "":
|
||||
return False
|
||||
if isinstance(content, list):
|
||||
return any(isinstance(part, dict) for part in content)
|
||||
# _apply_cache_marker only marks the LAST content part, so the carrier
|
||||
# predicate must agree: a list whose last element isn't a dict cannot
|
||||
# actually receive a marker and would waste a breakpoint. Mirror the
|
||||
# `content` truthiness + last-element-dict check in _apply_cache_marker.
|
||||
return bool(content) and isinstance(content[-1], dict)
|
||||
return isinstance(content, str)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user