mirror of
https://github.com/openai/codex.git
synced 2026-09-17 12:23:33 +00:00
fix: add callback to map before sending request to fix race condition
This commit is contained in:
@@ -568,9 +568,19 @@ impl Session {
|
||||
cwd: PathBuf,
|
||||
reason: Option<String>,
|
||||
) -> oneshot::Receiver<ReviewDecision> {
|
||||
// Add the tx_approve callback to the map before sending the request.
|
||||
let (tx_approve, rx_approve) = oneshot::channel();
|
||||
let event_id = sub_id.clone();
|
||||
let prev_entry = {
|
||||
let mut state = self.state.lock_unchecked();
|
||||
state.pending_approvals.insert(sub_id, tx_approve)
|
||||
};
|
||||
if prev_entry.is_some() {
|
||||
warn!("Overwriting existing pending approval for sub_id: {event_id}");
|
||||
}
|
||||
|
||||
let event = Event {
|
||||
id: sub_id.clone(),
|
||||
id: event_id,
|
||||
msg: EventMsg::ExecApprovalRequest(ExecApprovalRequestEvent {
|
||||
call_id,
|
||||
command,
|
||||
@@ -579,10 +589,6 @@ impl Session {
|
||||
}),
|
||||
};
|
||||
let _ = self.tx_event.send(event).await;
|
||||
{
|
||||
let mut state = self.state.lock_unchecked();
|
||||
state.pending_approvals.insert(sub_id, tx_approve);
|
||||
}
|
||||
rx_approve
|
||||
}
|
||||
|
||||
@@ -594,9 +600,19 @@ impl Session {
|
||||
reason: Option<String>,
|
||||
grant_root: Option<PathBuf>,
|
||||
) -> oneshot::Receiver<ReviewDecision> {
|
||||
// Add the tx_approve callback to the map before sending the request.
|
||||
let (tx_approve, rx_approve) = oneshot::channel();
|
||||
let event_id = sub_id.clone();
|
||||
let prev_entry = {
|
||||
let mut state = self.state.lock_unchecked();
|
||||
state.pending_approvals.insert(sub_id, tx_approve)
|
||||
};
|
||||
if prev_entry.is_some() {
|
||||
warn!("Overwriting existing pending approval for sub_id: {event_id}");
|
||||
}
|
||||
|
||||
let event = Event {
|
||||
id: sub_id.clone(),
|
||||
id: event_id,
|
||||
msg: EventMsg::ApplyPatchApprovalRequest(ApplyPatchApprovalRequestEvent {
|
||||
call_id,
|
||||
changes: convert_apply_patch_to_protocol(action),
|
||||
@@ -605,10 +621,6 @@ impl Session {
|
||||
}),
|
||||
};
|
||||
let _ = self.tx_event.send(event).await;
|
||||
{
|
||||
let mut state = self.state.lock_unchecked();
|
||||
state.pending_approvals.insert(sub_id, tx_approve);
|
||||
}
|
||||
rx_approve
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user