Repository navigation
fix(codex): stop an unreadable legacy hooks.json from clearing managed trust - #16147
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between f0c718e and 9bed42251a50d2f1079ba74fc35fc398b1b795ad. 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughLegacy Codex hook cleanup now returns without modifying hooks or trust data when 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
9bed422 to
96bcfe4
Compare
Visual evidenceThis PR is a main-process Codex trust-state fix ( Startup screenshot (product context only)Uncropped full window of the exact PR worktree after CDP attach (
Backing proof (the actual behavior)Focused regression, not a full-repo run: Result: 1/1 passed — 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. |
Review status: ready to landFinal verdict: PASS / clean at The key regression proof is valid: with the grant ledger seeded, reverting only the new production guard while retaining the test export makes The denial rig matches the measured platform shape: on macOS, 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. |
…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)
…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.
…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.

ELI5
If Orca can't read
~/.codex/hooks.jsonfor 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
cleanupLegacySystemManagedHooksreads the legacy hooks file and, on finding no hooks, removes Orca's managed trust entries from the systemconfig.tomland deletes that home's grant-ledger record.Since #15417 landed, the reader already tells those two answers apart:
readHooksJsonWithRawreturns{ raw: null, config: {} }{ 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
assertHooksJsonGenerationincodex-real-home-hook-install.ts:77has the identicalexistsSync ? read : nullshape, and I wrote the fix for it. Then I couldn't make it fail.Measured on both platforms, a permission denial leaves
existsSynctrue 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:
_internalsmember, so reverting the fix failed on the missing export, not the missing guard.hasRecordedRealHomeGrantand the test never seeded a grant-ledger record. The branch was inert.That's the version here. The rig models the measured denial shape — content reads throw
EACCES, whileexistsSyncandstatstay healthy — because that is whatchmod 000andicacls /denyactually do. No mode fakesexistsSync, since no platform does.1812/1812 across
src/main/codex+src/main/agent-hooks.check-changed-code-quality.mjs: 0 findings. Fullpnpm typecheckclean.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.