mirror of
https://github.com/openai/codex.git
synced 2026-11-25 07:23:22 +00:00
Handle pending network reviews after process completion (#42746)
## Why A remote process can finish while a network policy review is still pending. Normal process cleanup should withdraw that review without turning the completed command into a review failure or losing its output. ## What changed - Record whether a network policy request was withdrawn because the process finished, was cancelled, lost its executor connection, or timed out. - Treat normal process completion as cleanup while retaining fail-closed behavior for other cancellation causes. - Preserve explicit network denials before policy persistence so cleanup cannot replace the reported call outcome. ## Testing Add an integration test that completes a remote process during a pending network review and verifies that the command reports its successful exit and output without approving the withdrawn request. GitOrigin-RevId: 7f42d75631ee29eba43bf04cc953eea490f553fc
This commit is contained in:
1 parent
4e48cd02da
commit
8e85265c39
9 files changed
+430
-11
No files matched your search
@@ -9,6 +9,8 @@ use codex_network_proxy::NetworkDecision;
|
||||
use codex_network_proxy::NetworkPolicyDecision;
|
||||
use codex_network_proxy::NetworkPolicyRequest;
|
||||
use codex_network_proxy::NetworkProtocol;
|
||||
use codex_network_proxy::NetworkRequestCancellation;
|
||||
use codex_network_proxy::NetworkRequestCancellationReason;
|
||||
use serde_json::Value;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::time::Instant;
|
||||
@@ -526,6 +528,10 @@ impl Inner {
|
||||
Ok(true) => self.remove_session_if(process_id, session),
|
||||
Ok(false) => {}
|
||||
Err(error) => {
|
||||
session
|
||||
.network_policy
|
||||
.cancellation
|
||||
.record(NetworkRequestCancellationReason::ProcessCancelled);
|
||||
let terminated: Result<TerminateResponse, ExecServerError> = rpc_client
|
||||
.call_for_cleanup(
|
||||
EXEC_TERMINATE_METHOD,
|
||||
@@ -688,6 +694,10 @@ impl ExecServerClient {
|
||||
let process_cancelled = session
|
||||
.as_ref()
|
||||
.map(|session| session.network_policy.cancelled.clone());
|
||||
let process_cancellation = session
|
||||
.as_ref()
|
||||
.map(|session| session.network_policy.cancellation.clone());
|
||||
let cancellation = NetworkRequestCancellation::default();
|
||||
let expected_session = session.as_ref().map(Arc::downgrade);
|
||||
let policy_request =
|
||||
(process_id_valid && host_valid).then_some(NetworkPolicyRequest {
|
||||
@@ -712,6 +722,7 @@ impl ExecServerClient {
|
||||
exec_policy_hint: None,
|
||||
execution_id: None,
|
||||
disconnect: None,
|
||||
cancellation: Some(cancellation.clone()),
|
||||
});
|
||||
let inner = Arc::downgrade(&inner);
|
||||
let rpc_client = Arc::downgrade(&rpc_client);
|
||||
@@ -721,18 +732,26 @@ impl ExecServerClient {
|
||||
let _request_guard = request_guard;
|
||||
let decision = match (controller, policy_request, process_cancelled) {
|
||||
(Some(controller), Some(request), Some(process_cancelled)) => {
|
||||
// Core's pending-approval guard makes dropping this
|
||||
// future on process removal or deadline fail closed.
|
||||
// Keep the decision future outside select/timeout so its
|
||||
// guard sees the cancellation cause before it is dropped.
|
||||
let mut decision = controller.decider.decide(request);
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = connection_cancelled.cancelled() => return,
|
||||
_ = connection_cancelled.cancelled() => {
|
||||
cancellation.record(NetworkRequestCancellationReason::ConnectionClosed);
|
||||
return;
|
||||
},
|
||||
_ = process_cancelled.cancelled() => {
|
||||
cancellation.record(process_cancellation.as_ref()
|
||||
.and_then(NetworkRequestCancellation::reason)
|
||||
.unwrap_or(NetworkRequestCancellationReason::ProcessCancelled));
|
||||
NetworkDecision::deny(NETWORK_POLICY_DENIAL_REASON)
|
||||
}
|
||||
decision = timeout(
|
||||
result = timeout(
|
||||
controller.timeout,
|
||||
controller.decider.decide(request),
|
||||
) => decision.unwrap_or_else(|_| {
|
||||
&mut decision,
|
||||
) => result.unwrap_or_else(|_| {
|
||||
cancellation.record(NetworkRequestCancellationReason::TimedOut);
|
||||
NetworkDecision::deny(NETWORK_POLICY_DENIAL_REASON)
|
||||
}),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user