Gate streaming apply_patch parser

This commit is contained in:
Akshay Nathan
2026-05-04 11:15:50 -07:00
parent 66e5d99eb2
commit b459ba0f4d
10 changed files with 230 additions and 17 deletions
+6
View File
@@ -364,6 +364,9 @@
"apply_patch_streaming_events": {
"type": "boolean"
},
"apply_patch_streaming_parser": {
"type": "boolean"
},
"apps": {
"type": "boolean"
},
@@ -3833,6 +3836,9 @@
"apply_patch_streaming_events": {
"type": "boolean"
},
"apply_patch_streaming_parser": {
"type": "boolean"
},
"apps": {
"type": "boolean"
},
@@ -35,6 +35,7 @@ use crate::tools::sandboxing::ToolCtx;
use codex_apply_patch::ApplyPatchAction;
use codex_apply_patch::ApplyPatchFileChange;
use codex_apply_patch::Hunk;
use codex_apply_patch::ParsePatchMode;
use codex_apply_patch::StreamingPatchParser;
use codex_exec_server::ExecutorFileSystem;
use codex_features::Feature;
@@ -255,6 +256,14 @@ fn apply_patch_payload_command(payload: &ToolPayload) -> Option<String> {
}
}
fn apply_patch_mode(turn: &TurnContext) -> ParsePatchMode {
if turn.features.enabled(Feature::ApplyPatchStreamingParser) {
ParsePatchMode::Streaming
} else {
ParsePatchMode::Legacy
}
}
async fn effective_patch_permissions(
session: &Session,
turn: &TurnContext,
@@ -373,8 +382,10 @@ impl ToolHandler for ApplyPatchHandler {
.environment
.is_remote()
.then(|| turn.file_system_sandbox_context(/*additional_permissions*/ None));
match codex_apply_patch::maybe_parse_apply_patch_verified(
let parse_mode = apply_patch_mode(turn.as_ref());
match codex_apply_patch::maybe_parse_apply_patch_verified_with_mode(
&command,
parse_mode,
&cwd,
fs.as_ref(),
sandbox.as_ref(),
@@ -478,8 +489,15 @@ pub(crate) async fn intercept_apply_patch(
.primary_environment()
.filter(|env| env.environment.is_remote())
.map(|_| turn.file_system_sandbox_context(/*additional_permissions*/ None));
match codex_apply_patch::maybe_parse_apply_patch_verified(command, cwd, fs, sandbox.as_ref())
.await
let parse_mode = apply_patch_mode(turn.as_ref());
match codex_apply_patch::maybe_parse_apply_patch_verified_with_mode(
command,
parse_mode,
cwd,
fs,
sandbox.as_ref(),
)
.await
{
codex_apply_patch::MaybeApplyPatchVerified::Body(changes) => {
session
@@ -99,6 +99,18 @@ async fn post_tool_use_payload_uses_patch_input_and_tool_output() {
);
}
#[tokio::test]
async fn apply_patch_mode_follows_streaming_parser_feature() {
let (_, mut turn) = make_session_and_context().await;
assert_eq!(apply_patch_mode(&turn), ParsePatchMode::Legacy);
turn.features
.enable(Feature::ApplyPatchStreamingParser)
.expect("enable feature");
assert_eq!(apply_patch_mode(&turn), ParsePatchMode::Streaming);
}
#[test]
fn diff_consumer_does_not_stream_json_tool_call_arguments() {
let mut consumer = ApplyPatchArgumentDiffConsumer::default();
@@ -199,8 +199,8 @@ impl ToolRuntime<ApplyPatchRequest, ExecToolCallOutput> for ApplyPatchRuntime {
let sandbox = Self::file_system_sandbox_context_for_attempt(req, attempt);
let mut stdout = Vec::new();
let mut stderr = Vec::new();
let result = codex_apply_patch::apply_patch(
&req.action.patch,
let result = codex_apply_patch::apply_hunks(
req.action.hunks(),
&req.action.cwd,
&mut stdout,
&mut stderr,