[codex] Move hook request plumbing into hook runtime#23388
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55827a3141
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…top-hook # Conflicts: # codex-rs/core/src/session/turn.rs
| let hooks = sess.hooks(); | ||
| emit_hook_started_events(sess, turn_context, hooks.preview_stop(&request)).await; | ||
| let mut outcome = hooks.run_stop(request).await; | ||
| emit_hook_completed_events(sess, turn_context, std::mem::take(&mut outcome.hook_events)).await; |
There was a problem hiding this comment.
There is something strange here... if I get it correctly. run_stop_hooks emit the internal stuff, drain (with the take) and then return StopOutcome type (with hook_events now empty). So things are partially consumed but, from what I read, this wasn't doing that before
There was a problem hiding this comment.
Yeah, codex overcooked a bit trying to avoid a clone.
There was a problem hiding this comment.
Don't think it hurts anything.
Why
run_turnwas still hand-building hook payloads and lifecycle events for a couple of hook paths. Most hook call sites already delegate request construction and event emission tohook_runtime, which keeps turn orchestration focused on model-flow decisions rather than hook plumbing.This also keeps the legacy
after_agentmessage extraction next to the legacy hook dispatch instead of leaving response-item walking inrun_turn.What changed
run_stop_hooksinhook_runtimeto buildStopRequest, emit preview start events, run the hook, and emit completion events.run_legacy_after_agent_hookinhook_runtimeto build and dispatch the legacyAfterAgenthook payload, including extracting input messages from response items.run_turnto call the hook runtime helpers and keep only the resulting continuation/block/stop decisions inline.Validation
cargo test -p codex-core hook_runtime