Spaces:
Build error
Build error
Commit ·
9b5e783
1
Parent(s): b59d6a5
fix: prevent stat inflation in compute_frozen_count, fix token estimate
Browse files- compute_frozen_count now checks _cache directly instead of calling
get_compressed, which was inflating hit/miss stats on every turn
- update_from_result uses len//4 for rough token estimate instead of
raw character count
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
headroom/cache/compression_cache.py
CHANGED
|
@@ -151,7 +151,7 @@ class CompressionCache:
|
|
| 151 |
content = _extract_tool_result_content(msg)
|
| 152 |
if content is not None:
|
| 153 |
h = self.content_hash(content)
|
| 154 |
-
if
|
| 155 |
break
|
| 156 |
else:
|
| 157 |
# tool_result with non-string content; treat as unstable
|
|
@@ -202,5 +202,5 @@ class CompressionCache:
|
|
| 202 |
if orig_content == comp_content:
|
| 203 |
continue
|
| 204 |
h = self.content_hash(orig_content)
|
| 205 |
-
tokens_saved = len(orig_content) - len(comp_content)
|
| 206 |
self.store_compressed(h, comp_content, tokens_saved=max(tokens_saved, 0))
|
|
|
|
| 151 |
content = _extract_tool_result_content(msg)
|
| 152 |
if content is not None:
|
| 153 |
h = self.content_hash(content)
|
| 154 |
+
if h not in self._cache:
|
| 155 |
break
|
| 156 |
else:
|
| 157 |
# tool_result with non-string content; treat as unstable
|
|
|
|
| 202 |
if orig_content == comp_content:
|
| 203 |
continue
|
| 204 |
h = self.content_hash(orig_content)
|
| 205 |
+
tokens_saved = len(orig_content) // 4 - len(comp_content) // 4
|
| 206 |
self.store_compressed(h, comp_content, tokens_saved=max(tokens_saved, 0))
|