Skip to content

fix(codex): stop 'hooks pending review' from reappearing on every Orca-launched Codex session - #7896

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/codex-hook-config
Jul 9, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/codex-hook-config

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

User report: "Whenever I launch Codex in Orca, I receive a notification that there are hooks pending review; even after I acknowledge them, the notification reappears upon subsequent launches."

Root cause (reproduced in a test before fixing): Orca launches Codex with a managed runtime CODEX_HOME and mirrors the user's ~/.codex/hooks.json hooks into it. Trust for those mirrored hooks is only carried over when it already exists in ~/.codex/config.toml. When a personal hook was never approved outside Orca:

  1. The mirrored hook arrives untrusted → Codex shows hooks pending review.
  2. The user approves via /hooks → Codex writes the trust entry into the runtime config.toml.
  3. On the next launch, install()'s removeStaleRuntimeHookTrustEntries deletes every runtime trust entry not in its expected set — the user's approval isn't in that set → wiped. Prompt returns. Forever.

This only hits users with personal hooks in ~/.codex/hooks.json that lack system-side trust, which is why most users never see it.

Fix: write-back promotion (~/.codex stays the single source of truth)

  • hook-trust-promotion.ts — before install/refresh rewrites the runtime files, approvals Codex wrote into the runtime config.toml are translated back to the user's ~/.codex/config.toml, keyed to their own hooks.json (mapped by hook-content signature, so the prepended managed hook and dedupe-collapsed duplicates are handled; one approval promotes to every identical system entry). The normal mirror path then picks the trust up on the same launch and it survives stale cleanup — permanently, including for terminal Codex sessions.
  • Provenance snapshot (.orca-hook-trust-provenance.json in the runtime home) — records what Orca last wrote, so a fresh Codex approval is distinguishable from an Orca-mirrored entry whose system backing the user has since revoked. Revocation in ~/.codex/config.toml still wins and is not resurrected. When no snapshot exists yet (first launch after upgrading to this build, or a corrupted snapshot), promotion sits the launch out entirely — a stale mirror of since-revoked trust is indistinguishable from an approval, and resurrecting revoked trust is the one failure we must never have. Install writes the first snapshot; promotion starts on the next launch.
  • Verbatim hash mirroring — key-matched system user-hook trust hashes are now carried verbatim instead of being dropped unless they equal Orca's recomputation. Codex is the authority on its own hash algorithm; this makes user-hook trust immune to future hash-algorithm drift (the Fix Codex hook trust hash for matcherless events (UserPromptSubmit/Stop) #7110 class of bug). Orca's hash reproduction remains only for its own managed hooks.
  • Never touches ~/.codex for Orca's managed hooks — promotion explicitly excludes managed commands; the isolation that the runtime CODEX_HOME exists for is preserved.
  • codex-hook-identity.ts extracts the shared event-label maps / content signature / trust-entry builder out of hook-service.ts (which shrank) to avoid an import cycle.

Verification

  • 14 tests covering: the exact reported loop (approval survives relaunches and lands in ~/.codex/config.toml; steady-state launches rewrite nothing), revocation not resurrected (including the two post-upgrade resurrection sequences below), in-Orca /hooks disable propagating back to the system config, Codex hash-drift survival, dedupe fan-out, hook-deleted-from-system skip, the hooks-disabled refresh path, managed-hook exclusion, and upgrade-path no-op guarantees (first launch with no provenance leaves ~/.codex byte-identical).
  • All codex/codex-accounts/agent-hooks suites green; pnpm typecheck (node+cli+web), lint, and the max-lines ratchet green.
  • Live-validated against codex-cli 0.143.0 in a throwaway CODEX_HOME: a SessionStart hook trusted with Orca's computed hash executed; the same hook with a wrong hash was suppressed — confirming both the hash reproduction and the trust gate this design relies on.
  • Three independent adversarial review passes (correctness/root-cause, environment matrix, contracts/hostile inputs). The correctness pass found one High issue — the missing-provenance branch could resurrect trust a user had revoked/disabled in ~/.codex between their last old-build launch and the upgrade — fixed in 8e1e9c8 with both sequences pinned by regression tests (mutation-checked: the tests fail without the guard). Environment pass (Windows keys, WSL separation, SSH remote, CLI-offline compile, concurrent writers, macOS realpath) came back clean.

Upgrade behavior

First launch on this build never writes to ~/.codex (promotion is disabled until the first provenance snapshot exists). A user currently stuck in the loop approves one final time; that approval is promoted on the following launch and the prompt never returns.

Crash-triage summary

Description

Fixes the uncaptured macOS report submitted at 2026-07-09T03:39:48Z: an Orca-launched Codex session repeatedly showed hooks pending review after the user approved the hook, with Codex running under Orca’s managed CODEX_HOME. Orca now promotes a user’s approval from the managed runtime config back to the matching personal hook in ~/.codex/config.toml, so the next managed-home refresh preserves it.

Clear, undeniable fix evidence

The regression test keeps an in-Orca approval of a user hook across launches and promotes it to ~/.codex encodes the reported loop at the real CodexHookService.install() seam:

  1. A personal Stop hook starts without trust, so the managed runtime has no trust entry (the pending-review state).
  2. The fixture simulates Codex writing the user’s approval into the managed runtime config.
  3. A second install simulates the next Orca-launched session.
  4. The test proves the exact approval hash remains in the runtime config, is promoted to the user’s real config, and a third launch rewrites neither file.

Current-main verification: pnpm exec vitest run --config config/vitest.config.ts src/main/codex/hook-trust-promotion.test.ts — 12/12 passed.

ELI5

Orca gives Codex a separate “home folder.” The user approved a hook inside that folder, but Orca rebuilt the folder on the next launch and threw the approval away. Orca now copies approvals for the user’s own hooks back to their normal Codex settings before rebuilding, so Codex remembers the answer.

Trade-offs

  • The first launch after upgrading intentionally does not promote old managed-home trust because Orca cannot distinguish a fresh approval from trust the user revoked elsewhere. A user already stuck in the loop may need to approve once more; the following launch promotes and preserves it.
  • Approved or disabled personal-hook state is written back to ~/.codex/config.toml. This is the intended persistence point, but it is a new write to the user’s normal Codex config.
  • Orca-managed hooks are explicitly excluded, and a revocation in ~/.codex/config.toml remains authoritative.

…eappearing as pending review

Approvals the user makes inside Orca-launched Codex are written by Codex
into the runtime CODEX_HOME's config.toml. install() treated any runtime
trust entry it didn't expect as stale and deleted it on the next launch,
so users with personal hooks in ~/.codex/hooks.json (never approved
outside Orca) re-approved the same hooks on every single launch.

- hook-trust-promotion.ts: before install/refresh rewrites runtime files,
  translate externally-written runtime approvals back to the user's
  ~/.codex/config.toml keyed to their own hooks.json (content-signature
  mapping; managed status hooks are never promoted). A provenance
  snapshot of what Orca last wrote distinguishes fresh approvals from
  revoked mirrors, so system-side revocation still wins.
- Mirror key-matched system user-hook trust hashes verbatim instead of
  requiring them to equal our recomputation, so user-hook trust survives
  Codex hash-algorithm drift (#7110-class bugs).
- Extract shared codex-hook-identity.ts (event labels, signature, entry
  builder) to avoid a promotion<->hook-service import cycle.

Verified live against codex-cli 0.143.0: a hook trusted with our
computed hash executes; a wrong hash is suppressed.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a shared Codex hook identity module for event labels, managed script names, trust-entry construction, and trust signatures. It extends trust config handling to support explicit trusted hashes and enabled states. A new promotion module snapshots runtime trust provenance and promotes matching runtime approvals into system trust config. Hook-service is updated to use the shared Codex utilities and to call promotion and snapshot steps during install and refresh flows. A Vitest suite and tsconfig include list are updated to cover the new behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description doesn't follow the required template and omits Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR description to the required template and add each missing section: Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: preventing the hooks-review notification from reappearing in Orca-launched Codex sessions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…pshot

On the first launch after upgrading (no snapshot yet), a mirrored copy of
system trust that the user has since revoked or disabled in ~/.codex is
indistinguishable from an in-Orca approval. Promoting it would resurrect
revoked trust into the user's real config. Skip promotion for that launch;
install() writes the first snapshot and promotion starts on the next one.
Found by adversarial review; regression tests cover both sequences
(revoked block resurrected, disabled hook flipped back to enabled).

Co-authored-by: Orca <[email protected]>
@Jinwoo-H

Jinwoo-H commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Live end-to-end verification (real codex-cli 0.143.0 TUI driving the real install() from this branch in a sandboxed $HOME; nothing simulated):

  1. Launch 1: managed hooks pre-trusted (zero in review); the untrusted personal hook produced the real banner — "Hooks need review — 1 hook is new or changed."
  2. Approved via the real /hooks flow. Codex 0.143 wrote [hooks.state."…/hooks.json:stop:1:0"] with trusted_hash only (no enabled field) plus a bare [hooks.state] parent header — both shapes handled by the parser, and computeTrustedHash reproduced Codex's real hash byte-for-byte.
  3. Launch 2 (the old code's failure point): approval survived, was promoted into the system ~/.codex/config.toml at the system key with the identical hash, and the TUI relaunched with no banner.
  4. Launch 3: runtime config, system config, and provenance all byte-identical — no churn.
  5. Trusted Stop hook actually executed after a completed turn.
  6. Revocation: deleting the system trust block removed the runtime entry, brought the banner back, and was not resurrected on subsequent installs.
  7. Missing-provenance guard (8e1e9c8): with provenance deleted and system trust revoked, nothing was promoted.

The reported loop is reproduced-then-fixed against the real binary, including the visible notification lifecycle.

@Jinwoo-H
Jinwoo-H merged commit 2c20089 into main Jul 9, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/codex-hook-config branch July 9, 2026 06:05
brennanb2025 pushed a commit that referenced this pull request Jul 9, 2026
…ve-override guard, gate test path

- Restore per-launch Codex hook upkeep on the interactive PTY launch path via a
  shared maintainCodexLaunchHooks() helper (fire-and-forget from the sync spawn
  path, awaited from commit-message prep). This keeps #7896's runtime /hooks
  approval promotion + user-hook refresh running on every Codex launch, which the
  presence-gating refactor had dropped from the interactive path. Enabled installs
  stay presence-gated.
- Relay CLI presence: report 'unknown' for a relative (non-absolute, non-home)
  override path instead of probing it against the relay process CWD, mirroring the
  local detector's guard. Adds a regression test.
- Repoint the agent-hooks.cli-presence-gating reliability gate at the split-out
  ssh-relay-session-agent-hook-presence.test.ts where those assertions now live.
brennanb2025 pushed a commit that referenced this pull request Jul 10, 2026
…ller loop, honest Windows-remote presence

- Launch-prep no longer drops #7896 approval promotion when the presence
  gate skips the managed install (false-'missing' PATH probe or relative
  command override). Promotion now runs on every Codex launch; only the
  managed-config write stays presence-gated. Guarded by a new predicate test.
- Remove the now-dead duplicated installer loop + errorStatus from
  install-telemetry (production uses the CLI-safe copy in controls); keep the
  electron-coupled recorder there and test it directly. Add fail-open loop
  coverage to controls where the loop actually lives.
- Relay Windows presence reports 'unknown' (honest) instead of a false
  'missing'; drop the unused 'unsupported_remote_platform' skip reason.
brennanb2025 pushed a commit that referenced this pull request Jul 10, 2026
Reconcile presence-gated Codex launch prep with main's #7969 WSL runtime-home
status-hook install:
- WSL runtime-home installs (installForRuntimeHome/refreshRuntimeUserHooksForRuntimeHome)
  run unconditionally and synchronously — never presence-gated, since the
  Windows-side PATH probe cannot see a codex CLI living inside the WSL distro
  (gating it would regress #7969).
- Non-WSL launches keep the presence gate plus the always-run #7896 approval
  promotion from this branch's review fixes.
- Keep both new tsconfig.cli entries and the added imports (getDefaultWslDistro,
  codexLaunchNeedsDirectApprovalPromotion).
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants