Skip to content

fix(codex): Orca writes its Codex status hook once, approved by Codex, so every launch gets status and no review screen - #24234

Closed
brennanb2025 wants to merge 70 commits into
mainfrom
brennanb2025/codex-hooks-write-once
Closed

brennanb2025 wants to merge 70 commits into
mainfrom
brennanb2025/codex-hooks-write-once

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2924 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3109 $\color{#cf222e}{\Huge{\mathbf{−}}}$​185
Prod 46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2154 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1031 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1123

ELI5

Orca shows whether Codex is working, waiting or done by giving Codex a small "status hook". Until now, Orca re-added that hook to your Codex settings folder (~/.codex) on every Codex launch, then asked Codex to approve it in the background. Until the approval landed, Codex could stop on its "Hooks need review" screen for Orca's hook, inside Orca or outside it.

Now Orca writes its hook and Codex's own approval of it once: the approval first, then the hook. After that it touches ~/.codex only when something actually changed. Status works however you start Codex in an Orca pane, and Codex never asks you to review Orca's hook.

How it works (not a shim)

Orca doesn't wrap, replace or rename the codex command, and it doesn't change how any terminal starts Codex. It writes one entry into Codex's own hooks file (~/.codex/hooks.json), the same file Codex reads every time it starts, however it was started. The entry only does anything when Codex runs inside an Orca terminal (it checks for environment variables only Orca sets), so Codex run anywhere else ignores it. Orca also writes Codex's own approval for that entry into ~/.codex/config.toml, so Codex never asks you to review it. Orca rewrites these files only when something changes.

Main's existing codex shell function, which adds --no-daemon (from #23900, widened to more shells by #23933), is unchanged by this PR.

What Changed

The problem. #23552 stopped terminal launches from stripping your hooks. It still wrote Orca's entry into ~/.codex/hooks.json on every Codex launch and resume, and approved it with a background Codex session that took up to 30 s. Its own description listed three races where the review screen could still appear:

  • a resume after a failed approval;
  • a Codex update that changes the approval;
  • hooks turned off during an approval.
    New panes also quietly switched to an Orca-managed Codex folder while the approval was pending, and resumes waited for it.

What changes for you:

  • Orca no longer rewrites ~/.codex on every launch. It writes only when something changed: first enable, a Codex update that changes the approval, an edit of yours that moved Orca's entry, or turning status hooks on or off. Otherwise it writes nothing and starts no Codex process.
  • Codex never shows "Hooks need review" for Orca's hook. Orca writes Codex's own approval before the hook, so the hook never exists unapproved because of Orca.
  • Status works however you start Codex in an Orca pane (table below).
  • If you switch Orca's hook off in Codex's own /hooks screen, Orca turns it back on at its next check (the next terminal you open or Codex launch Orca starts). Orca's status-hooks setting is the one off switch.
  • Turning status hooks off removes Orca's hook and its approvals, and keeps your own hooks' approvals, as before.

Which Codex launches get status

How you start Codex Status?
codex typed in an Orca terminal (bash, zsh, fish, PowerShell, cmd.exe, Git Bash) Yes
An alias or function that runs codex Yes
codex by full path, command codex, npx @openai/codex, a company launcher that ends in Codex Yes
A script, Makefile, or another agent's shell inside an Orca terminal Yes
tmux or screen started inside an Orca terminal Yes, shown on the terminal that started the tmux server (same as before)
Codex that Orca starts (new terminal, resume, restored terminals) Yes
Codex chats and commit messages Yes, from Codex's own event stream; no hook needed
WSL and SSH terminals Yes, through their existing installers (see Differences)
Codex outside Orca Orca's hook does nothing there (it needs an Orca terminal), and it's approved, so no review screen
Codex older than 0.129 (it can't approve hooks) No status; orca agent hooks status says to update Codex

Mechanism:

  • The approval comes from Codex. Orca asks the installed Codex for its hash of Orca's hook. It does that with codex app-server and hooks/list in a throwaway Codex folder, and remembers the answer per Codex binary and version. Orca writes that hash, plus enabled = true, into ~/.codex/config.toml before it adds the hook to ~/.codex/hooks.json. If the hook write fails, it takes back only its own approvals.
  • One check keeps it current. reconcileCodexHooks runs at app start, when you turn status hooks on or off, when a terminal opens, and before Orca launches Codex. It never throws, and it reads your setting when it runs. When nothing changed, it reads two files and stops.
  • After a write, Codex confirms it. One read-only hooks/list against ~/.codex checks that Codex trusts Orca's hook. It's skipped while Codex is rebuilding its session index.
    • If Codex reports a different hash, Orca removes its hook for that Codex and says why.
    • If the approval was lost to a concurrent edit, Orca rewrites it once.
  • If Orca can't approve its hook in ~/.codex, new terminals use Orca's managed Codex folder instead, as before, and status says why. That covers a hooks.json Orca can't read, approvals you wrote in a form Orca can't add to safely, or Codex refusing the approval. The folder is chosen afresh each time, from the current state.
  • Orca never breaks your config.toml. Every approval write is refused if the file would no longer load.
  • Managed Codex accounts get the same Codex-derived approval when a terminal opens.

Why

Main's per-launch write and background approval are what left room for the review screen and the churn. A hook file written once and kept up to date covers every way Codex starts, which a per-launch command-line flag or a codex wrapper can't.

Alternatives considered:

Differences from the common pattern

The common pattern for a Codex terminal writes a durable status hook into the Codex folder, gated on the host's terminal environment so it does nothing elsewhere. It then either lets Codex show its review screen outside the host's own launcher, or passes Codex's hook-trust bypass flag. This PR follows the durable, environment-gated hook.

  • Orca writes Codex's own approval for its hook, and never uses the bypass flag. Intended. Your rule is never a review screen for Orca's hook. The bypass would also run every repository's unreviewed project hooks.
  • Orca's entry goes last in each event in ~/.codex/hooks.json (first in Orca-managed folders, which Orca rewrites on every launch). Intended. Codex keys approvals by position, so a hook you add later can't shift Orca's.
  • After a hook you insert ahead of Orca's, or a Codex update that changes the hash, Codex can show the review screen in a terminal that's already open, until Orca's next check: the next terminal you open, or the next Codex Orca launches. The same goes for a Codex started outside Orca. Intended. Orca repairs it at that next check. Codex's hash has been identical from 0.133 to 0.159, and CI checks the latest Codex.
  • Two Orca builds running at once on the same folder (e.g. a dev build beside a packaged one). An older build adds and approves its own entry per launch; this build converts it only at app start or when you turn hooks on. Intended. That window belongs to the older build and ends when it updates.
  • Codex older than 0.129 gets no Orca status. Intended. It can't approve hooks, so Orca can't promise no review screen. Status says to update Codex.
  • Approvals you wrote as an inline table in config.toml (state = { … }) stop Orca adding its own. Those terminals get no Orca status, and status says why. Intended: Orca never makes your config.toml unloadable.
  • WSL terminals keep their installer, which writes and approves per launch from the Linux Codex's own hash. Temporary. Follow-up: run the same write-once check inside the distro.
  • SSH terminals keep the remote installer, whose approval Orca computes itself. Temporary. Follow-up: STA-9491 (get the hash from the remote Codex).
  • Dead session-migration code for the Orca-managed folder. Temporary. Follow-up: STA-9329.

Linked Issue

Follow-up to #23552.

Visual Proof

QA ran this branch's real dev app (2bc3ec5) on macOS and Windows 11. Each rig had an isolated home and Codex folder, codex went through a guard that refused the real ~/.codex, and turns went to a local mock model, with no login. The machines' real ~/.codex, ~/.claude and ~/.orca files, plus the Windows box's WSL ~/.codex, were hash-checked before the first launch, after it, after every scenario and after quitting. They never changed. Drivers: Grok on macOS; Codex, then opencode, on Windows.

macOS

Scenario Working Done
A new terminal: Orca's entry written once, status shows, no review
An alias, a full path, command codex, a script
codex resume --last, codex exec
Status hooks OFF, then ON
A user hook inserted ahead: Orca re-approves its own once, and Orca's hook shows Trusted
Codex 0.150.1 → 0.159.2 with Orca writing nothing
Stop switched off in /hooks: the same terminal stays off, and the next new terminal turns it back on
Restart with the terminal open
Beside an older Orca build: no review screen

Windows 11

Scenario Screenshot
A new PowerShell terminal: working, then idle
cmd.exe: plain codex, a doskey macro, resume --last
A PowerShell alias
A Codex update: the review screen lists only a hook the test added itself; Orca's hook is trusted
Status hooks OFF, then ON
Restart with terminals open

Testing

  • Real Codex, opt-in contract (src/main/codex/codex-hook-file-entry-binary-contract.test.ts). It passes on Codex 0.131.0, 0.133.0, 0.150.1 and 0.159.2, isolated; CI runs both pinned versions and the latest. It checks:

    • Orca's written approval makes every hook trusted and enabled, including over a /hooks switch-off;
    • an inserted hook shows as untrusted until Orca's next check;
    • an inline config.toml is left loadable;
    • a real Codex terminal UI start shows no review and the hook posts, while a deliberately mis-keyed approval does show the review.
  • Unit tests cover:

    • no writes or spawns when nothing changed;
    • writes on a missing entry, an inserted hook, a hash change, and on and off;
    • approval before entry, with rollback;
    • concurrent edits;
    • both spellings of a symlinked ~/.codex;
    • managed folders, including a late or failed Codex answer;
    • the fallback to the managed folder;
    • Codex's session-index rebuild;
    • status and the CLI.
      Each guard was removed in turn, and its test went red.
  • Related suites: about 150 files pass; the node and CLI typechecks are clean.

  • QA in the real app: macOS and Windows, run against 2bc3ec5. Later commits only fix edge cases the review found, and their unit tests and the real-Codex contract pass.

    • Every launch method showed status, with no review screen for Orca's hook: typed, alias, full path, command codex, scripts, cmd.exe (plain, doskey, cmd /c), PowerShell (pwsh -Command, scripts), resume and exec.
    • Zero writes when nothing changed: across new terminals, restarts and a Codex update.
    • One write when something did change: an inserted hook, hooks off or on.
    • Review screens seen: only ones listing hooks the test added and deliberately left unapproved. Orca never approves your own hooks.
    • Not exercised: an older Orca build actually rewriting the shared entry. The rig's guard blocked the older build's own background approval.
  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Author: @BrennanKB5

  • On Windows, Codex runs hooks through cmd without /d, so a broken HKCU cmd AutoRun fails Orca's hook (same as before this change).
  • Orca's hook command and script are byte-identical to main's, and nothing a client and a remote host exchange changes.

…nothing writes ~/.codex

Orca put its status hook entry into ~/.codex/hooks.json (and into every
managed Codex home) on each pane launch and resume, then asked Codex to
approve it in the background. Until that approval landed, a Codex started in
that home showed Codex's "Hooks need review" screen, and several races (a
failed approval, a Codex update, hooks off racing an approval, two Orca
builds) could leave a user looking at it.

Codex reads hooks and their approvals from `-c` session flags as well as
from files. Each native Codex launch now carries one flag,
`-c hooks={<8 events>, state={<key>={trusted_hash=...}}}`: Orca's hook plus
Codex's own approval of it. Nothing about Orca's hook is written to any
Codex home, and a flag never carries a hook without its approval.

- The key and hash come from Codex itself: `hooks/list` in a throwaway
  CODEX_HOME. Codex hashes a hook with no path or position in it, so the
  answer holds everywhere. Saved per `codex --version`, re-asked on any
  mismatch.
- The pane `codex` function (bash/zsh, fish, PowerShell) adds the flag only
  when its binary reports that version and the Codex home holds no Orca file
  entry (an older build's, which already posts status). Otherwise it adds
  nothing: no status, never a review screen.
- cmd.exe has no function: its pane defines a doskey macro in the existing
  /K startup that calls a gate script in the same cmd.exe. Main adds the
  flag to Orca-launched commands that name codex by absolute path.
- On Windows the flag holds no `"` or `%`; a profile path that needs the
  quoted cmd.exe spelling is carried by the script's 8.3 name.
- App start and turning hooks on remove Orca's entries from ~/.codex (with
  the user's hooks' approvals moved, as the opt-out does), run the
  retired-form sweep, refresh the managed home's user-hook mirror, and ask
  Codex for the flag. Turning hooks off is unchanged.
- Native launch prep, resume, structured chats and commit messages only
  mirror the user's own hooks into managed homes. WSL and SSH keep their
  installers.

Deleted: the per-launch real-home install, its background approval,
cooldown, withdrawal and launch/resume waits, the real-home lane gate, and
the managed-home install of Orca's entry.
…dex too

Its hook is a .cmd script named by a bare forward-slash path, the spelling the
Windows flag carries, so the same five checks pin the synthetic session-flags
key and approval on Windows.
The status hook flag and its Codex version were copied into each pane's
env at spawn, from state derived only at app start or when the setting
turned on. Panes outlive Orca restarts in the terminal daemon, so a
Codex update, a codex installed later, one failed derivation, a pane
spawned before the derivation landed, or the hooks setting changing
left panes with no status (or with Orca's hook after the opt-out) until
they were reopened.

Panes now carry only ORCA_CODEX_HOOK_FLAGS, the path of a per-profile
table in userData (codex-hook-flags/<codex --version>.flag, plus
.no-daemon), and each launch reads the entry for its own binary's
version. A launch that finds none writes <version>.request with its
codex path; the main process watches the table and derives an entry for
that binary, at most three times per binary and version with backoff.
The opt-out empties the table, and a derivation in flight when it lands
publishes nothing. An entry is the single store of the derived answer:
it holds the whole flag, is re-derived when its hook definition differs
from this build's, and is published only after Codex lists the complete
flag as trusted. getStatus and the CLI read the table from disk.

Also: carriers skip the flag beside the user's own `-c hooks...`, match
older Orca entries by the sweep's agent-hooks/codex-hook. needle with
either separator, take --no-daemon from the entry instead of probing
--help, and the cmd gate tries every version line. Codex resumes wait
at most 3 s for a derivation in flight. Shell wrapper snapshots
regenerated for the new function text.
… shells in CI

App start now strips Orca's entries from ~/.codex on every launch, and
the tests that pinned that removal went with the deleted installer.
Restore them against removeRealHomeCodexHookEntries: no ~/.codex
creates nothing; a malformed or unreadable hooks.json keeps its bytes,
Orca's trust and the ownership ledger; a mixed hook group loses only
hash-proven Orca trust; a user hook after Orca's keeps its approval.

The pane CLI load-boundary test mocked a module this branch deleted,
so it guarded nothing; it now forbids loading the hook service and the
flag derivation. The shell carrier suite joins the shell contracts job,
the only CI job with fish, and fails there without pwsh or fish.
…heck; comments name the flag

The contract now calls the same check Orca runs before publishing a
table entry, against the real binary: the complete flag reads as
trusted, and a wrong hash does not. Passed on Codex 0.150.1 and 0.159.2.

Comments that still described install(), the real-home grant lane, or
the opt-out as the only ~/.codex writer now describe the managed-home
refresh and app start's removal.
The changed-code quality gate rejects type assertions; five migrated
suites cast JSON.parse results, and one imported a module twice.
macOS reports a write burst under the watched directory's own name, so
filtering events by the .request suffix dropped most requests: a launch
that missed waited for the next event or an Orca restart. The watcher
test was red 2 runs in 3 on this laptop before this change, 5 in 5
green after.
… switch

When a user switches Orca's hook off in Codex's /hooks screen, Codex
writes enabled = false for the session-flag key into the home's
config.toml and merges it per field with the flag's approval. The flag
carried only trusted_hash, so the hook stayed off for good; a Stop
switched off left the pane stuck on "working". Only Orca's own setting
may turn Orca's hook off (#23289).

Each event's state now carries enabled = true beside trusted_hash, in
both spellings (the Windows one still holds no " or %). The pre-publish
check also requires Codex to list every event as enabled, and an entry
published before this shape is re-derived. A real-binary contract case
writes enabled = false at every session-flag key and expects the flag to
list each hook trusted and enabled; it passes on Codex 0.150.1 and
0.159.2 and fails on 0.159.2 when the field is dropped.
With hooks off, every typed codex still ran a --version probe and left a
request for Orca to delete, because the table directory stayed in place
and only its entries were removed.

The directory is now the switch. The opt-out and disabling Codex remove
it; app start with hooks on and the setting turning on create it, the
latter even when codex is not installed yet (a new per-agent enabler
runs before the presence-gated installers), so a later launch's miss
still asks for its entry. Every carrier (bash/zsh, fish, PowerShell, the
cmd gate, Orca-launched path-named codex) checks the directory first and
runs plain codex, with no probe and no request, when it is missing.
Publishing never creates the directory, and the generation guard still
stops a derivation in flight at the opt-out. The request watch is re-armed
whenever the directory is created again. Shell wrapper snapshots
regenerated for the new check.
The codex hook service, which the CLI's managed-hook controls load,
now imports codex-hook-flag-requests.ts; tc:cli rejects a file outside
its explicit list (TS6307).
…lows the setting

Round-2 review of the session-flag table found these problems:
- A failed delete at app start (a request racing rm -rf, a Windows file held
  open, a request that is a directory) threw out of startup, so Orca would
  not start. The same throw skipped the rest of the opt-out.
- A codex installed after start got an entry, but no hook script.
- The resume wait had nothing to wait on until after the claude installers.
- An ON right after an OFF joined a run the OFF had voided.
- The table's presence followed whichever toggle ran last, not the setting.
- A missed file-watch event waited for the next launch.
- Entries for old versions and old definitions were never pruned.

Now:
- Every table and request delete is best-effort (retries, logged, never
  thrown); requests that are not files are skipped; a failed publish removes
  its temp file.
- One reconcile makes the table exist exactly while Codex hooks are on. It
  reads the setting when it runs and is called from app start, the ON
  enabler and the opt-out (outside the trust lane).
- A derivation writes the hook script and cmd gate before publishing.
- App start schedules the default derivation right after shell PATH
  hydration, and the 3 s resume wait counts it.
- Runs are deduped per (codex path, generation); a voided run is never a
  failed try.
- Requests drain right after the watch opens, again a second later, on every
  native pane spawn and Orca-launched miss; a failed watch falls back to
  those drains.
- Reconcile prunes entries with another definition and keeps the eight
  newest; status reports the entry for this process's codex version.

Carriers:
- The user hooks override is also caught as -c=hooks…, with whitespace
  before the key, and --config= hooks….
- npm's codex.ps1 maps to its sibling codex.cmd for requests and probes.
- fish writes its request through sh, so a failed write is silent.
- PowerShell and Orca-launched commands try every --version line, as the
  cmd gate does.
- The cmd gate's findstr is case-insensitive.

The flag lookup helpers move to codex-hook-session-flag-lookup.ts.
Tests (watcher ones now use a fake watch and fake timers) cover each item.
…contracts for the codex function

The vitest guard now unsets ORCA_CODEX_HOOK_FLAGS (and guards it as live
state), ORCA_CODEX_HOOK_GATE and ORCA_CODEX_HOOK_ARG: a shell suite that
spreads process.env inside an Orca pane wrote five requests into the live
table, which the live app would have served by running the test's fake
codex. The shell contracts job now runs when only
src/shared/codex-shell-function.ts changes.
…lag table machinery

The table lifecycle had grown a generation counter, generation-keyed
in-flight runs, pending starts, per-request failure counters with backoff,
an open/close/reconcile/nudge split, two settle drains, a process-wide
default version, and main writing request files to itself. Each patched one
race the others created.

One function now does it all, and every call site calls it:
- It reads the setting when it runs. Off: remove the table, forget what it
  knew, close the watch. On: create the table, write the hook script and cmd
  gate when they differ (nothing is derived if the script cannot be
  written), watch the table, then derive in a single-flight run with at most
  one rerun.
- A run derives for Orca's own codex, for any binary an Orca-side launch
  names, and for each request's binary (codex.ps1 maps to its codex.cmd;
  cmd's path-less request means Orca's codex).
- A binary is derived again only when its fingerprint (realpath, size,
  mtime, inode) changed or its entry is gone; a failure is cached per
  fingerprint until the binary changes or hooks are toggled.
- A publish is checked against the setting and the table synchronously
  right before the write, which is what stops a run that an opt-out
  overtook. The run then prunes entries of another definition (cap 8).

Call sites:
- app start, once shell PATH hydration settles (running is set at once, so
  a cold-start resume's bounded wait sees it);
- every setting change, on or off, even when the codex CLI is not found;
- each native pane spawn, next tick;
- Orca-side launch prep for the binary it runs;
- a resume, which waits for the sync at most 3 s;
- any event from the table watch, debounced 100 ms.

The installer keeps only the ~/.codex, retired-form and managed-home
cleanup plus its shared scripts. Status reports the entry for the version of
the codex this process resolves; the CLI learns that version once, within
the 5 s version timeout, before printing status. The CLI's process follows
the saved setting for the table but derives nothing: the app does at its
next start.
… idle, and never latches a timeout

Round-3 review of syncCodexHookFlags found:
- S1: a request's version was ignored. A version manager's shim keeps its
  bytes when the codex behind it updates, so the new version never got an
  entry. A requested version without an entry is now derived whatever the
  fingerprint says; a binary that answers another version is remembered for
  that request.
- S2: on Windows profiles that need the 8.3 name, every sync spawned
  cmd.exe for the short path. The carriable hook command is now remembered
  per process for the script path; a failed lookup is retried after 60 s.
  A codex that is not installed is recorded without spawning it.
- S3: a failed 8.3 lookup during the prune deleted every entry. Nothing is
  pruned while this build's definition is unknown.
- S4: failures are now cached per fingerprint and per requested version.
  Timeouts (--version, app-server, 8.3 lookup) retry after 60 s; other
  failures stay cached until the binary changes or hooks are toggled. A
  derivation an opt-out overtook writes into the replaced map, so its
  failure never reaches the answers after the toggle.
- S5: a call landing between a run's last check and its end was lost. The
  run now decides to rerun or finish and clears `running` in one step.

Also: one pane spawn schedules one sync however many env builders ask;
tests for the bounded wait's timeout, a codex request that is not a codex
binary, and the 8.3 cases. The trust tests read the approval in either
flag spelling (W2-1).
…filter

On the Windows box every PowerShell lane was red: the machine's cmd AutoRun
fails against the sandboxed USERPROFILE and its error names the sandbox,
whose 'orca-codex-hook-flag-' prefix matched /codex|ORCA_|hooks/i. The
sandbox is now 'shell-carrier-'.
…ing a rerun ends the run

N3-1: every derivation throw counted as transient, so a codex without the
app-server, or one whose app-server exits early, cost a --version and an
app-server spawn every 60 s for the life of the process. Only app-server
timeouts and failed spawns retry soon now; other failures stay cached per
fingerprint until the binary changes or hooks are toggled.

N3-2: reading the setting to decide a rerun sat outside the run's try, so a
throw there left 'running' set to a rejected promise that every later sync
returned. The decision now happens inside it; a throw ends the run cleanly.
…sts resolve on Windows

RC-3: every native Windows pane defines the cmd codex macro, but the gate
script was written only while Codex hooks were on. In a build that never
ran with them on, every typed codex printed cmd's "not recognized". The
gate is now written at app start whatever the setting (it is inert
without the table), and the macro clears the flag variable and calls the
gate only if the file exists, so a missing gate runs plain codex quietly
and never reuses a flag an earlier launch left set.

RC-4: a Git Bash pane writes its codex path as /c/Users/..., which Node
cannot resolve, so the binary read as missing and its failure stayed
cached. Requests' /<drive>/... paths are read as <drive>:\... on Windows.

RC-5: the registry comment named the retired app-server trust grant.
…Codex is older

Codex 0.131 and 0.132 list only 6 hook events in hooks/list (no
SubagentStart or SubagentStop), so a derivation for them always failed
with a detail that did not tell the user what to do. 0.133.0 and newer
pass the full real-binary contract.

MIN_CODEX_HOOK_FLAG_VERSION is 0.133.0. A `codex-cli X.Y.Z` below it is
not asked anything beyond --version: no app-server spawn, and the failure
is cached per fingerprint like any deterministic one. Status, in the app
(Settings) and in `orca agent hooks status`, reads "Codex <v> is older
than 0.133; update Codex for Orca status". A version Orca cannot parse
(a dev build) is not treated as old and derives as before. The CI contract
pins (0.150.1, 0.158.0) are above the minimum and need no change.
…elds

CI's anti-slop lint rejects Reflect.get. readSessionFlagTrust now builds the
trust record straight from the typed hooks/list listings (the untrusted-input
parser it went through served the retired memo file), and a spawn error is
recognised by a narrowed 'syscall' field.
…mock carries the status reader

codex-cmd-hook-flag-gate.test.ts holds a runIf(win32) block that runs the
gate in cmd.exe, so it self-skipped everywhere in CI. It joins both Windows
registration lists the lane test requires (the package_windows argv and
WINDOWS_PACKAGE_TESTS); the same cases passed 10/10 on the Windows box.

The CLI deferral suite mocks the managed-hook controls. The CLI handler now
also takes readManagedAgentHookStatuses from that module, and reading an
export the mock did not define threw before `agent hooks off` applied the
setting. The handler's call is unchanged (applyAgentStatusHooksEnabled(false,
the saved settings)), so the mock gains the export and the expectation stays.
…oks-write-once

Conflicts with #24332 (Codex's Interrupt hook):
- codex-hook-local-install.ts, codex-real-home-hook-entry-plan.ts and
  codex-real-home-frozen-entry.test.ts stay deleted: this branch removed the
  managed-home and real-home installers they belong to.
- hook-service-managed-install.test.ts and hook-service-trust-grant.test.ts
  keep this branch's side: main's side extends tests of those deleted installers.

#24332's intent carried into the session flag:
- The flag defines Interrupt too, and every event's timeout comes from
  buildCodexManagedHook, so Codex's per-event normalization (Interrupt capped
  at 3 s) is what the flag carries and codexHookSessionFlagDefines checks.
- Interrupt is optional: derivation requires the original 8 events, adds
  Interrupt's approval when Codex lists it, and the pre-publish check requires
  it trusted and enabled only then. An older Codex drops the definition
  silently. Real-binary runs: 0.133.0 lists 8 and verifies, with Interrupt
  defined and no warning; 0.150.1 and 0.159.2 list and trust all 9.
- The contract accepts either shape and checks Interrupt is trusted wherever
  Codex lists it, and that a real turn prints no hook warning.
…the retrying helper

Now that the file runs in the Windows CI lane, its raw recursive rmSync
calls trip the lane's tree-removal boundary: a cmd.exe child still holding
the sandbox can fail a single-shot delete there. Both use removeTreeSync.
@brennanb2025 brennanb2025 changed the title fix(codex): Orca's Codex status hook rides each launch as a flag; nothing writes ~/.codex fix(codex): Orca's Codex status hook rides each launch as a flag, so Orca never writes its hook into ~/.codex Oct 1, 2026
… widen its CI scope

The contract now starts a real Codex TUI in a pty with Orca's reconciled entry
(no review, the hook posts) and a mis-keyed control (review shown), checks a
config.toml with inline hook approvals stays loadable, and matches only
'need(s) review' in exec output. The contract job also runs when any file that
decides whether Codex accepts Orca's approval changes. Drops a deleted test
from the shard timings.
On Windows Codex resolves its default home from the Profile folder, not
USERPROFILE, so a check with CODEX_HOME removed could list, and start an
app-server in, a different home than the one Orca wrote. Pass CODEX_HOME
explicitly there; Orca already approves the resolved spelling Codex keys an
explicit home by. POSIX keeps the default-home check.
…able config.toml

The managed refresh's mirrored user-trust upsert, the user-trust moves, the
rollback restore, the mirrored enabled states and the SSH writer now all go
through the same check: a write that would turn a config.toml Codex can load
into one it cannot (a user's inline or dotted hooks.state) is refused. A file
that is already broken may still be repaired.
- An event that also holds an older build's entry keeps the approval of
  Orca's own frozen entry: deferred events are never swept as stale.
- A refusal of Orca's approval survives the per-process re-probe, so a
  refused binary is not written, checked and withdrawn on every app start.
- A timed-out answer keeps a managed home's approved entry, like a late one.
- The routing gate re-reads ~/.codex/hooks.json when asked, and runs with a
  managed account selected also keep it current.
- A write whose check waited for Codex's session index is checked once more on
  a later reconcile; any finished check drops that.
- Removing approvals goes through the same must-still-load guard.
…e hashes

Without hashes the managed home could not approve Orca's entry either, so
moving panes there gains nothing; before any answer the lane stays open too.
… that times out

A non-zero exit was never remembered, so every pane spawn and managed install
spawned it again. It now waits out the same 60 s window as a timeout.
The mocked real-home ensure and trust wait were removed by this PR.
@brennanb2025 brennanb2025 changed the title fix(codex): Orca's Codex status hook rides each launch as a flag, so Orca never writes its hook into ~/.codex fix(codex): Orca writes its Codex status hook once, approved by Codex, so every launch gets status and no review screen Oct 5, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: v2 (durable, write-once status hook), ready for review, not merged

The problem. Orca re-added its Codex status hook to ~/.codex on every Codex launch and approved it in the background, for up to 30 s. Until that approval landed, Codex could show "Hooks need review" for Orca's hook. This PR's first version moved the hook onto each launch's command line instead. That only reached launches that go through Orca's shell function: Codex started by full path, from scripts, from tmux or from company launchers lost status. Brennan ruled out that kind of enforced launch path, so this is v2.

What changes for users.

  • Status works however Codex is started in an Orca terminal.
  • Codex never shows "Hooks need review" for Orca's hook. Orca writes Codex's own approval before the hook.
  • Orca writes ~/.codex only when something changed, never on every launch.
  • Full details, with the "Which Codex launches get status" table and the Differences section, are in the PR body.

Review. Three full reviewers, three narrow re-checks and a readiness checklist (PASS, no P0/P1). Fixed along the way:

  • the fallback to Orca's managed folder when Orca can't approve its hook in ~/.codex (restored from main);
  • a late Codex answer stripping a managed folder's entry;
  • false "rejected" verdicts under concurrent writes;
  • stale answers behind version-manager shims;
  • the post-write check skipping while Codex rebuilds its session index;
  • never making the user's config.toml unloadable (every approval write is now guarded);
  • both spellings of a symlinked ~/.codex;
  • the Windows post-write check using the folder Orca wrote;
  • an approval lost when an event also holds an older build's entry;
  • a refusal forgotten on restart;
  • extra Codex spawns on each terminal for a broken install;
  • the CI contract's scope.

Deferred / Intended.

  • A /hooks switch-off in Codex stays off in that same terminal until Orca's next check (the next terminal or Codex launch from Orca). QA confirmed on macOS and Windows that the next terminal turns it back on.
  • Codex older than 0.129 gets no status, and status says to update Codex.
  • Inline approval tables in config.toml get no Orca status, and Orca says why.
  • WSL stays per-launch. Temporary.
  • SSH stays per-launch: STA-9491. Temporary.
  • Dead mirror-migration code: STA-9329. Temporary.
  • A write made while Codex rebuilds its session index isn't re-checked if Orca restarts first.

Verified.

  • The real-Codex contract on 0.131.0, 0.133.0, 0.150.1 and 0.159.2. It covers a Codex terminal-UI start with no review screen, plus a control with a wrong approval that does show it.
  • Unit tests, with each guard removed in turn to confirm its test goes red.
  • tc:node and tc:cli are clean.
  • QA in the real app on macOS (Grok) and Windows 11 (Codex, then opencode), at 2bc3ec5:
    • every launch method showed status;
    • zero writes when nothing changed;
    • no review screen for Orca's hook;
    • real ~/.codex, ~/.claude and ~/.orca files, and the box's WSL ~/.codex, unchanged at every check.

Not verified.

  • An older Orca build actually rewriting the shared entry: the rig's guard blocked the older build's background approval.
  • Real Linux.
  • tmux (not installed on either QA machine).
  • QA ran on 2bc3ec5. The later commits fix only edge cases found in review, each covered by tests.

CI. The one red check, verify:localization-coverage, comes from main's #25472 (worktree-creation-hook-preparation.ts), a file this PR doesn't touch.

Not merged.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 5, 2026 13:24

@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 missed-cleanup edge and a comment nitpick.

Reviewed changes

This run re-reviewed the PR at its current head, where the mechanism differs from the earlier snapshot: Orca now writes Codex's own approval of its status hook into ~/.codex once and reconciles on change, instead of carrying the hook per launch as a -c hooks=… flag. Read the full 80-file diff.

  • Write-once approval then entry — reconcileRealHomeCodexHookEntries plans the frozen entry per event and writes Codex-derived approvals before the hooks.json entry, with state-guarded rollback (codex-hook-approval-first-write.ts, codex-real-home-hook-install.ts).
  • Codex-derived hashes — a throwaway CODEX_HOME app-server hooks/list supplies Codex's per-event hash; binary fingerprints and per-version hashes are memoized with a 60 s transient retry (codex-hook-trust-derivation.ts, codex-hook-trust-memo.ts, codex-hook-hash-lookup.ts).
  • Never break config.toml — every hooks.state write is refused if it would make a loadable file unloadable; reads now also surface dotted/inline approvals (config-toml-trust.ts, config-toml-hook-trust-read.ts).
  • Reconcile singleton + routing gate — codex-hook-reconcile.ts coalesces app-start/setting/pane-spawn/launch triggers, gates launches to the managed home when ~/.codex can't take the entry, and post-checks a write with one read-only hooks/list.
  • Deletions and wiring — background-grant/withdrawal/entry-trust/per-launch-flag modules removed; the codex installer now calls reconcileHooks; CLI status prints the home it read; CI adds the real-binary file-entry contract on both pins and @latest.

ℹ️ Nitpicks

  • codex-hook-reconcile.ts:107 — the comment "it reads the files after this spawn anyway" is not strictly guaranteed: a run already past its file read won't re-read, so a freshness reconcile can be delayed to the next spawn or app start. The behavior is bounded, and setting changes use the never-dropped rerun path — the comment just overstates the guarantee.

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

}
return (verdict = install.verdict)
try {
removeHookTrustEntries(tomlPath, stale)

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.

The new readParsedHookTrust fallback surfaces dotted/inline hooks.state approvals to readHookTrustEntries, but removeHookTrustEntries only matches [hooks.state."…"] blocks, so an approval that findStaleOrcaApprovals selects from the fallback is silently left in place. Orca only ever writes block form, so this is an edge case with no user-visible impact, but the sweep's intent and its reach don't match.

Technical details
# Stale-approval sweep can't remove the dotted/inline approvals it now selects

## Affected sites
- `src/main/codex/codex-real-home-hook-install.ts:203` — `removeHookTrustEntries(tomlPath, stale)` is a silent no-op for a key that `findStaleOrcaApprovals` returned from the smol-toml fallback.
- `src/main/codex/config-toml-hook-trust-read.ts:31-40` — `readParsedHookTrust` now surfaces dotted/inline `hooks.state` approvals.
- `src/main/codex/config-toml-hook-trust-edit.ts:40-53` — `removeHookTrustContent` only matches `[hooks.state."…"]` table headers.

## Required outcome
- Either the stale set excludes keys the block remover cannot act on, or removal handles dotted/inline approvals, so the sweep's reach matches its intent (or the no-op is documented).

## Open questions for the human
- Is a dotted/inline Orca-hash approval reachable outside a hand-edited `config.toml`? If not, documenting the no-op may be enough.

@brennanb2025
brennanb2025 requested a review from Jinwoo-H October 5, 2026 19:52
…oks-write-once

# Conflicts:
#	config/tsconfig.cli.json

@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 new issues in this delta — the one prior informational finding still stands, so this is a comment review rather than an approval.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review at f06ceb1 — a single merge of origin/main (dbc57ef), with no PR-authored behavior change.

  • Merge-up of origin/main. The merge folds in main's provider-process rename (codex-process-exit-deadline → provider-process/provider-process-exit-deadline, codex-app-server-record-reader → provider-process/provider-record-reader, plus provider-process-launch). The PR's own staged-list hunks in config/scripts/pr-code-change-scope.mjs and config/tsconfig.cli.json were updated to the new paths; the rest of the merge is main's unrelated work.
  • Merged state is coherent. No dangling references to the old codex-process-exit-deadline / codex-app-server-record-reader names remain anywhere, and every path the merged scope/tsconfig lists reference exists on disk.

ℹ️ Prior stale-approval sweep finding still open

The earlier review's informational finding at src/main/codex/codex-real-home-hook-install.ts:203 is unchanged by this merge: removeHookTrustEntries still matches only [hooks.state."…"] blocks, so a dotted/inline approval that findStaleOrcaApprovals selects from the new smol-toml fallback is silently left in place. No user-visible impact (Orca only writes block form), so it is not a merge blocker; the thread is left open for the author to decide whether to reconcile the sweep's reach with its selection or document the no-op.

Technical details
# Stale-approval sweep can't remove the dotted/inline approvals it now selects

## Affected sites
- `src/main/codex/codex-real-home-hook-install.ts:203` — `removeHookTrustEntries(tomlPath, stale)` is a silent no-op for a key `findStaleOrcaApprovals` returned from the smol-toml fallback.
- `src/main/codex/config-toml-hook-trust-read.ts` — `readParsedHookTrust` now surfaces dotted/inline `hooks.state` approvals.
- `src/main/codex/config-toml-hook-trust-edit.ts` — `removeHookTrustContent` only matches `[hooks.state."…"]` table headers.

## Required outcome
- Either exclude keys the block remover cannot act on from the stale set, handle dotted/inline approvals in removal, or document the intentional no-op.

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

The hook-approval paths this PR adds pushed pr-code-change-scope.test.mjs
past its 600-line limit once merged with main.
@Jinwoo-H

Jinwoo-H commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by #25741 #25742 #25743 #25744

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.

2 participants