Architecture

CCR Entry Lifecycle & EMA Threshold State

content overthreshold(compress_chat_completion /transform_*_inner)compute_key(bytes) →BLAKE3 40-hexlen < inline bytebudget(inline_ccr LRU 1024/ AphroditeStateinline_store)Token mode →SqliteCcrStore.put(TTL rows)Cache mode →InMemoryCcrStore.put(cap 10k + TTL)marker emittedpreview + <catalog_summaryemits DELTA previews(+N new compressionsthis turn -pre_llm_callcontext)/retrieve oraphrodite_retrieve(hash)byte-exactround-tripentry stays storedturn-age -conv_index keepslast 50 turnsrecent_markers keepslast 200LRU / byte-budgetpressure(inline_store_bytes> 256MB default)TTL elapsed(ccr_ttl_seconds,default 3600s)dropped fromindex/marker ringpop_back oldest(inline) / LRU tailbackend TTL sweep onget/lenprocess restartwipes all in-processstate(new process = freshstate)ClassifiedHashedStored_inlineStored_sqliteStored_lruPreviewedhash|type|size&gt;>>RecalledRetrievedDecayedEvictedExpiredGC
CCR ENTRY LIFECYCLE
ema = 200 (=2.0x) atbuild_stateeach successfulcompressionratio =orig/comp*100ema = 0.2 ratio +0.8 ema (α=0.2)threshold_for(ct)reads emaema/100 > 20 →tune=2.0 (raise bar)0 < ema/100 < 3 →tune=0.5 (lower bar)else → tune=1.0SeedUpdateAggressiveLenientNeutralfill_pct =clamp(100 -ema/20,1..99)*100exposed asX-Aphrodite-Fill-Pct +/metricsLive-tunableatomics(configreload):cache/token/inlinethresholds,code_multiplier
EMA COMPRESSION-RATIO THRESHOLD STATE
IN THIS DOCUMENT

Crimson marks the heading currently in view; every entry is one of the document's own headings.

State machine of a single CCR entry from creation through storage, preview, retrieval, and eviction/decay/GC - plus the separate EMA compression-ratio state that governs the adaptive threshold.

CCR entry lifecycle

content overthreshold(compress_chat_completion /transform_*_inner)compute_key(bytes) →BLAKE3 40-hexlen < inline bytebudget(inline_ccr LRU 1024/ AphroditeStateinline_store)Token mode →SqliteCcrStore.put(TTL rows)Cache mode →InMemoryCcrStore.put(cap 10k + TTL)marker emittedpreview + <catalog_summaryemits DELTA previews(+N new compressionsthis turn -pre_llm_callcontext)/retrieve oraphrodite_retrieve(hash)byte-exactround-tripentry stays storedturn-age -conv_index keepslast 50 turnsrecent_markers keepslast 200LRU / byte-budgetpressure(inline_store_bytes> 256MB default)TTL elapsed(ccr_ttl_seconds,default 3600s)dropped fromindex/marker ringpop_back oldest(inline) / LRU tailbackend TTL sweep onget/lenprocess restartwipes all in-processstate(new process = freshstate)ClassifiedHashedStored_inlineStored_sqliteStored_lruPreviewedhash|type|size&gt;>>RecalledRetrievedDecayedEvictedExpiredGC
CCR ENTRY LIFECYCLE

Eviction tiers:

StoreBoundEviction
inline_store (AphroditeState)500 entries AND 256 MB byte budgetevict_over_budget pops oldest from the back until both hold
inline_ccr (proxy AppState)1024 entries (LRU)LRU tail
recent_markers200 markers (ring)oldest dropped
conv_indexlast 50 turnsoldest turn removed
referenced_fileslast 100 filesoldest dropped
SqliteCcrStore / InMemoryCcrStoreTTL from ccr_ttl_seconds (default 3600s); in-memory also capped at 10,000 entrieslazy TTL sweep on get/len

A process restart is a hard reset: a fresh process has a new OnceLock/handles, so every prior marker becomes unresolvable at once (not a graceful per-entry transition).

The dylib is loaded once per process from the resolved path - restarting Hermes is how a new build is picked up.

EMA compression-ratio threshold state

ema = 200 (=2.0x) atbuild_stateeach successfulcompressionratio =orig/comp*100ema = 0.2 ratio +0.8 ema (α=0.2)threshold_for(ct)reads emaema/100 > 20 →tune=2.0 (raise bar)0 < ema/100 < 3 →tune=0.5 (lower bar)else → tune=1.0SeedUpdateAggressiveLenientNeutralfill_pct =clamp(100 -ema/20,1..99)*100exposed asX-Aphrodite-Fill-Pct +/metricsLive-tunableatomics(configreload):cache/token/inlinethresholds,code_multiplier
EMA COMPRESSION-RATIO THRESHOLD STATE

Call sites

ConcernModule
evict_over_budget / inline_store_putcrates/aphrodite/src/state/
record_marker (cap 200) / record_tool_event (cap 200)crates/aphrodite/src/state/
archive_turn (conv_index cap 50)crates/aphrodite/src/session.rs
EMA update / compute_fill_pctcrates/aphrodite/src/proxy.rs
Backend TTL: SqliteCcrStore / InMemoryCcrStorevendor/headroom/crates/headroom-core/src/ccr/backends/{sqlite,in_memory}.rs
inline_ccr LRU (1024)crates/aphrodite/src/proxy.rs