Skip to content

fix(codex): stop an unreadable legacy hooks.json from clearing managed trust - #16147

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/codex-hooks-read-followup
Aug 24, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/codex-hooks-read-followup

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

ELI5

If Orca can't read ~/.codex/hooks.json for a moment, it concludes there are no hooks configured — and then removes the hook approvals you already gave, plus the record that you gave them. You get asked to approve hooks you'd already approved.

What Changed

cleanupLegacySystemManagedHooks reads the legacy hooks file and, on finding no hooks, removes Orca's managed trust entries from the system config.toml and deletes that home's grant-ledger record.

Since #15417 landed, the reader already tells those two answers apart:

readHooksJsonWithRaw returns
genuine absence { raw: null, config: {} }
failed read { raw: null, config: null }

Both still fell into the same branch. One line now returns before the removal when the answer was "could not read".

Why #15417 didn't catch it

#15417 fixed the classifier. This is a consumer of it that ignored the distinction — the read was already reporting correctly and the caller collapsed it anyway. Worth noting as a pattern: fixing the primitive doesn't fix callers that were written against the old two-valued shape.

What I deliberately left out

The sibling assertHooksJsonGeneration in codex-real-home-hook-install.ts:77 has the identical existsSync ? read : null shape, and I wrote the fix for it. Then I couldn't make it fail.

Measured on both platforms, a permission denial leaves existsSync true and throws from the read — so that path already fails closed. Reverting my guard while keeping everything else left all three of its tests green. That's unprovable code, so it's dropped rather than shipped with tests that assert nothing.

Linked Issue

Fixes STA-5264. Follow-up to STA-4823 / #15417.

Visual Proof

N/A — no UI surface. The observable difference is that trust entries and the ledger record survive.

Testing

One test, and it took three attempts to make it honest — the first two passed against the unfixed code:

  1. First version called a newly-exported _internals member, so reverting the fix failed on the missing export, not the missing guard.
  2. Second version reverted only the logic and still passed, because the removal branch is gated on hasRecordedRealHomeGrant and the test never seeded a grant-ledger record. The branch was inert.
  3. Third version seeds the ledger. Reverting the guard now turns it red.

That's the version here. The rig models the measured denial shape — content reads throw EACCES, while existsSync and stat stay healthy — because that is what chmod 000 and icacls /deny actually do. No mode fakes existsSync, since no platform does.

  • 1812/1812 across src/main/codex + src/main/agent-hooks.

  • check-changed-code-quality.mjs: 0 findings. Full pnpm typecheck clean.

  • Automated tests added

  • Manual: not run. Deterministic under the rig.

Provenance

Recovered from an uncommitted worker worktree during cleanup — it would have been deleted with it.

AI Disclosure

N/A — internal.

…d trust

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing #15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7da13be0-83c8-4aea-8145-4786643d33c9

📥 Commits

Reviewing files that changed from the base of the PR and between f0c718e and 9bed42251a50d2f1079ba74fc35fc398b1b795ad.

📒 Files selected for processing (2)
  • src/main/codex/codex-hooks-read-denial-followup.test.ts
  • src/main/codex/hook-service.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Legacy Codex hook cleanup now returns without modifying hooks or trust data when hooks.json cannot be read. The cleanup function is exposed through _internals. A Vitest regression test simulates denied reads, initializes isolated paths, seeds trust data, and verifies that managed trust removal is not called.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
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 and concisely identifies the fix for unreadable legacy hooks.json clearing managed trust.
Description check ✅ Passed The description covers the required sections, linked issue, rationale, testing, visual proof, and scope; minor unchecked checklist items do not block review.
✨ 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.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/codex-hooks-read-followup branch from 9bed422 to 96bcfe4 Compare August 23, 2026 22:05
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual evidence

This PR is a main-process Codex trust-state fix (cleanupLegacySystemManagedHooks returns when readHooksJsonWithRaw reports a failed read). There is no renderer control or UI change, so the screenshot is not a claim that the trust-preservation behavior is visible in the app.

Startup screenshot (product context only)

Uncropped full window of the exact PR worktree after CDP attach (1728×1009). Isolated profile (ORCA_DEV_USER_DATA_PATH), so this is the empty-workspace start screen — not a demonstration that an unreadable ~/.codex/hooks.json keeps managed trust.

window.api.app.getIdentity():

  • devRepoRoot: /Users/brennanbenson/orca/workspaces/orca/review-16147
  • devBranch: brennanb2025/codex-hooks-read-followup
  • devLabel: review-16147 @ brennanb2025/codex-hooks-read-followup

pr-16147-codex-hooks-startup.png

Backing proof (the actual behavior)

Focused regression, not a full-repo run:

pnpm exec vitest run --config config/vitest.config.ts src/main/codex/codex-hooks-read-denial-followup.test.ts

Result: 1/1 passed — returns before the removal branch instead of discarding approvals (4713ms).

No SSH test: the changed cleanup path operates on the local system Codex home and does not change relay, remote filesystem, RPC, or SSH-host behavior.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready to land

Final verdict: PASS / clean at 96bcfe45a531ef4ee41fcb65ebb5527e40669fc9. Opening and closing readiness reviews plus the same-model code review found no P0/P1/P2 issues, no meaningful follow-up edits, and no performance or scope regressions.

The key regression proof is valid: with the grant ledger seeded, reverting only the new production guard while retaining the test export makes returns before the removal branch instead of discarding approvals fail because the removal spy is called once. Restoring the guard makes the named test pass, so the test proves the behavior rather than merely depending on a new export or an inert branch.

The denial rig matches the measured platform shape: on macOS, existsSync and stat succeed while the content read throws EACCES (-13); the Windows analogue is EPERM (-4048). The test deliberately leaves existsSync real and fails only the read. The sibling assertHooksJsonGeneration change remains correctly omitted: for this reachable denial shape its existing readFileSync already throws closed, so no guard there can be demonstrated by a red regression.

Verification completed:

No mobile or SSH validation was needed: this is a local main-process Codex-home cleanup change with no renderer, mobile, RPC, relay, remote-filesystem, or SSH execution-boundary change.

@brennanb2025
brennanb2025 merged commit 8d08d00 into main Aug 24, 2026
88 of 93 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.

(cherry picked from commit 8d08d00)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…d trust (stablyai#16147)

`cleanupLegacySystemManagedHooks` reads `~/.codex/hooks.json` and, when it finds
no hooks, removes Orca's managed trust entries from the system config.toml and
deletes that home's grant-ledger record.

Since the STA-4823 read classification landed, `readHooksJsonWithRaw` reports a
genuine absence as `{ raw: null, config: {} }` and a failed read as
`{ raw: null, config: null }`. Both still fell into the same branch, so a read
that merely failed discarded hook approvals the user had already given — and the
ledger record that would have let a later pass notice.

Only the definitive-absence answer may reach the removal now.

Found while reviewing stablyai#15417 and not covered by it: that PR fixed the classifier
and this is a consumer of it that still collapsed the two answers.

The sibling `assertHooksJsonGeneration` guard in codex-real-home-hook-install.ts
has the same `existsSync ? read : null` shape and is deliberately NOT changed
here. Measured, a permission denial leaves existsSync true and throws from the
read, so that path already fails closed; a guard there could not be made to fail
in a test and would be unprovable code.
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