mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Validate responses against typed pending approvals
Approval responses were keyed only by string ID and could return values the server did not offer. That allowed one approval kind to consume another kind’s waiter and trusted client-supplied persistence payloads too broadly. Key pending approvals by request kind, record the exact accepted ReviewDecision values, and consume each waiter once before applying an amendment or continuing execution. Preserve ordinary session approval and the exact server-proposed restrictive network-deny path, while treating unoffered responses as denied. Route delegated cancellation to the matching exec or patch waiter and keep Guardian-only reviews independent of the approval ledger. Add unit, integration, delegation, and telemetry coverage for exact payloads, kind isolation, cancellation, replay, and compatibility.
This commit is contained in:
@@ -538,6 +538,7 @@ async fn handle_exec_approval(
|
||||
&approval_id_for_op,
|
||||
cancel_token,
|
||||
Some(&review_cancel),
|
||||
/*pending_approval_to_cancel*/ None,
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
@@ -559,6 +560,7 @@ async fn handle_exec_approval(
|
||||
&approval_id_for_op,
|
||||
cancel_token,
|
||||
/*review_cancel_token*/ None,
|
||||
Some(PendingApprovalToCancel::Exec),
|
||||
)
|
||||
.await
|
||||
};
|
||||
@@ -647,6 +649,7 @@ async fn handle_patch_approval(
|
||||
&approval_id,
|
||||
cancel_token,
|
||||
Some(&review_cancel),
|
||||
/*pending_approval_to_cancel*/ None,
|
||||
)
|
||||
.await,
|
||||
)
|
||||
@@ -665,6 +668,7 @@ async fn handle_patch_approval(
|
||||
&approval_id,
|
||||
cancel_token,
|
||||
/*review_cancel_token*/ None,
|
||||
Some(PendingApprovalToCancel::Patch),
|
||||
)
|
||||
.await
|
||||
};
|
||||
@@ -763,6 +767,7 @@ async fn maybe_auto_review_mcp_request_user_input(
|
||||
&event.call_id,
|
||||
cancel_token,
|
||||
Some(&review_cancel),
|
||||
/*pending_approval_to_cancel*/ None,
|
||||
)
|
||||
.await;
|
||||
let selected_label = match decision {
|
||||
@@ -884,13 +889,21 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Await an approval decision, aborting on cancellation.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum PendingApprovalToCancel {
|
||||
Exec,
|
||||
Patch,
|
||||
}
|
||||
|
||||
/// Await an approval decision, aborting any matching parent approval waiter on
|
||||
/// cancellation. Guardian-only reviews do not create such a waiter.
|
||||
async fn await_approval_with_cancel<F>(
|
||||
fut: F,
|
||||
parent_session: &Session,
|
||||
approval_id: &str,
|
||||
cancel_token: &CancellationToken,
|
||||
review_cancel_token: Option<&CancellationToken>,
|
||||
pending_approval_to_cancel: Option<PendingApprovalToCancel>,
|
||||
) -> codex_protocol::protocol::ReviewDecision
|
||||
where
|
||||
F: core::future::Future<Output = codex_protocol::protocol::ReviewDecision>,
|
||||
@@ -901,9 +914,25 @@ where
|
||||
if let Some(review_cancel_token) = review_cancel_token {
|
||||
review_cancel_token.cancel();
|
||||
}
|
||||
parent_session
|
||||
.notify_approval(approval_id, codex_protocol::protocol::ReviewDecision::Abort)
|
||||
.await;
|
||||
match pending_approval_to_cancel {
|
||||
Some(PendingApprovalToCancel::Exec) => {
|
||||
parent_session
|
||||
.notify_exec_approval(
|
||||
approval_id,
|
||||
codex_protocol::protocol::ReviewDecision::Abort,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
Some(PendingApprovalToCancel::Patch) => {
|
||||
parent_session
|
||||
.notify_patch_approval(
|
||||
approval_id,
|
||||
codex_protocol::protocol::ReviewDecision::Abort,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
codex_protocol::protocol::ReviewDecision::Abort
|
||||
}
|
||||
decision = fut => {
|
||||
|
||||
Reference in New Issue
Block a user