mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Route blocked network requests to their owning calls (#32897)
## Why Policy-blocked proxy requests must terminate the corresponding active tool call and preserve the correct approval result, including when multiple calls are running concurrently. ## What changed - Resolve a blocked request's execution ID to its registered active network call before recording the policy denial. - Preserve an outcome already recorded for that call, and cancel the owning call after storing a new denial. ## Testing Expand network approval integration coverage for Guardian and user decisions, permission hooks, persisted policy amendments, concurrent calls, timeouts, cancellations, and unattributed proxy requests. GitOrigin-RevId: 961901bbc07cc498309453ec78cda1a56ab00a4b
This commit is contained in:
1 parent
592467fb96
commit
090f4de37b
6 files changed
+1066
-80
No files matched your search
@@ -415,14 +415,6 @@ impl NetworkApprovalService {
|
||||
(created, true)
|
||||
}
|
||||
|
||||
async fn record_outcome_for_single_active_call(&self, outcome: NetworkApprovalOutcome) {
|
||||
let Some(owner_call) = self.resolve_single_active_call().await else {
|
||||
return;
|
||||
};
|
||||
self.record_call_outcome(&owner_call.registration_id, outcome)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
async fn take_call_outcome(&self, registration_id: &str) -> Option<NetworkApprovalOutcome> {
|
||||
let mut calls = self.calls.lock().await;
|
||||
@@ -467,12 +459,29 @@ impl NetworkApprovalService {
|
||||
return;
|
||||
};
|
||||
|
||||
let outcome = NetworkApprovalOutcome::DeniedByPolicy(message);
|
||||
if let Some(execution_id) = blocked.execution_id.as_deref() {
|
||||
self.record_call_outcome(execution_id, outcome).await;
|
||||
let owner_call = if let Some(execution_id) = blocked.execution_id.as_deref() {
|
||||
self.resolve_active_call_by_execution_id(execution_id).await
|
||||
} else {
|
||||
self.record_outcome_for_single_active_call(outcome).await;
|
||||
self.resolve_single_active_call().await
|
||||
};
|
||||
let Some(owner_call) = owner_call else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut calls = self.calls.lock().await;
|
||||
if calls
|
||||
.call_outcomes
|
||||
.contains_key(&owner_call.registration_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
calls.call_outcomes.insert(
|
||||
owner_call.registration_id.clone(),
|
||||
NetworkApprovalOutcome::DeniedByPolicy(message),
|
||||
);
|
||||
|
||||
drop(calls);
|
||||
owner_call.cancellation_token.cancel();
|
||||
}
|
||||
|
||||
async fn active_turn_context(
|
||||
|
||||
@@ -387,12 +387,15 @@ async fn record_blocked_request_sets_policy_outcome_for_owner_call() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn blocked_request_policy_does_not_override_user_denial_outcome() {
|
||||
async fn blocked_request_does_not_override_recorded_approval_outcome() {
|
||||
let service = NetworkApprovalService::default();
|
||||
register_call_with_default_shell_trigger(&service, "registration-1").await;
|
||||
|
||||
service
|
||||
.record_call_outcome("registration-1", NetworkApprovalOutcome::DeniedByUser)
|
||||
.record_call_outcome(
|
||||
"registration-1",
|
||||
NetworkApprovalOutcome::DeniedByPolicy("custom approval rejection".to_string()),
|
||||
)
|
||||
.await;
|
||||
service
|
||||
.record_blocked_request(denied_blocked_request("example.com"))
|
||||
@@ -400,7 +403,32 @@ async fn blocked_request_policy_does_not_override_user_denial_outcome() {
|
||||
|
||||
assert_eq!(
|
||||
service.take_call_outcome("registration-1").await,
|
||||
Some(NetworkApprovalOutcome::DeniedByUser)
|
||||
Some(NetworkApprovalOutcome::DeniedByPolicy(
|
||||
"custom approval rejection".to_string()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn specific_approval_outcome_replaces_earlier_blocked_request() {
|
||||
let service = NetworkApprovalService::default();
|
||||
register_call_with_default_shell_trigger(&service, "registration-1").await;
|
||||
|
||||
service
|
||||
.record_blocked_request(denied_blocked_request("example.com"))
|
||||
.await;
|
||||
service
|
||||
.record_call_outcome(
|
||||
"registration-1",
|
||||
NetworkApprovalOutcome::DeniedByPolicy("specific approval rejection".to_string()),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
service.take_call_outcome("registration-1").await,
|
||||
Some(NetworkApprovalOutcome::DeniedByPolicy(
|
||||
"specific approval rejection".to_string()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user