Lightweight coding agent that runs in your terminal
Rust
Consolidate approval telemetry context (#36825)
Dylan Hurdb2dc8b3e4be4
diff --git a/codex-rs/core/src/tools/approvals.rs b/codex-rs/core/src/tools/approvals.rsindex 4d9dfd9e02..693f37707a 100644--- a/codex-rs/core/src/tools/approvals.rs+++ b/codex-rs/core/src/tools/approvals.rs@@ -9,7 +9,6 @@ use crate::sandboxing::SandboxPermissions;use crate::session::turn_context::TurnContext;use crate::tools::flat_tool_name;use crate::tools::sandboxing::ApprovalCtx;-use crate::tools::sandboxing::ToolCtx;use crate::tools::sandboxing::ToolError;use crate::tools::sandboxing::ToolRuntime;use codex_config::types::ApprovalsReviewer;@@ -193,9 +192,7 @@ pub(super) async fn resolve_tool_approval<Rq, Out, T>(req: &Rq,permission_request_run_id: &str,ctx: ApprovalCtx<'_>,- tool_ctx: &ToolCtx,reviewer: ApprovalReviewer,- otel: &codex_otel::SessionTelemetry,) -> Result<ReviewDecision, ToolError>whereT: ToolRuntime<Rq, Out>,@@ -214,7 +211,7 @@ wheredecision: ReviewDecision::Approved,source: ApprovalResolutionSource::Hook,};- record_resolution(otel, tool_ctx, &resolution);+ record_resolution(&ctx, &resolution);return resolution.into_tool_result();}Some(PermissionRequestDecision::Deny { message }) => {@@ -222,7 +219,7 @@ wheredecision: ReviewDecision::denied(message),source: ApprovalResolutionSource::Hook,};- record_resolution(otel, tool_ctx, &resolution);+ record_resolution(&ctx, &resolution);return resolution.into_tool_result();}None => {}@@ -245,7 +242,7 @@ where),source: ApprovalResolutionSource::Guardian,};- record_resolution(otel, tool_ctx, &resolution);+ record_resolution(&ctx, &resolution);return resolution.into_tool_result();}};@@ -268,24 +265,20 @@ wheredecision: resolution,source,};- record_resolution(otel, tool_ctx, &resolution);+ record_resolution(&ctx, &resolution);resolution.into_tool_result()}-fn record_resolution(- otel: &codex_otel::SessionTelemetry,- tool_ctx: &ToolCtx,- resolution: &ApprovalResolution,-) {+fn record_resolution(ctx: &ApprovalCtx<'_>, resolution: &ApprovalResolution) {let source = match resolution.source {ApprovalResolutionSource::Hook => ToolDecisionSource::Config,ApprovalResolutionSource::Guardian => ToolDecisionSource::AutomatedReviewer,ApprovalResolutionSource::User => ToolDecisionSource::User,};- let tool_name = flat_tool_name(&tool_ctx.tool_name);- otel.tool_decision(+ let tool_name = flat_tool_name(ctx.tool_name);+ ctx.turn.session_telemetry.tool_decision(tool_name.as_ref(),- &tool_ctx.call_id,+ ctx.call_id,&resolution.decision,source,);diff --git a/codex-rs/core/src/tools/orchestrator.rs b/codex-rs/core/src/tools/orchestrator.rsindex b994c658f6..fbcbc596b5 100644--- a/codex-rs/core/src/tools/orchestrator.rs+++ b/codex-rs/core/src/tools/orchestrator.rs@@ -171,6 +171,7 @@ impl ToolOrchestrator {session: &tool_ctx.session,turn: &tool_ctx.turn,call_id: &tool_ctx.call_id,+ tool_name: &tool_ctx.tool_name,retry_reason: None,network_approval_context: None,};@@ -179,9 +180,7 @@ impl ToolOrchestrator {req,tool_ctx.call_id.as_str(),approval_ctx,- tool_ctx,ApprovalReviewer::Guardian,- &otel,).await?;already_approved = true;@@ -202,6 +201,7 @@ impl ToolOrchestrator {session: &tool_ctx.session,turn: &tool_ctx.turn,call_id: &tool_ctx.call_id,+ tool_name: &tool_ctx.tool_name,retry_reason: reason.clone(),network_approval_context: None,};@@ -210,13 +210,11 @@ impl ToolOrchestrator {req,tool_ctx.call_id.as_str(),approval_ctx,- tool_ctx,if strict_auto_review {ApprovalReviewer::Guardian} else {ApprovalReviewer::for_turn(turn_ctx)},- &otel,).await?;already_approved = true;@@ -397,6 +395,7 @@ impl ToolOrchestrator {session: &tool_ctx.session,turn: &tool_ctx.turn,call_id: &tool_ctx.call_id,+ tool_name: &tool_ctx.tool_name,retry_reason: Some(retry_reason),network_approval_context: network_approval_context.clone(),};@@ -407,13 +406,11 @@ impl ToolOrchestrator {req,&permission_request_run_id,approval_ctx,- tool_ctx,if strict_auto_review {ApprovalReviewer::Guardian} else {ApprovalReviewer::for_turn(turn_ctx)},- &otel,).await?;}diff --git a/codex-rs/core/src/tools/sandboxing.rs b/codex-rs/core/src/tools/sandboxing.rsindex 98332fd228..07bfeca90f 100644--- a/codex-rs/core/src/tools/sandboxing.rs+++ b/codex-rs/core/src/tools/sandboxing.rs@@ -121,6 +121,7 @@ pub(crate) struct ApprovalCtx<'a> {pub session: &'a Arc<Session>,pub turn: &'a Arc<TurnContext>,pub call_id: &'a str,+ pub tool_name: &'a ToolName,pub retry_reason: Option<String>,pub network_approval_context: Option<NetworkApprovalContext>,}