refs(#2264): Phase 2 — wire FrozenPrefix::verify() into turn_loop
Refs #2264 (Phase 2 — conservative path, warn-only).
Summary
Wires the Phase 1 FrozenPrefix type into the request path for the first
time. Adds a three-zone diagnostic layer alongside the existing
PrefixStabilityManager::check_and_update(). No behavioral change to
existing prefix-cache monitoring — this is an additional, independent
observation layer.
First turn: freeze baseline via PinnedPrefix::freeze()
Subsequent turns: FrozenPrefix::verify() against current system+tools,
log drift via tracing::debug!, auto-re-freeze
Files
| File | Change |
|---|---|
crates/tui/src/core/session.rs |
+4: import FrozenPrefix, add frozen_prefix field + default |
crates/tui/src/core/engine/turn_loop.rs |
+32: import PinnedPrefix, insert verify block |
What this does NOT do
- No request blocking
- No user-visible events (yet — Phase 3)
- No interaction with existing
PrefixStabilityManageror/cache stats - No
/cache zoneschanges
Testing
- cargo check: clean (6 pre-existing schema_migration warnings only)
- 37 prompt_zones + prefix_cache tests pass
Greptile Summary
Wires the Phase 1 FrozenPrefix type into the turn loop as a second, independent prefix-drift diagnostic layer. On the first turn it freezes a baseline; on subsequent turns it calls FrozenPrefix::verify(), logs any drift at debug level, and auto-re-freezes. No user-visible events or request blocking are introduced.
turn_loop.rs: Adds a ~32-line block afterPrefixStabilityManager::check_and_updatethat freezes/verifies theFrozenPrefixbaseline usingPinnedPrefix::new+freeze().session.rs: Addsfrozen_prefix: Option<FrozenPrefix>to theSessionstruct, defaulting toNone, imported fromprompt_zones.
Confidence Score: 4/5
The change is warn-only with no request blocking, but it introduces a tool-hashing approach that diverges from the established PrefixStabilityManager — any tool carrying a cache_control or allowed_callers field will cause the two layers to disagree, producing false-positive drift signals that will become user-visible in Phase 3.
The tool digest function in prompt_zones uses full serde serialization while prefix_cache intentionally strips internal-only fields for the same hashing purpose. This divergence is baked in from the first freeze, making the FrozenPrefix baseline unreliable for any session with tools that have non-None internal fields. Fixing it before Phase 3 is significantly cheaper than after.
crates/tui/src/core/engine/turn_loop.rs — the verify block, and by extension prompt_zones::tool_catalog_digest which should align its serialization with prefix_cache::tool_to_api_json.
Important Files Changed
| Filename | Overview |
|---|---|
| crates/tui/src/core/engine/turn_loop.rs | Wires FrozenPrefix verification into the turn loop; the tool-hashing logic diverges from PrefixStabilityManager (full serde serialization vs. API-shape-only), which will produce false-positive drift events for any tool with internal-only fields (e.g. cache_control). |
| crates/tui/src/core/session.rs | Adds frozen_prefix: Option |
Sequence Diagram
sequenceDiagram
participant TL as turn_loop
participant PSM as PrefixStabilityManager
participant FP as FrozenPrefix (new)
participant Sess as Session
TL->>PSM: check_and_update(system_text, active_tools)
alt drift detected
PSM-->>TL: Err(PrefixChange)
TL->>TL: emit PrefixCacheChange event
else stable
PSM-->>TL: Ok(true)
end
TL->>TL: "system_text = prefix_cache::system_prompt_text(...)"
TL->>TL: "current_tools = active_tools.as_deref()"
alt session.frozen_prefix is None (first turn)
TL->>TL: PinnedPrefix::new(system_prompt, tools.to_vec())
TL->>FP: pinned.freeze()
TL->>Sess: "frozen_prefix = Some(frozen)"
else session.frozen_prefix is Some(frozen)
TL->>FP: frozen.verify(system_text, current_tools)
alt verify Err(drift)
FP-->>TL: PrefixDrift
TL->>TL: tracing::debug!(drift)
TL->>TL: PinnedPrefix::new(...) — auto-re-freeze
TL->>Sess: "frozen_prefix = Some(new_frozen)"
else verify Ok
FP-->>TL: ()
end
end
TL->>TL: build MessageRequest and send
Reviews (2): Last reviewed commit: "fix: clarify comment, avoid per-turn too..." | Re-trigger Greptile
Hey @encyc — just wanted to let you know that the FrozenPrefix Phase 2 has been harvested into the v0.8.50 triage branch (#2504). The three-zone diagnostic layer landed cleanly and all tests pass. Really tidy work — adding a second independent observation layer without any behavioral change is exactly the right approach for a phased rollout like this. Thank you! 🐋