Record Guardian context mode in review and classification telemetry (#49294)

## Why

Guardian review and classification telemetry lacks the context mode needed to distinguish `legacy`, `independent`, and `thread_owned` reviews.

## What changed

- Add `guardian_context_mode` to review and classification analytics and `context_mode` to their metrics.
- Capture the mode from the conversation history snapshot before review preparation or classification setup so failure metrics retain it, including when review preparation or reviewer startup fails.
- Use `unknown` for review metric tags when no context mode is available.

## Testing

Update metric assertions to cover `thread_owned` classification tags and the `unknown` review fallback.

GitOrigin-RevId: 79f7d11b3e4ccfc53681890d75fbc7c54e1ce7de
This commit is contained in:
felixxia-oai
2026-09-29 16:09:48 +00:00
committed by copyberry
parent 4773a132c3
commit d79a95bdf8
10 changed files with 58 additions and 6 deletions
+4
View File
@@ -400,6 +400,7 @@ pub enum GuardianReviewedAction {
#[derive(Clone, Serialize)]
pub struct GuardianReviewEventParams {
pub guardian_context_mode: Option<&'static str>,
pub thread_id: String,
pub turn_id: String,
pub review_id: String,
@@ -479,6 +480,7 @@ impl GuardianReviewTrackContext {
completed_at_ms: u64,
) -> GuardianReviewEventParams {
GuardianReviewEventParams {
guardian_context_mode: result.guardian_context_mode,
thread_id: self.thread_id.clone(),
turn_id: self.turn_id.clone(),
review_id: self.review_id.clone(),
@@ -531,6 +533,7 @@ impl GuardianReviewTrackContext {
#[derive(Debug)]
pub struct GuardianReviewAnalyticsResult {
pub guardian_context_mode: Option<&'static str>,
pub decision: GuardianReviewDecision,
pub terminal_status: GuardianReviewTerminalStatus,
pub failure_reason: Option<GuardianReviewFailureReason>,
@@ -556,6 +559,7 @@ pub struct GuardianReviewAnalyticsResult {
impl GuardianReviewAnalyticsResult {
pub fn without_session() -> Self {
Self {
guardian_context_mode: None,
decision: GuardianReviewDecision::Denied,
terminal_status: GuardianReviewTerminalStatus::FailedClosed,
failure_reason: None,
+1
View File
@@ -21,6 +21,7 @@ pub struct GuardianV2Event {
#[serde(untagged)]
pub enum GuardianV2EventKind {
Classification {
guardian_context_mode: &'static str,
outcome: &'static str,
risk_level: Option<&'static str>,
duration_ms: u64,
@@ -292,6 +292,7 @@ async fn guardian_review_event_ingests_custom_fact_with_optional_target_item() {
.ingest(
AnalyticsFact::Custom(CustomAnalyticsFact::GuardianReview(Box::new(
GuardianReviewEventParams {
guardian_context_mode: None,
thread_id: "thread-guardian".to_string(),
turn_id: "turn-guardian".to_string(),
review_id: "review-guardian".to_string(),