fix: ensure PatchApplyBeginEvent and PatchApplyEndEvent are dispatched reliably #1760
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.
This is a follow-up to #1705, as that PR inadvertently lost the logic where
PatchApplyBeginEventandPatchApplyEndEventevents were sent when patches were auto-approved.Though as part of this fix, I believe this also makes an important safety fix to
assess_patch_safety(), as there was a case that returnedSandboxType::None, which arguably is the thing we were trying to avoid in #1705.On a high level, we want there to be only one codepath where
apply_patchhappens, which should be unified with the patch to runexec, in general, so that sandboxing is applied consistently for both cases.Prior to this change,
apply_patch()incorewould either:exec()to shell out toapply_patchusing the appropriate sandboxapply_patchin memorycodex/codex-rs/core/src/apply_patch.rs
Lines 61 to 63 in 549846b
In this implementation, only the latter would dispatch
PatchApplyBeginEventandPatchApplyEndEvent, though the former would dispatchExecCommandBeginEventandExecCommandEndEventfor theapply_patchcall (or, more specifically, thecodex --codex-run-as-apply-patch PATCHcall).To unify things in this PR, we:
apply_patch()function, and instead have it also return withDelegateToExec, though we add an extra field to the return value,user_explicitly_approved_this_action.codex.rswhere we processDelegateToExec, we useSandboxType::Nonewhenuser_explicitly_approved_this_actionistrue. This means we no longer run the apply_patch logic in memory, as we alwaysexec(). (Note this is what allowed us to delete so much code inapply_patch.rs.)codex.rs, we further updatenotify_exec_command_begin()andnotify_exec_command_end()to take additional fields to determine what type of notification to send:ExecCommandorPatchApply.Admittedly, this PR also drops some of the functionality about giving the user the opportunity to expand the set of writable roots as part of approving the
apply_patchcommand. I'm not sure how much that was used, and we should probably rethink how that works as we are currently tidying up the protocol to the TUI, in general.