aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
56
akode-rs/ext/guardian-reviewer/src/context_policy.rs
Normal file
56
akode-rs/ext/guardian-reviewer/src/context_policy.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
//! Owns sync reviewer checkpoint policy for each context mode.
|
||||
//! Independent review retains thread-owned authorization without parent checkpoints.
|
||||
|
||||
use akode_features::Feature;
|
||||
use akode_features::Features;
|
||||
use akode_history::ResponseItemEnvelope;
|
||||
use akode_protocol::models::ResponseItem;
|
||||
|
||||
use crate::GuardianContextMode;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ReviewContextPolicy {
|
||||
Legacy,
|
||||
LegacyWithCheckpointReuse,
|
||||
ThreadOwned,
|
||||
Independent,
|
||||
}
|
||||
|
||||
impl ReviewContextPolicy {
|
||||
pub fn for_context(mode: GuardianContextMode, features: &Features) -> Self {
|
||||
match mode {
|
||||
GuardianContextMode::ThreadOwned => Self::ThreadOwned,
|
||||
GuardianContextMode::Independent => Self::Independent,
|
||||
GuardianContextMode::Legacy
|
||||
if features.enabled(Feature::GuardianReuseParentCompaction) =>
|
||||
{
|
||||
Self::LegacyWithCheckpointReuse
|
||||
}
|
||||
GuardianContextMode::Legacy => Self::Legacy,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parent_compaction(
|
||||
self,
|
||||
history: &[ResponseItemEnvelope],
|
||||
) -> anyhow::Result<Option<ResponseItem>> {
|
||||
if matches!(self, Self::Legacy | Self::Independent) {
|
||||
return Ok(None);
|
||||
}
|
||||
let Some(checkpoint) = akode_history::CompactionCheckpoint::latest(history) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let valid = checkpoint.is_usable();
|
||||
if !valid && self == Self::LegacyWithCheckpointReuse {
|
||||
// Legacy review can use its retained transcript without this checkpoint.
|
||||
return Ok(None);
|
||||
}
|
||||
anyhow::ensure!(
|
||||
valid,
|
||||
"parent compaction checkpoint is unusable for Guardian review"
|
||||
);
|
||||
// The synchronous reviewer can consume checkpoints across advertised comp_hash
|
||||
// values. Let the backend validate the payload; review errors still fail closed.
|
||||
Ok(Some(checkpoint.item.clone()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user