Skip to content

Stream apply_patch changes#17862

Merged
akshaynathan merged 12 commits intomainfrom
draft-stream-responses-apply-patch-events
Apr 17, 2026
Merged

Stream apply_patch changes#17862
akshaynathan merged 12 commits intomainfrom
draft-stream-responses-apply-patch-events

Conversation

@akshaynathan
Copy link
Copy Markdown
Contributor

Adds new events for streaming apply_patch changes from responses api. This is to enable clients to show progress during file writes.

Caveat: This does not work with apply_patch in function call mode, since that required adding streaming json parsing.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@akshaynathan akshaynathan changed the title [DRAFT} Stream apply_patch changes [DRAFT] Stream apply_patch changes Apr 15, 2026
@akshaynathan akshaynathan force-pushed the draft-stream-responses-apply-patch-events branch from ac74bdc to aa91fe9 Compare April 15, 2026 15:49
@akshaynathan akshaynathan requested a review from pakrym-oai April 15, 2026 16:02
@akshaynathan akshaynathan changed the title [DRAFT] Stream apply_patch changes Stream apply_patch changes Apr 15, 2026
@akshaynathan
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@akshaynathan
Copy link
Copy Markdown
Contributor Author

recheck

github-actions bot added a commit that referenced this pull request Apr 15, 2026
@pakrym-oai
Copy link
Copy Markdown
Collaborator

Needs an integration test. Search suite or test_codex.

Comment thread codex-rs/apply-patch/src/parser.rs Outdated
return Err(e);
}
ParseMode::Lenient => check_patch_boundaries_lenient(&lines, e)?,
ParseMode::Streaming => check_patch_boundaries_streaming(&lines, e)?,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we return the "actual patch scope" from this match expression? or individual check_ methods? that way we won't need the matches!(mode, ParseMode::Streaming below again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread codex-rs/apply-patch/src/parser.rs Outdated

#[test]
fn test_parse_patch_streaming() {
assert_eq!(
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a stress test that takes in one large patch that has types of operations, slices it in 1 character increments and feeds to the streaming parser. We should see the ever increasing hunk count. (feel free to add stricter assertions if you'd like)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let active_path = hunks.last().map(Hunk::path).map(Path::to_path_buf);
let changes = convert_apply_patch_hunks_to_protocol(&hunks);
self.last_progress = Some(hunks);
Some(PatchApplyDeltaEvent {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a delta event right? is the latest state.

PatchApplyUpdatedEvent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread codex-rs/core/src/codex.rs Outdated
match event {
ResponseEvent::Created => {}
ResponseEvent::OutputItemDone(item) => {
if active_tool_argument_diff_consumer
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can clean this out unconditionally. you don't support parallel diff consumers anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread codex-rs/core/src/file_watcher_tests.rs Outdated
tx.add_changed_paths(&[path("b"), path("c")]).await;
// Force a fresh throttle window so slow CI scheduling after the first
// receive cannot consume it before the blocked receive starts.
throttled.next_allowed = Some(Instant::now() + Duration::from_secs(1));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread codex-rs/protocol/src/protocol.rs Outdated
PatchApplyBegin(PatchApplyBeginEvent),

/// Incremental model-generated structured changes for an `apply_patch` call.
PatchApplyDelta(PatchApplyDeltaEvent),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to expose this event through app-server for App to be able to consume

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming in the next PR

Comment thread codex-rs/protocol/src/protocol.rs Outdated
/// Structured file changes parsed from the model-generated patch input so far.
pub changes: HashMap<PathBuf, FileChange>,
/// File path currently being written, when known.
pub active_path: Option<PathBuf>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be calculated by the client based on changes[-1]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, will calculate on the client!

Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean!! Nice work!

Let's add a core integration test and expose through app-server API. And maybe rename the event because it's not truly a delta

@akshaynathan akshaynathan force-pushed the draft-stream-responses-apply-patch-events branch 3 times, most recently from ee0456a to 6effc01 Compare April 16, 2026 21:41
@akshaynathan akshaynathan force-pushed the draft-stream-responses-apply-patch-events branch from 1d185c2 to 4de8d61 Compare April 16, 2026 23:28
@akshaynathan akshaynathan enabled auto-merge (squash) April 17, 2026 00:07
@akshaynathan akshaynathan disabled auto-merge April 17, 2026 00:17
@akshaynathan akshaynathan merged commit 7995c66 into main Apr 17, 2026
25 checks passed
@akshaynathan akshaynathan deleted the draft-stream-responses-apply-patch-events branch April 17, 2026 01:12
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants