Skip to content

Commit 084236f

Browse files
authored
Add call_id to patch approvals and elicitations (openai#1660)
Builds on openai#1659 and adds call_id to a few more places for the same reason.
1 parent bc944e7 commit 084236f

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

codex-rs/core/src/codex.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl Session {
279279
pub async fn request_patch_approval(
280280
&self,
281281
sub_id: String,
282+
call_id: String,
282283
action: &ApplyPatchAction,
283284
reason: Option<String>,
284285
grant_root: Option<PathBuf>,
@@ -287,6 +288,7 @@ impl Session {
287288
let event = Event {
288289
id: sub_id.clone(),
289290
msg: EventMsg::ApplyPatchApprovalRequest(ApplyPatchApprovalRequestEvent {
291+
call_id,
290292
changes: convert_apply_patch_to_protocol(action),
291293
reason,
292294
grant_root,
@@ -1629,7 +1631,7 @@ async fn apply_patch(
16291631
// Compute a readable summary of path changes to include in the
16301632
// approval request so the user can make an informed decision.
16311633
let rx_approve = sess
1632-
.request_patch_approval(sub_id.clone(), &action, None, None)
1634+
.request_patch_approval(sub_id.clone(), call_id.clone(), &action, None, None)
16331635
.await;
16341636
match rx_approve.await.unwrap_or_default() {
16351637
ReviewDecision::Approved | ReviewDecision::ApprovedForSession => false,
@@ -1667,7 +1669,13 @@ async fn apply_patch(
16671669
));
16681670

16691671
let rx = sess
1670-
.request_patch_approval(sub_id.clone(), &action, reason.clone(), Some(root.clone()))
1672+
.request_patch_approval(
1673+
sub_id.clone(),
1674+
call_id.clone(),
1675+
&action,
1676+
reason.clone(),
1677+
Some(root.clone()),
1678+
)
16711679
.await;
16721680

16731681
if !matches!(
@@ -1751,6 +1759,7 @@ async fn apply_patch(
17511759
let rx = sess
17521760
.request_patch_approval(
17531761
sub_id.clone(),
1762+
call_id.clone(),
17541763
&action,
17551764
reason.clone(),
17561765
Some(root.clone()),

codex-rs/core/src/protocol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ pub struct ExecApprovalRequestEvent {
435435

436436
#[derive(Debug, Clone, Deserialize, Serialize)]
437437
pub struct ApplyPatchApprovalRequestEvent {
438+
/// Responses API call id for the associated patch apply call, if available.
439+
pub call_id: String,
438440
pub changes: HashMap<PathBuf, FileChange>,
439441
/// Optional explanatory reason (e.g. request for extra write access).
440442
#[serde(skip_serializing_if = "Option::is_none")]

codex-rs/mcp-server/src/codex_tool_runner.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async fn run_codex_tool_session_inner(
156156
EventMsg::ExecApprovalRequest(ExecApprovalRequestEvent {
157157
command,
158158
cwd,
159-
call_id: _,
159+
call_id,
160160
reason: _,
161161
}) => {
162162
handle_exec_approval_request(
@@ -167,6 +167,7 @@ async fn run_codex_tool_session_inner(
167167
request_id.clone(),
168168
request_id_str.clone(),
169169
event.id.clone(),
170+
call_id,
170171
)
171172
.await;
172173
continue;
@@ -180,11 +181,13 @@ async fn run_codex_tool_session_inner(
180181
break;
181182
}
182183
EventMsg::ApplyPatchApprovalRequest(ApplyPatchApprovalRequestEvent {
184+
call_id,
183185
reason,
184186
grant_root,
185187
changes,
186188
}) => {
187189
handle_patch_approval_request(
190+
call_id,
188191
reason,
189192
grant_root,
190193
changes,

codex-rs/mcp-server/src/exec_approval.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct ExecApprovalElicitRequestParams {
3232
pub codex_elicitation: String,
3333
pub codex_mcp_tool_call_id: String,
3434
pub codex_event_id: String,
35+
pub codex_call_id: String,
3536
pub codex_command: Vec<String>,
3637
pub codex_cwd: PathBuf,
3738
}
@@ -45,6 +46,7 @@ pub struct ExecApprovalResponse {
4546
pub decision: ReviewDecision,
4647
}
4748

49+
#[allow(clippy::too_many_arguments)]
4850
pub(crate) async fn handle_exec_approval_request(
4951
command: Vec<String>,
5052
cwd: PathBuf,
@@ -53,6 +55,7 @@ pub(crate) async fn handle_exec_approval_request(
5355
request_id: RequestId,
5456
tool_call_id: String,
5557
event_id: String,
58+
call_id: String,
5659
) {
5760
let escaped_command =
5861
shlex::try_join(command.iter().map(|s| s.as_str())).unwrap_or_else(|_| command.join(" "));
@@ -71,6 +74,7 @@ pub(crate) async fn handle_exec_approval_request(
7174
codex_elicitation: "exec-approval".to_string(),
7275
codex_mcp_tool_call_id: tool_call_id.clone(),
7376
codex_event_id: event_id.clone(),
77+
codex_call_id: call_id,
7478
codex_command: command,
7579
codex_cwd: cwd,
7680
};

codex-rs/mcp-server/src/patch_approval.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct PatchApprovalElicitRequestParams {
2727
pub codex_elicitation: String,
2828
pub codex_mcp_tool_call_id: String,
2929
pub codex_event_id: String,
30+
pub codex_call_id: String,
3031
#[serde(skip_serializing_if = "Option::is_none")]
3132
pub codex_reason: Option<String>,
3233
#[serde(skip_serializing_if = "Option::is_none")]
@@ -41,6 +42,7 @@ pub struct PatchApprovalResponse {
4142

4243
#[allow(clippy::too_many_arguments)]
4344
pub(crate) async fn handle_patch_approval_request(
45+
call_id: String,
4446
reason: Option<String>,
4547
grant_root: Option<PathBuf>,
4648
changes: HashMap<PathBuf, FileChange>,
@@ -66,6 +68,7 @@ pub(crate) async fn handle_patch_approval_request(
6668
codex_elicitation: "patch-approval".to_string(),
6769
codex_mcp_tool_call_id: tool_call_id.clone(),
6870
codex_event_id: event_id.clone(),
71+
codex_call_id: call_id,
6972
codex_reason: reason,
7073
codex_grant_root: grant_root,
7174
codex_changes: changes,

codex-rs/mcp-server/tests/codex_tool.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ fn create_expected_elicitation_request(
171171
codex_event_id,
172172
codex_command: command,
173173
codex_cwd: workdir.to_path_buf(),
174+
codex_call_id: "call1234".to_string(),
174175
})?),
175176
})
176177
}
@@ -384,6 +385,7 @@ fn create_expected_patch_approval_elicitation_request(
384385
codex_reason: reason,
385386
codex_grant_root: grant_root,
386387
codex_changes: changes,
388+
codex_call_id: "call1234".to_string(),
387389
})?),
388390
})
389391
}

codex-rs/tui/src/chatwidget.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl ChatWidget<'_> {
328328
self.bottom_pane.push_approval_request(request);
329329
}
330330
EventMsg::ApplyPatchApprovalRequest(ApplyPatchApprovalRequestEvent {
331+
call_id: _,
331332
changes,
332333
reason,
333334
grant_root,

0 commit comments

Comments
 (0)