Repository navigation
Fix Codex hook trust hash for matcherless events (UserPromptSubmit/Stop) - #7110
Conversation
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
Codex drops the matcher from UserPromptSubmit and Stop hook identities before hashing (codex-rs matcher_pattern_for_event), but computeTrustedHash folded a present matcher into the identity for every event. A hooks.json entry carrying "matcher": "" on those events — a shape some third-party hook installers write — therefore hashed to a value Codex never stores. The system-trust mirror then missed, and removeStaleRuntimeHookTrustEntries deleted the trust entry Codex wrote after the user pressed t, re-prompting the hook review on every launch. Replicate the per-event normalization in computeTrustedHash so both sides agree for all events. Co-Authored-By: Claude Fable 5 <[email protected]>
b9d7135 to
2fc2684
Compare
|
Maintainer take-over. A maintainer has adopted this PR, independently verified it end-to-end, rebased it onto latest DescriptionCodex derives a hook's
Fix: replicate EvidenceReproduction — fix reverted (pre-PR behavior), the two new tests FAIL: Independent hash recompute (standalone script, does NOT import the module): The buggy Upstream ground truth (openai/codex match event_name {
PreToolUse | PermissionRequest | PostToolUse | SessionStart
| SubagentStart | SubagentStop | PreCompact | PostCompact => matcher,
UserPromptSubmit | Stop => None,
}The PR's mapping returns After — fix in place, rebased onto latest
ELI5Codex needs a "fingerprint" to remember you already approved a hook. For two kinds of hooks Codex leaves one detail out of the fingerprint, but Orca was including it — so Orca's fingerprint never matched Codex's, and Orca kept forgetting your approval and asking again every single launch. This makes Orca leave that detail out too, exactly like Codex, so the approval sticks. Trade-offsNo user-visible regression. The change only affects the identity hash for Maintainer take-over — not merging; leaving the final call to a human reviewer. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/codex/config-toml-trust.ts (1)
111-127: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider an explicit exhaustiveness guard.
The switch relies on the TS compiler flagging an added
CodexEventLabelmember via missing-return analysis, which only triggers whennoImplicitReturnsis enabled. An explicitneverguard enforces the "classify every new event" intent independent of tsconfig.♻️ Optional exhaustiveness guard
case 'session_start': return matcher + default: { + const _exhaustive: never = eventLabel + return _exhaustive + } } }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8e8a7fad-44ad-4a25-863e-db88a791d8ea
📥 Commits
Reviewing files that changed from the base of the PR and between b9d7135f407d46d36f24565187d906474ebff0b6 and 2fc2684.
📒 Files selected for processing (2)
src/main/codex/config-toml-trust.test.tssrc/main/codex/config-toml-trust.ts
Approved system hooks still match by signature (stablyai#7110), but the managed runtime trust entry is written with Codex's hooks/list currentHash instead of the system trusted_hash. Both Windows separator variants of the key are cleared before that write so slash/backslash copies cannot stay conflicted. Fixes stablyai#16428
…op) (stablyai#7110) Co-authored-by: Claude Fable 5 <[email protected]>
Approved system hooks still match by signature (stablyai#7110), but the managed runtime trust entry is written with Codex's hooks/list currentHash instead of the system trusted_hash. Both Windows separator variants of the key are cleared before that write so slash/backslash copies cannot stay conflicted. Fixes stablyai#16428
Approved system hooks still match by signature (stablyai#7110), but the managed runtime trust entry is written with Codex's hooks/list currentHash instead of the system trusted_hash. Both Windows separator variants of the key are cleared before that write so slash/backslash copies cannot stay conflicted. Fixes stablyai#16428
Summary
Fixes an endless hook re-trust loop for Codex user hooks on the
UserPromptSubmitandStopevents.Symptom. A user hook registered in
~/.codex/hooks.jsonwith"matcher": ""(a shape some third-party hook installers write on every event) can never be durably trusted inside Orca's managedCODEX_HOME. Every launch shows:Pressing
ttrusts it for that session, but the prompt is back on the next launch — even when the same hook is already trusted in system-level Codex.Root cause. Codex does not support matchers on
UserPromptSubmit/Stopand drops them from the hook trust identity before hashing (codex-rshooks/src/events/common.rs,matcher_pattern_for_event:UserPromptSubmit | Stop => None; the trust check indiscovery.rsis a strict hash equality). Orca'scomputeTrustedHashreproducescommand_hook_hashbut folds a present matcher into the identity for every event. For a definition carrying"matcher": ""on those two events, Orca therefore computes a hash Codex never stores, and two things go wrong on every launch:getTrustedSystemUserHookSignaturescompares its expected hash against the system config'strusted_hash(which Codex wrote matcher-omitted), misses, and refuses to mirror the system-level trust into the runtime home.removeStaleRuntimeHookTrustEntriesdeletes the runtime trust entry that Codex itself wrote when the user pressedt(matcher-omitted, so it never matches Orca's expected hash) → the review prompt reappears next launch, forever.The other events (
SessionStart/PreToolUse/PostToolUse) are unaffected because Codex keeps the matcher there, so both sides already agree — which is exactly the asymmetry observed in the wild.Verified by recomputing both hash variants against a real Codex 0.140
config.toml: the storeduser_prompt_submit/stophashes match only the matcher-omitted identity, while the other events' hashes match only the matcher-included identity.Fix. Replicate
matcher_pattern_for_eventinconfig-toml-trust.ts(matcherPatternForEvent) and apply it incomputeTrustedHash, so the matcher is dropped fromuser_prompt_submit/stopidentities exactly like Codex does. The switch is written exhaustively overCodexEventLabelto satisfylint:switch-exhaustivenessand to fail compilation if Codex adds an event label.Screenshots
No visual change.
Testing
pnpm lint— fails identically on unmodifiedmainin my environment (verify:localization-catalogwants a catalog sync unrelated to this PR, andtsgolintcrashes with a Go runtime panic). Scoped checks on the two changed files pass:oxlint src/main/codex/config-toml-trust.ts src/main/codex/config-toml-trust.test.tsis clean, andpnpm run lint:switch-exhaustivenesspasses across the repo.pnpm typecheck— passes.vitest run src/main/codex/config-toml-trust.test.ts src/main/codex/hook-service.test.ts— 106 passed / 7 skipped (and the trust suite alone after the final revision: 83 passed / 2 skipped).pnpm test/pnpm build— not runnable in my environment: the native-runtime preflight requires Node 24 prebuilds (node-pty) and I'm on Node 26; failures are all Electron/node-pty environment errors also present without this change. CI should exercise these.drops the matcher on user_prompt_submit/stop like matcher_pattern_for_event— equality ofmatcher: ''/matcher: 'anything'/absent for both events (this is the regression that caused the loop).REAL_APPROVED_HASHfixture.removeStaleRuntimeHookTrustEntries, Codex accepts them, and the re-trust prompt is gone across launches.AI Review Report
Review performed with Claude Code against the real Codex source as ground truth:
matcher_pattern_for_event(onlyUserPromptSubmit/Stopdrop the matcher;PreCompact/PostCompact/SessionStart/tool events keep it, including empty string). Confirmed the fix converges both failure paths (system-trust mirroring and stale-entry sweep) because both flow throughcomputeTrustedHash.computeTrustedHashis the single choke point for hash derivation;getTrustSignature(definition↔definition matching) intentionally untouched since both sides always come from the same hooks.json shapes. No behavior change for events where Codex keeps the matcher.Security Audit
Notes
"matcher": ""on events that can't have one; I've sent the complementary fix upstream there too (fix(hooks/codex): omit matcher key on UserPromptSubmit/Stop entries tma1-ai/tma1#63). Orca's fix stands on its own: any hooks.json in this shape, from any installer or hand-edit, currently loops.🤖 Generated with Claude Code