Skip to content

Cache-stable eviction: hysteresis + sticky evicted set - #56

Merged
ayman3000 merged 1 commit into
mainfrom
feat/cache-stable-eviction
Aug 24, 2026
Merged

Cache-stable eviction: hysteresis + sticky evicted set#56
ayman3000 merged 1 commit into
mainfrom
feat/cache-stable-eviction

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

Makes Naseem's prompts cache-friendly the way Claude Code/Codex prompts are: byte-stable prefix, append-only growth, volatility at the tail.

Root cause of the cache misses: once a conversation exceeded the inline budget, eviction ran every turn, evicting just enough — so the ledger (in the system block) and the message list changed on every call, and provider prefix caches (OpenAI/Anthropic discount cached prompt tokens heavily) never hit.

Fix:

  • Sticky evictions: once an exchange is externalized it stays externalized (tracked by head-message id) — the prefix cannot flap.
  • Low-watermark hysteresis: a budget breach evicts down to evictionTargetFraction (default 0.5) of the budget, buying ~half a budget of slack before the next eviction event. Between events, system block + all completed messages are byte-identical across calls (proven by test: the entire previous output is a byte-equal prefix of the next).

Deliberately NOT done (alternation risk on Anthropic-style providers, and unnecessary once the ledger is frozen between events): moving the ledger out of the system block.

Tests: 2 new (byte-stable prefix across calls; breach evicts to low watermark); full suite green.

🤖 Generated with Claude Code

Continuous eviction (evict just enough, every turn) changed the
model-facing prefix on every call once over budget — the ledger and
message list shifted each turn, so provider prompt caches never hit and
every call metered its full context. Evictions are now sticky (by head
message id, never undone) and a budget breach evicts down to
evictionTargetFraction (default 0.5) of the budget: the prefix stays
byte-identical until ~half a budget of new content accumulates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ayman3000
ayman3000 merged commit e4e75f1 into main Aug 24, 2026
@ayman3000
ayman3000 deleted the feat/cache-stable-eviction branch August 24, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant