NeMo-Relay icon indicating copy to clipboard operation
NeMo-Relay copied to clipboard

[Enhancement]: Install Codex's SessionEnd and Interrupt hooks

Open Somay-kousis opened this issue 3 weeks ago • 1 comments

Affected area

CLI

Problem or opportunity

Codex now has SessionEnd (openai/codex#33895, merged 07-17) and Interrupt (openai/codex#40511, merged 08-25) hook events. Codex 0.154 lists both in its hook config. Relay installs neither:

  • The generated Codex hook set (crates/cli/src/agents/codex/mod.rs) has 9 events, without SessionEnd or Interrupt.
  • The Codex adapter already maps sessionEnd to the agent end (crates/cli/src/agents/codex/adapter.rs:26), so half of it is there, but the hook is never installed.
  • docs/nemo-relay-cli/codex.mdx:356 says "The Codex plugin schema does not expose SessionEnd", and the comment at crates/cli/src/events/mod.rs:77 says Codex has no reliable SessionEnd. Both are out of date.

Real run, Codex 0.154 app-server driven over JSON-RPC with a mock provider and both hooks installed: turn/interrupt ran Interrupt with the session and turn ids, and thread/archive ran SessionEnd with the transcript path. The interrupted turn sent no Stop.

So today:

  • An interrupted Codex turn sends no Stop, and Relay installs no hook that would see it, so its codex-task stays open until the idle timeout and closes as unfinished, not as interrupted.
  • The ATIF file is finalized when the task closes or at idle timeout, not when the session actually ends.

Proposed enhancement

  1. Add SessionEnd and Interrupt to the generated Codex hooks.
  2. Map Interrupt to a turn end with an interrupted status, the same way Claude's StopFailure becomes a failed turn end (crates/cli/src/agents/claude/adapter.rs:51).
  3. Let SessionEnd finalize the task and its ATIF, and update the docs and the events/mod.rs comment.

Runtime contract and binding impact

CLI hook generation and the Codex adapter only. The hook digests and trust-hash tests change with the event list. No binding changes.

One catch I hit: Codex gives these two events a 1-second default timeout (3-second cap), while the transparent launch hashes every generated hook with a 600-second default (crates/cli/src/agents/codex/launch.rs:311). With that hash Codex reports both hooks as modified and skips them silently. The trust hash has to use the per-event timeout.

Alternatives considered

  • Keep relying on Stop and the idle timeout. It works, but interrupted turns and session ends show up late and unlabeled.
  • Install only Interrupt. SessionEnd mostly changes when ATIF is written, so it could wait.

Acceptance criteria

  • The generated Codex hook config includes both events, and the trust tests cover them.
  • An interrupted Codex turn closes as interrupted without waiting for the idle timeout.
  • Ending a Codex session finalizes its ATIF.
  • Docs no longer say Codex has no SessionEnd.

Not checked: the interactive TUI, since I drove the app-server instead, and codex exec, where neither hook fired in my runs.

Two questions: should these be gated on a minimum Codex version above today's 0.143, and should Interrupt show as an error like StopFailure or as its own status?

I'd like to work on this. Can you assign it to me?

Somay-kousis avatar Nov 10 '26 15:11 Somay-kousis

  1. Should these be gated on a minimum Codex version above today's 0.143

Yes. We can increase the floor

  1. should Interrupt show as an error like StopFailure or as its own status?

I think this is fine (showing as an error).

willkill07 avatar Nov 10 '26 16:11 willkill07