Skip to content

fix(codex): approve Orca's hook in managed Codex homes with Codex's own hash - #25742

Merged
Jinwoo-H merged 28 commits into
mainfrom
jinwoo/codex-hook-b-codex-derived-hash
Oct 6, 2026
Merged

Jinwoo-H merged 28 commits into
mainfrom
jinwoo/codex-hook-b-codex-derived-hash

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2584 $\color{#cf222e}{\Huge{\mathbf{−}}}$​292 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2292
Prod 30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1429 $\color{#cf222e}{\Huge{\mathbf{−}}}$​300 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1129

Stack: #25741 (config.toml safety, merged) → #25742 (Codex's hash for managed homes) → #25743 (~/.codex written only on change) → #25744 (cleanup). This is part 2 of 4; review and merge in order. Supersedes #24234.

ELI5

Codex asks you to review any hook it hasn't seen approved. Orca's status hook needs an approval written with Codex's own fingerprint ("hash") of the hook. In Orca-managed Codex homes (the shared one and each signed-in account's), Orca used to get that approval by running a background Codex session on every launch. Now Orca asks the installed Codex once per Codex version for that fingerprint, in a throwaway folder, remembers it, and writes the approval before the hook.

What Changed

  • Before: every Codex launch into a managed home ran a short codex app-server session to approve Orca's hook, which could take up to about 10 s. If that failed, Orca wrote a fingerprint it computed itself, which has drifted from Codex's before (Fix Codex hook trust hash for matcherless events (UserPromptSubmit/Stop) #7110).
  • After:
    • Until Codex answers (it's late, not found, or the app hasn't asked yet), each event keeps the approval the home already has, and any event without one gets Orca's own fingerprint, so every event has Orca's hook, as before. Status says "Approved by Orca; not yet confirmed by Codex". Codex's own fingerprint replaces it at the next launch.

    • A user hook's leftover approval no longer counts as Orca's. Approvals are filed by position. If a user removes a hook listed before Orca's, that hook's old approval ends up in Orca's position. Orca used to keep it, write nothing and report "installed", while Codex put Orca's hook up for review. Now Orca keeps an approval only if it holds Orca's own fingerprint or one Codex gave for Orca's hook; otherwise it writes Orca's fingerprint.

    • Asking once. At app start, once the shell PATH is loaded, Orca asks the installed Codex for its fingerprint of Orca's hook. It runs hooks/list in a throwaway Codex home and remembers the answer per Codex version. Launches in managed homes then write the approval first, then the hook, and start nothing. An unchanged launch reads two files.

    • Waiting. A Codex launch waits at most 3 s for an answer it doesn't have yet. Plain terminals don't wait. If the answer is late, Orca keeps the approvals the home already has.

    • When the hook is removed. Orca removes its hook from a managed home only when Codex itself answered that it can't be approved:

      • an old Codex without hooks/list (status says to update Codex);
      • a Codex that gives the hook different fingerprints depending on where it sits.

      "Codex not found" (for example, before the shell PATH is loaded) never removes a working hook.

    • Codex 0.128. It lists hooks without fingerprints and has no approval system, so Orca writes the hook with no approval.

    • Turning hooks off removes Orca's approvals written with any remembered Codex version's fingerprint. Orca keeps Codex's answer, so turning hooks back on starts nothing new.

    • orca agent hooks status now prints which file each status is about.

  • ~/.codex itself is unchanged in this PR. A follow-up moves it to the same approach. WSL keeps its current approval session.

Why

  • Codex is the only reliable source of its own fingerprint. Computing it in Orca broke before. Asking Codex in a throwaway home never touches the user's real files.
  • Cross-check against a future Codex change. In the same call, Orca lists its hook in three spots: the normal one, after another hook, and in a trusted project folder. If Codex fingerprints them differently, Orca checks once more, then refuses rather than writing an approval that would put the hook up for review.
  • Approval first, with a careful rollback. Writing the approval before the hook means Codex never sees an unapproved Orca hook. If the hook write fails, Orca takes back only the approvals it wrote, and only if nobody else changed them.
  • Only the app asks Codex. The CLI reads what the app saved, so orca commands never start Codex.

Linked Issue

Fixes #

Visual Proof

N/A: no UI change. The only visible difference is the hook status detail text.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated
    • Unit tests:
      • the cross-check, including a disagreement confirmed by a second run;
      • Codex 0.128 listings without a fingerprint, and Codex without hooks/list;
      • one question per binary at a time, held back after a failure;
      • a Windows-shim re-check once per process;
      • the CLI never asking;
      • "Codex not found" never removing a working hook;
      • a home approved in only some events keeping those and getting Orca's fingerprint in the rest;
      • a user hook's leftover approval at Orca's position replaced with Orca's fingerprint;
      • status reading the answer for the Codex on PATH, not one another binary gave;
      • approval-first with rollback that never overwrites another writer;
      • turning hooks off recognizing an older version's fingerprint;
      • the warm-up waiting for PATH;
      • only Codex launches waiting.
    • Real-Codex contract, run in CI on both pinned versions and latest, and locally on 0.160.1 with throwaway homes:
      • Codex lists Orca's hook in all three spots with the same fingerprint;
      • a managed home lists the hook as trusted;
      • codex exec runs it with no review;
      • a real TUI start shows no review screen, while a deliberately wrong fingerprint does show one.

Notes

  • Cross-platform: paths go through the existing helpers. Windows .cmd shims get their version re-checked once per app run.
  • SSH and WSL: unchanged. SSH still writes its own approval; WSL keeps its approval session.
  • Performance:
    • Launches into managed homes no longer start a Codex session.
    • At app start, a new Codex version costs one codex --version and one short hooks/list.
    • After that, each app run costs one --version.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one narrow gap worth a look.

Reviewed changes

  • Codex's own hash, asked from a throwaway home. New codex-hook-trust-derivation.ts asks one Codex binary for its hash of Orca's entry, cross-checking the same entry at group 0, after a dummy group, and from a trusted project folder; the answer is cached per binary fingerprint and version in the new codex-hook-trust-memo.ts (codex-hook-trust.json).
  • Approval-first write with rollback. New codex-hook-approval-first-write.ts writes the [hooks.state.*] approval before the hooks.json entry, and on failure takes back only its own approval (preserving a switched-off key verbatim, never another writer's). installCodexHooksExclusively is rewired to it, and the managed-home background grant session is removed.
  • Status rebuilt around the answer. codex-hook-status.ts now reads the home's files and compares Orca's entry/approval against Codex's last answer (installed / partial / not_installed plus a reason); the ledger-based status path is dropped.
  • Wait only where Codex is launched. launchesCodex threads through the PTY spawn env so only an Orca-launched Codex waits up to 3 s for the answer; plain terminals and structured launches go ahead.
  • App-start warm-up and CI contract. The lookup starts after shell-PATH hydration in main-process-ready-runtime.ts; CI adds a pinned-and-latest codex-hook-file-entry-binary-contract gate, and the CLI status line now names the file each agent reports on.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/codex-hook-b-codex-derived-hash branch from 256e90a to 9d5efd6 Compare October 6, 2026 02:45
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/codex-hook-a-config-toml-safety branch from 3c8e2eb to 76f82d4 Compare October 6, 2026 04:11
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/codex-hook-b-codex-derived-hash branch from 9d5efd6 to 668ae79 Compare October 6, 2026 04:11
…own hash, written first

Managed homes (the shared mirror and per-account homes) no longer run a
background approval session. Status reads the home's files against Codex's
answer, and turning hooks off recognizes every saved version's hashes.
…p their background approval

The previous commit carried only the managed resume's wait; this one holds
the managed install it relies on. Managed homes (the shared mirror and
per-account homes) write Codex's hash before the entry, fall back to their
own approvals when the answer is late, and strip Orca's entry only when
Codex itself answered with nothing to approve. Status reads the home's files
against Codex's answer, and turning hooks off recognizes every saved
version's hashes.
…rca's own hash, as main did

A late, temporary or missing answer with no earlier approval in the home now
writes main's self-computed approval instead of leaving the hook out. Codex's
answer replaces it at the next install, a definitive answer (no hooks/list,
a refused cross-check, 0.128) never uses it, and status says the approval
is Orca's until Codex confirms it.
Until Codex answers, a managed home kept only the events it had already
approved and dropped Orca's entry from the rest. Each event now keeps the
home's approval, else gets Orca's own hash, as main wrote every event. One
reader of the approval at Orca's entry serves the stopgap and status.
…disk-only memo

- One answer type with a kind (hashes, refused, pending) replaces two types
  and the three-field decoding at each caller.
- The lookup keeps one in-process answer per binary path, replacing the
  process memo, the global latest answer and the transient-failure map;
  status now reads the answer for the codex on PATH, not the last one asked.
- The memo file keeps Codex's refusals per version, like its hashes.
- Derivation takes the version it is given; one 30 s version-probe timeout.
- The launch wait reuses withTimeout, and launch prep passes launchesCodex
  down instead of a wait in milliseconds.
- Turning hooks off no longer forgets Codex's answer.
- Tests mock the derivation instead of a test-only resolver in production.
…tatus checks the binary's fingerprint

Also names the lookup functions for the answer they return.
@Jinwoo-H
Jinwoo-H changed the base branch from jinwoo/codex-hook-a-config-toml-safety to main October 6, 2026 07:08
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/codex-hook-b-codex-derived-hash branch from 9a95263 to 4c50d0e Compare October 6, 2026 07:08
@Jinwoo-H
Jinwoo-H requested a review from brennanb2025 as a code owner October 6, 2026 07:08
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf4280d4-2124-4c99-bd07-c7d78b26c5f6
📥 Commits

Reviewing files that changed from the base of the PR and between 1b33f61 and 14e2a35.

📒 Files selected for processing (25)
  • src/main/codex/codex-hook-approval-first-write.test.ts
  • src/main/codex/codex-hook-approval-first-write.ts
  • src/main/codex/codex-hook-hash-lookup.ts
  • src/main/codex/codex-hook-local-maintenance.ts
  • src/main/codex/codex-hook-orca-approvals.ts
  • src/main/codex/codex-hook-service-implementation.ts
  • src/main/codex/codex-hook-status.ts
  • src/main/codex/codex-hook-trust-derivation.test.ts
  • src/main/codex/codex-hook-trust-derivation.ts
  • src/main/codex/codex-hook-trust-failure-memo.test.ts
  • src/main/codex/codex-hook-trust-memo.test.ts
  • src/main/codex/codex-hook-trust-memo.ts
  • src/main/codex/codex-managed-trust-reconciliation.ts
  • src/main/codex/codex-real-home-shared-entry.test.ts
  • src/main/codex/config-toml-hook-trust-edit.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service-concurrent-launch-install.test.ts
  • src/main/codex/hook-service-legacy-cleanup.test.ts
  • src/main/codex/hook-service-managed-codex-hashes.test.ts
  • src/main/codex/hook-service-runtime-trust-repair.test.ts
  • src/main/codex/hook-service-windows-key-spellings.test.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/startup/codex-launch-per-agent-hook-opt-out.test.ts
  • src/main/startup/codex-launch-preparation.ts
  • src/main/startup/codex-session-resume-launch.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Codex hook installation now derives and caches hashes from Codex hook listings. Managed trust approvals are written before hook entries and restored when eligible writes fail. Status reads use Codex answers and managed hook slots. Launch preparation passes Codex-specific context through spawn and startup paths. The pull request adds unit, integration, binary-contract, CI, and CLI status coverage.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 14e2a

No identified issue currently prevents merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 126 functions across 51 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: approving Orca’s managed Codex hook with Codex’s own hash.
Description check ✅ Passed The description covers the user-facing change, rationale, implementation, testing, visual proof, and platform considerations. The “Fixes #” field is blank; the template requires an issue link for outs…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68518ee0-cb0b-4903-8e29-6b75a32b1043
📥 Commits

Reviewing files that changed from the base of the PR and between 29e6696 and 4c50d0e.

📒 Files selected for processing (51)
  • .github/workflows/pr.yml
  • config/scripts/pr-code-change-scope.mjs
  • config/scripts/pr-code-change-scope.test.mjs
  • config/tsconfig.cli.json
  • src/cli/handlers/agent-hooks.test.ts
  • src/cli/handlers/agent-hooks.ts
  • src/main/agent-hooks/local-agent-cli-presence.ts
  • src/main/agent-hooks/managed-hook-script-refresh.test.ts
  • src/main/agent-hooks/managed-hook-stdin-lifecycle.test.ts
  • src/main/agent-hooks/windows-hook-post-interpreter.test.ts
  • src/main/codex-accounts/runtime-home-service-per-account-migration.test.ts
  • src/main/codex/codex-app-server-client.ts
  • src/main/codex/codex-hook-approval-first-write.test.ts
  • src/main/codex/codex-hook-approval-first-write.ts
  • src/main/codex/codex-hook-definition.ts
  • src/main/codex/codex-hook-file-entry-binary-contract.test.ts
  • src/main/codex/codex-hook-hash-lookup.test.ts
  • src/main/codex/codex-hook-hash-lookup.ts
  • src/main/codex/codex-hook-local-install.ts
  • src/main/codex/codex-hook-local-maintenance.ts
  • src/main/codex/codex-hook-orca-approvals.ts
  • src/main/codex/codex-hook-service-implementation.ts
  • src/main/codex/codex-hook-status.ts
  • src/main/codex/codex-hook-trust-cleanup.ts
  • src/main/codex/codex-hook-trust-derivation.test-fixture.ts
  • src/main/codex/codex-hook-trust-derivation.test.ts
  • src/main/codex/codex-hook-trust-derivation.ts
  • src/main/codex/codex-hook-trust-memo.test.ts
  • src/main/codex/codex-hook-trust-memo.ts
  • src/main/codex/codex-hook-user-mirroring.ts
  • src/main/codex/codex-managed-trust-reconciliation.ts
  • src/main/codex/codex-real-home-shared-entry.test.ts
  • src/main/codex/codex-trust-grant-host.ts
  • src/main/codex/config-toml-hook-trust-edit.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service-concurrent-launch-install.test.ts
  • src/main/codex/hook-service-managed-codex-hashes.test.ts
  • src/main/codex/hook-service-runtime-trust-repair.test.ts
  • src/main/codex/hook-service-test-harness.ts
  • src/main/codex/hook-service-trust-grant.test.ts
  • src/main/codex/hook-service-wsl-runtime.test.ts
  • src/main/ipc/pty-spawn-codex-home-unavailable.test.ts
  • src/main/ipc/pty/host-env/types.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts
  • src/main/ipc/pty/runtime/spawn-preflight.ts
  • src/main/startup/codex-hook-hash-warmup-wiring.test.ts
  • src/main/startup/codex-launch-during-real-home-grant.test.ts
  • src/main/startup/codex-launch-per-agent-hook-opt-out.test.ts
  • src/main/startup/codex-launch-preparation.ts
  • src/main/startup/codex-session-resume-launch.ts
  • src/main/startup/main-process-ready-runtime.ts
💤 Files with no reviewable changes (1)
  • src/main/codex/codex-trust-grant-host.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread config/scripts/pr-code-change-scope.mjs Resolved
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.

1 participant