mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Add managed command checkpoints requiring fresh human approval (#58045)
## Why Managed command policies need to require a human decision independently of automatic review, hook allowances, and saved approvals. ## What changed - Support `decision = "prompt-user"` in managed `requirements.toml` prefix rules, requiring a fresh, one-time human decision for matching commands. - Add experimental `humanCommand` approval requests for clients advertising both `experimentalApi` and `requiredHumanApproval`. Accept only `accept`, `decline`, or `cancel`; reject commands when no capable client is available. - Restrict responses to capable clients that received the request, and replay pending prompts to compatible clients on reconnect. - Enable the capability in the TUI and update protocol schemas and client bindings. ## Testing Add coverage for fresh decisions overriding saved allowances, hook allowances, and automatic review, plus child-thread approval routing and rejection of responses from incompatible or unrelated clients. GitOrigin-RevId: 0b95ff6aab7f8a04b7298c8a4329d1fddf6a603e
This commit is contained in:
@@ -88,7 +88,7 @@ pub(crate) struct RunningTask {
|
||||
/// Mutable state for a single turn.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct TurnState {
|
||||
pending_approvals: HashMap<String, oneshot::Sender<ReviewDecision>>,
|
||||
pending_approvals: HashMap<String, PendingApproval>,
|
||||
pending_request_permissions: HashMap<String, PendingRequestPermissions>,
|
||||
pending_user_input: HashMap<String, oneshot::Sender<AcceptedUserInputResponse>>,
|
||||
pending_elicitations: HashMap<(String, RequestId), oneshot::Sender<ElicitationResponse>>,
|
||||
@@ -104,6 +104,27 @@ pub(crate) struct TurnState {
|
||||
pub(crate) last_known_step_context: Option<Arc<StepContext>>,
|
||||
}
|
||||
|
||||
pub(crate) struct PendingApproval {
|
||||
pub(crate) sender: oneshot::Sender<ReviewDecision>,
|
||||
pub(crate) kind: codex_protocol::approvals::ExecApprovalKind,
|
||||
pub(crate) turn_id: String,
|
||||
}
|
||||
|
||||
impl PendingApproval {
|
||||
pub(crate) fn validate(&self, decision: ReviewDecision) -> ReviewDecision {
|
||||
if self.kind == codex_protocol::approvals::ExecApprovalKind::HumanCommand
|
||||
&& !matches!(
|
||||
decision,
|
||||
ReviewDecision::Approved | ReviewDecision::Denied { .. } | ReviewDecision::Abort
|
||||
)
|
||||
{
|
||||
ReviewDecision::denied("Managed command policy requires a one-time human approval.")
|
||||
} else {
|
||||
decision
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Host receipt metadata follows the response through the asynchronous tool waiter.
|
||||
pub(crate) struct AcceptedUserInputResponse {
|
||||
pub(crate) response: RequestUserInputResponse,
|
||||
@@ -124,14 +145,24 @@ impl TurnState {
|
||||
&mut self,
|
||||
key: String,
|
||||
tx: oneshot::Sender<ReviewDecision>,
|
||||
) -> Option<oneshot::Sender<ReviewDecision>> {
|
||||
self.pending_approvals.insert(key, tx)
|
||||
kind: codex_protocol::approvals::ExecApprovalKind,
|
||||
turn_id: String,
|
||||
) -> Option<PendingApproval> {
|
||||
self.pending_approvals.insert(
|
||||
key,
|
||||
PendingApproval {
|
||||
sender: tx,
|
||||
kind,
|
||||
turn_id,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn remove_pending_approval(
|
||||
&mut self,
|
||||
key: &str,
|
||||
) -> Option<oneshot::Sender<ReviewDecision>> {
|
||||
pub(crate) fn pending_approval(&self, key: &str) -> Option<&PendingApproval> {
|
||||
self.pending_approvals.get(key)
|
||||
}
|
||||
|
||||
pub(crate) fn remove_pending_approval(&mut self, key: &str) -> Option<PendingApproval> {
|
||||
self.pending_approvals.remove(key)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user