fix: clarify comment, avoid per-turn tool clone on happy path

- Comment: remove 'never auto-re-pins' (it does auto-re-freeze),
  describe accurately as 'auto-re-freeze on drift'
- Perf: use as_deref().unwrap_or_default() to borrow &[Tool] for
  verify(), only to_vec() when constructing PinnedPrefix
This commit is contained in:
Justin Gao
2026-06-01 23:41:06 +08:00
committed by Hunter B
parent b122b58c92
commit c9e4c8b2ce
+13 -10
View File
@@ -312,29 +312,32 @@ impl Engine {
}
// Three-zone prefix contract (#2264): freeze baseline on first
// turn, verify against frozen baseline on subsequent turns.
// Operates alongside PrefixStabilityManager — this is the
// diagnostic layer that never auto-re-pins (unlike check_and_update).
// Phase 2: warn-only, no request refusal.
// turn, verify against it on subsequent turns. Operates alongside
// PrefixStabilityManager as an independent diagnostic layer.
// Phase 2: warn-only, auto-re-freeze on drift.
let system_text =
crate::prefix_cache::system_prompt_text(self.session.system_prompt.as_ref());
let current_tools: Vec<crate::models::Tool> = active_tools.clone().unwrap_or_default();
let current_tools: &[crate::models::Tool] = active_tools.as_deref().unwrap_or_default();
match &self.session.frozen_prefix {
Some(frozen) => {
if let Err(drift) = frozen.verify(&system_text, &current_tools) {
if let Err(drift) = frozen.verify(&system_text, current_tools) {
tracing::debug!(
target: "prefix_cache",
"three-zone drift: {drift}"
);
let pinned =
PinnedPrefix::new(self.session.system_prompt.as_ref(), current_tools);
let pinned = PinnedPrefix::new(
self.session.system_prompt.as_ref(),
current_tools.to_vec(),
);
self.session.frozen_prefix = Some(pinned.freeze());
}
}
None => {
let pinned =
PinnedPrefix::new(self.session.system_prompt.as_ref(), current_tools);
let pinned = PinnedPrefix::new(
self.session.system_prompt.as_ref(),
current_tools.to_vec(),
);
self.session.frozen_prefix = Some(pinned.freeze());
}
}