hooks: emit Bash PostToolUse when exec_command completes via write_stdin#18888
Merged
eternal-openai merged 5 commits intomainfrom Apr 23, 2026
Merged
hooks: emit Bash PostToolUse when exec_command completes via write_stdin#18888eternal-openai merged 5 commits intomainfrom
eternal-openai merged 5 commits intomainfrom
Conversation
# Conflicts: # codex-rs/core/src/tools/handlers/unified_exec.rs # codex-rs/core/src/tools/registry.rs # codex-rs/core/src/unified_exec/mod.rs
abhinav-oai
reviewed
Apr 22, 2026
abhinav-oai
reviewed
Apr 22, 2026
|
|
||
| let tool_response = result.post_tool_use_response(call_id, payload)?; | ||
| let command = result.hook_command.clone()?; | ||
| let tool_use_id = if result.event_call_id.is_empty() { |
Collaborator
There was a problem hiding this comment.
[question] when would this be empty?
and isn't it the same as call_id?
Contributor
Author
There was a problem hiding this comment.
Yeah, good ask - I think you're right that this should never happen. It’s only there as a defensive fallback because ExecCommandToolOutput has one synthetic constructor path (intercept_apply_patch) that doesn’t participate in the normal unified-exec lifecycle and leaves event_call_id empty. That path also never produces a PostToolUse payload, but I'll leave it in just in case
sayan-oai
approved these changes
Apr 23, 2026
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #16246.
Why
exec_commandalready emitsPreToolUse, but long-running unified exec commands that finish on a laterwrite_stdinpoll could miss the matchingPostToolUse. That left the Bash hook lifecycle inconsistent, broke expectations aroundtool_use_idandtool_input.command, and meantPostToolUseblock/replacement feedback could fail to replace the final session output before it reached model context.This keeps the fix scoped to the
exec_command/write_stdinlifecycle. Broader non-Bash hook expansion is still out of scope here and remains tracked separately in #16732.What changed
PostToolUsePayloadwhile handlers still have access to their concrete output type, and carrytool_use_idthrough that payload.exec_commandstring through unified exec state (ExecCommandRequest,ProcessEntry,PreparedProcessHandles, andExecCommandToolOutput) viahook_command, and remove the now-unusedsession_commandoutput metadata.PostToolUsefor long-runningexec_commandsessions when a laterwrite_stdinpoll observes final completion, using the originalexec_commandcall id and hook-facing command.exec_commandbehavior aligned with the same payload construction, including interactive completions that return a final result directly.PostToolUseblock/replacement feedback before the finalwrite_stdincompletion output is sent back to the model.write_stdinitself out ofPreToolUsematching so it continues to act as transport/polling for the original Bash tool call.BashandEdit|Write, while still treating patterns with regex characters (for examplemcp__.*) as regexes.PostToolUsereplaces the finalwrite_stdinoutput in model context.Testing
cargo test -p codex-hookscargo test -p codex-core post_tool_use_payloadcargo test -p codex-core post_tool_use_blocks_when_exec_session_completes_via_write_stdin