# Context shaping must keep the cached prefix stable Status: accepted ## Context Prompt caching keys on the request prefix. Any change to earlier bytes invalidates the cache from that point on. ## Decision - Observation masking is a pure function of the message list and a boundary, so the prefix is byte-stable while the boundary stays put. Moving the boundary rewrites the cache from the first changed result, so the agent moves it rarely, in steps of a fixed number of assistant turns. The session file keeps the originals. - The batching nudge is injected at turn end so the cached prefix is untouched. ## Consequences Masking lags behind the ideal point in exchange for cache hits. Code: crates/hx-core/src/mask.rs (module, `boundary`, `apply`), crates/hx-core/src/nudge.rs