From d12d7129a255d710fe4110319ec31ea865914637 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 21:53:23 +0530 Subject: [PATCH] refactor(cache): drop the int guard on the fork compaction count Every context engine inherits ContextEngine.compression_count: int = 0 and the only tagged forks in tests (the review-fork Recorder and the scope tests) have no compressor or an int counter, so the isinstance check guarded nothing. Also cut the _apply_fork_tag docstring to the WHY; the measurement numbers belong in the PR body, not the source. --- agent/prompt_cache_scope.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/agent/prompt_cache_scope.py b/agent/prompt_cache_scope.py index cd8e44370a..a2fea6e7e0 100644 --- a/agent/prompt_cache_scope.py +++ b/agent/prompt_cache_scope.py @@ -202,21 +202,13 @@ def is_fork_cache_scope(scope: Any) -> bool: def _apply_fork_tag(agent: Any, scope: str) -> str: - """Derive ``::`` for a tagged cache-parity fork on a slot-keyed provider, but only - after the fork's own compaction committed. - - A same-model fork shares the parent's scope (#109964): until it compacts, its requests are a - strict prefix extension of the parent's, so request #1 is a warm read and cannot evict. Once - its in-place compaction rewrites the transcript, on xAI the divergent stream evicts the - parent's conversation slot (grok-4.7, ~160k: the parent's next call read 1,152 of 162k prompt - tokens, 2/2, vs 162,176 with a derived key). ``compression_count`` is the fork's own counter - (rolled back on aborted attempts). Evaluated per call, so a provider fallback re-evaluates. - """ + """``::`` for a tagged fork on a slot-keyed route, once the fork's OWN compaction + committed: before it the fork extends the parent's prefix (warm read, #109964); after it the + rewritten stream would evict the parent's xAI slot. Read per call, so fallbacks re-evaluate.""" tag = getattr(agent, "_prompt_cache_fork_tag", None) if not scope or not isinstance(tag, str) or not tag: return scope - compactions = getattr(getattr(agent, "context_compressor", None), "compression_count", 0) - if not isinstance(compactions, int) or compactions < 1: + if getattr(getattr(agent, "context_compressor", None), "compression_count", 0) < 1: return scope if not is_slot_keyed_cache_route( getattr(agent, "provider", ""), getattr(agent, "model", ""), getattr(agent, "base_url", ""),