-
Notifications
You must be signed in to change notification settings - Fork 7.1k
fix: implement 'Allow this session' for apply_patch approvals #8451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+576
−149
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3d59b1f
fix: implement 'Allow this session' for apply_patch
owenlin0 e395603
clean up
owenlin0 e45c51a
add app-server test
owenlin0 b824fda
ApprovalDecision -> CommandExecutionApprovalDecision + FileChangeAppr…
owenlin0 b470dae
remove cached approval checks in apply_patch runtime
owenlin0 f1aeeee
PatchApprovalStore -> ApplyPatchApprovalStore
owenlin0 e69db79
format
owenlin0 b9931c2
shorten: remove 'this session' text
owenlin0 fc1c0fd
remove extra store and extend approvable to work for apply_patch
owenlin0 2991dcc
lint
owenlin0 1445ce5
add docstrings
owenlin0 267ccb0
rename
owenlin0 0d95657
change tui shortcut from s to a
owenlin0 f1afe46
update
owenlin0 df96740
pr feedback
owenlin0 006190e
fix
owenlin0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,9 @@ use codex_app_server_protocol::AccountRateLimitsUpdatedNotification; | |
| use codex_app_server_protocol::AgentMessageDeltaNotification; | ||
| use codex_app_server_protocol::ApplyPatchApprovalParams; | ||
| use codex_app_server_protocol::ApplyPatchApprovalResponse; | ||
| use codex_app_server_protocol::ApprovalDecision; | ||
| use codex_app_server_protocol::CodexErrorInfo as V2CodexErrorInfo; | ||
| use codex_app_server_protocol::CommandAction as V2ParsedCommand; | ||
| use codex_app_server_protocol::CommandExecutionApprovalDecision; | ||
| use codex_app_server_protocol::CommandExecutionOutputDeltaNotification; | ||
| use codex_app_server_protocol::CommandExecutionRequestApprovalParams; | ||
| use codex_app_server_protocol::CommandExecutionRequestApprovalResponse; | ||
|
|
@@ -26,6 +26,7 @@ use codex_app_server_protocol::ErrorNotification; | |
| use codex_app_server_protocol::ExecCommandApprovalParams; | ||
| use codex_app_server_protocol::ExecCommandApprovalResponse; | ||
| use codex_app_server_protocol::ExecPolicyAmendment as V2ExecPolicyAmendment; | ||
| use codex_app_server_protocol::FileChangeApprovalDecision; | ||
| use codex_app_server_protocol::FileChangeOutputDeltaNotification; | ||
| use codex_app_server_protocol::FileChangeRequestApprovalParams; | ||
| use codex_app_server_protocol::FileChangeRequestApprovalResponse; | ||
|
|
@@ -1193,6 +1194,21 @@ fn format_file_change_diff(change: &CoreFileChange) -> String { | |
| } | ||
| } | ||
|
|
||
| fn map_file_change_approval_decision( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic sounds supper hacky but it was already there so I guess out of scope |
||
| decision: FileChangeApprovalDecision, | ||
| ) -> (ReviewDecision, Option<PatchApplyStatus>) { | ||
| match decision { | ||
| FileChangeApprovalDecision::Accept => (ReviewDecision::Approved, None), | ||
| FileChangeApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None), | ||
| FileChangeApprovalDecision::Decline => { | ||
| (ReviewDecision::Denied, Some(PatchApplyStatus::Declined)) | ||
| } | ||
| FileChangeApprovalDecision::Cancel => { | ||
| (ReviewDecision::Abort, Some(PatchApplyStatus::Declined)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_arguments)] | ||
| async fn on_file_change_request_approval_response( | ||
| event_turn_id: String, | ||
|
|
@@ -1211,23 +1227,12 @@ async fn on_file_change_request_approval_response( | |
| .unwrap_or_else(|err| { | ||
| error!("failed to deserialize FileChangeRequestApprovalResponse: {err}"); | ||
| FileChangeRequestApprovalResponse { | ||
| decision: ApprovalDecision::Decline, | ||
| decision: FileChangeApprovalDecision::Decline, | ||
| } | ||
| }); | ||
|
|
||
| let (decision, completion_status) = match response.decision { | ||
| ApprovalDecision::Accept | ||
| | ApprovalDecision::AcceptForSession | ||
| | ApprovalDecision::AcceptWithExecpolicyAmendment { .. } => { | ||
| (ReviewDecision::Approved, None) | ||
| } | ||
| ApprovalDecision::Decline => { | ||
| (ReviewDecision::Denied, Some(PatchApplyStatus::Declined)) | ||
| } | ||
| ApprovalDecision::Cancel => { | ||
| (ReviewDecision::Abort, Some(PatchApplyStatus::Declined)) | ||
| } | ||
| }; | ||
| let (decision, completion_status) = | ||
| map_file_change_approval_decision(response.decision); | ||
| // Allow EventMsg::PatchApplyEnd to emit ItemCompleted for accepted patches. | ||
| // Only short-circuit on declines/cancels/failures. | ||
| (decision, completion_status) | ||
|
|
@@ -1281,28 +1286,30 @@ async fn on_command_execution_request_approval_response( | |
| .unwrap_or_else(|err| { | ||
| error!("failed to deserialize CommandExecutionRequestApprovalResponse: {err}"); | ||
| CommandExecutionRequestApprovalResponse { | ||
| decision: ApprovalDecision::Decline, | ||
| decision: CommandExecutionApprovalDecision::Decline, | ||
| } | ||
| }); | ||
|
|
||
| let decision = response.decision; | ||
|
|
||
| let (decision, completion_status) = match decision { | ||
| ApprovalDecision::Accept => (ReviewDecision::Approved, None), | ||
| ApprovalDecision::AcceptForSession => (ReviewDecision::ApprovedForSession, None), | ||
| ApprovalDecision::AcceptWithExecpolicyAmendment { | ||
| CommandExecutionApprovalDecision::Accept => (ReviewDecision::Approved, None), | ||
| CommandExecutionApprovalDecision::AcceptForSession => { | ||
| (ReviewDecision::ApprovedForSession, None) | ||
| } | ||
| CommandExecutionApprovalDecision::AcceptWithExecpolicyAmendment { | ||
| execpolicy_amendment, | ||
| } => ( | ||
| ReviewDecision::ApprovedExecpolicyAmendment { | ||
| proposed_execpolicy_amendment: execpolicy_amendment.into_core(), | ||
| }, | ||
| None, | ||
| ), | ||
| ApprovalDecision::Decline => ( | ||
| CommandExecutionApprovalDecision::Decline => ( | ||
| ReviewDecision::Denied, | ||
| Some(CommandExecutionStatus::Declined), | ||
| ), | ||
| ApprovalDecision::Cancel => ( | ||
| CommandExecutionApprovalDecision::Cancel => ( | ||
| ReviewDecision::Abort, | ||
| Some(CommandExecutionStatus::Declined), | ||
| ), | ||
|
|
@@ -1442,6 +1449,14 @@ mod tests { | |
| Arc::new(Mutex::new(HashMap::new())) | ||
| } | ||
|
|
||
| #[test] | ||
| fn file_change_accept_for_session_maps_to_approved_for_session() { | ||
| let (decision, completion_status) = | ||
| map_file_change_approval_decision(FileChangeApprovalDecision::AcceptForSession); | ||
| assert_eq!(decision, ReviewDecision::ApprovedForSession); | ||
| assert_eq!(completion_status, None); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_handle_error_records_message() -> Result<()> { | ||
| let conversation_id = ConversationId::new(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want this? How is it different from Cancel? (in any case, add a docstring please)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately they behave differently and both are used by VSCE. added docstrings
decline- does not abort the turncancel- aborts