Consolidate approval telemetry context (#36825)

## What changed

Add the tool name to `ApprovalCtx` and use the context's call ID and session
telemetry when recording approval decisions. This removes redundant `ToolCtx`
and telemetry parameters from `resolve_tool_approval`.

GitOrigin-RevId: 238a6f708f83993d64606bfaa74df344b0b46178
This commit is contained in:
Dylan Hurd authored and copyberry committed 2026-08-04 02:29:43 +00:00
1 parent 64bb8094ba
commit b2dc8b3e4b
3 files changed
+12 -21

No files matched your search

+8 -15
View File
@@ -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>
where
T: ToolRuntime<Rq, Out>,
@@ -214,7 +211,7 @@ where
decision: 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 @@ where
decision: 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 @@ where
decision: 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,
);