Align cmux Codex CLI hook setup with current event surface

Closed
AU
1mo ago
+1320-15

Closes #5962

Root cause

cmux's Codex CLI hook setup only installed Feed hooks for PreToolUse and
PermissionRequest. The current upstream Codex CLI hook event surface also
emits PostToolUse, PreCompact, PostCompact, SubagentStart, and
SubagentStop, so Feed missed tool completion, compaction lifecycle, and
subagent lifecycle telemetry. Several of those event names also weren't
registered in the Feed classifier, so they would have collapsed to a generic
PreToolUse instead of keeping their own name.

Fix

  • Setup persistence — extend the codex AgentHookDef.feedHookEvents to the
    full upstream telemetry set, and add SubagentStart/SubagentStop to the
    codex hook event name + label tables (cmux.swift) so the install path writes
    the hooks and computes their trust hashes.
  • Feed classification — register the new events in the codex semantic table
    and add FeedEventSemantic cases so each keeps its own wire hook_event_name
    (PreCompact, PostCompact, SubagentStart, SubagentStop, PostToolUse)
    rather than collapsing together. All stay non-actionable telemetry;
    PermissionRequest remains non-blocking so Codex's own approval reviewer keeps
    owning allow/deny.
  • App-boundary decoding — add the new HookEventName cases to
    WorkstreamEvent and handle them in the exhaustive WorkstreamStore /
    AgentChatSessionRegistry switches. Compaction + subagent-start telemetry
    materialize as non-actionable items that preserve their event name (mirrors the
    existing notification synthetic-tool-name precedent).
  • Compatibility — the internal source key stays "codex".

Tests

Two-commit red/green for the cleanly-testable portion (classifier + CLI install/
telemetry behavior, which compile against the old code and fail). The
enum-coupled Swift tests (WorkstreamEvent/WorkstreamStore) land with the fix
because they reference the new enum cases that must exist to compile.

  • FeedEventClassificationTests: new events keep distinct, non-actionable names.
  • WorkstreamEventTests: app-boundary decode of the new hook event names.
  • WorkstreamStoreTests: telemetry ingestion stays non-actionable + name-preserving.
  • tests/test_codex_feed_hooks.py: install persists all feed hooks; each new
    event stays distinct non-blocking telemetry end-to-end.

Tradeoff

The new subagent/compaction telemetry has no dedicated WorkstreamKind, so it
materializes as a toolResult carrying the event name as a synthetic tool name
(same pattern as the existing notification event) rather than expanding the
persisted WorkstreamKind enum.

Localization

No localized UI strings or web message catalogs were changed. The synthetic tool
names (PreCompact, etc.) are event identifiers, consistent with the existing
non-localized notification label. English markdown docs (docs/agent-hooks.md,
docs/feed.md) were updated; these are not message catalogs. The web docs
session-restore table uses a minified/generated message pipeline and its
high-level Codex summary is left for a separate docs pass.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Feed now installs the full codex CLI hook event surface so tool completion, compaction, and subagent telemetry stay distinct and non‑blocking. It also adds a per‑pane runaway‑memory guardrail with a banner and kill action to stop a leaking pane before the app gets OOM‑suspended. Closes #5962.

  • New Features

    • Per‑pane runaway‑memory guardrail (default on): warns with a sidebar badge and dismissible banner; threshold is configurable in Terminal settings (GB); “Kill Pane Process” sends SIGTERM then SIGKILL to the foreground process group (shell stays open), or closes the pane if no group exists.
  • Bug Fixes

    • Align codex Feed hooks with upstream CLI events: install PostToolUse, PreCompact, PostCompact, SubagentStart, SubagentStop; classify and decode them as distinct, non‑actionable telemetry across Feed and app boundaries (source key remains "codex").

Summary by CodeRabbit

Release Notes

  • New Features

    • Added memory guardrail that monitors per-pane memory usage, displays warning banners when thresholds are exceeded, and can terminate runaway processes.
    • Expanded Codex telemetry event tracking to capture additional lifecycle and interaction events for improved monitoring.
  • Settings

    • Added terminal guardrail options: enable/disable memory monitoring and configure the memory threshold limit (GB).
  • Documentation

    • Updated integration documentation to reflect expanded telemetry capabilities.