[failproofai-473] Fix Codex hooks.json: drop invalid top-level version field#473
[failproofai-473] Fix Codex hooks.json: drop invalid top-level version field#473NiveditJain wants to merge 1 commit into
Conversation
…on` field Codex CLI v0.142+ refuses to start a session when ~/.codex/hooks.json carries a top-level `version` field. Codex's HooksFile config struct is #[serde(deny_unknown_fields)] and only permits `hooks` (plus an optional `description`), so the `version: 1` marker our Codex integration wrote — an unverified assumption — produced: failed to parse hooks config: unknown field `version`, expected `hooks` at line 2 column 11 The `codex` integration now writes only `hooks`, and strips any leftover `version` on the next install/uninstall so a previously-broken config self-heals. Also correct the hook `timeout` from 60000 to 60: Codex reads `timeout` in seconds (its `timeout_sec` field, default 600), so the old value meant ~16.7h instead of 60s. The `__failproofai_hook__` marker is kept — Codex's internally-tagged HookHandlerConfig::Command tolerates unknown fields, and it is the primary install-detection key shared with every other integration. Scope is Codex-only; Copilot and Cursor legitimately carry `version: 1` in their own schemas. Regenerated the dogfood .codex/hooks.json to match. Verified against real Codex CLI v0.142.5: the old config reproduces the exact parse error, the fixed config parses cleanly and runs the hooks, and the marker is tolerated. Unit (1907), e2e (298), typecheck, lint, build, and Docker clean-install smoke all green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X6cq77Ku4Zg7Dx6z57hNzr
📝 WalkthroughWalkthroughThis PR fixes Codex hooks.json to remove an invalid top-level ChangesCodex hooks version and timeout fix
Estimated code review effort: 2 (Simple) | ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/hooks/integrations.ts (1)
297-300: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: extract shared "strip legacy version" helper.
The
delete (s as Record<string, unknown>).version;migration logic is duplicated betweenwriteHookEntriesandremoveHooksFromFile(the latter also trackshadVersion). A small shared helper (e.g.stripLegacyVersion(settings)) would reduce duplication.Also applies to: 325-332
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/integrations.ts` around lines 297 - 300, The legacy top-level version stripping logic is duplicated in `writeHookEntries` and `removeHooksFromFile`, so extract it into a shared helper such as `stripLegacyVersion(settings)` and use it in both places. Make the helper operate on the settings object before serialization, preserve `hadVersion` behavior in `removeHooksFromFile`, and keep the migration behavior identical while removing the repeated `delete (s as Record<string, unknown>).version;` logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/hooks/integrations.ts`:
- Around line 297-300: The legacy top-level version stripping logic is
duplicated in `writeHookEntries` and `removeHooksFromFile`, so extract it into a
shared helper such as `stripLegacyVersion(settings)` and use it in both places.
Make the helper operate on the settings object before serialization, preserve
`hadVersion` behavior in `removeHooksFromFile`, and keep the migration behavior
identical while removing the repeated `delete (s as Record<string,
unknown>).version;` logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4f739712-0b3e-45ce-b709-7cb55333e673
📒 Files selected for processing (7)
.codex/hooks.jsonCHANGELOG.mdCLAUDE.md__tests__/e2e/hooks/codex-integration.e2e.test.ts__tests__/hooks/integrations.test.tssrc/hooks/integrations.tssrc/hooks/types.ts
Problem
Installing failproofai hooks for OpenAI Codex wrote a top-level
"version": 1into~/.codex/hooks.json. Codex CLI v0.142+ then refuses to start any session:Root cause (confirmed against Codex's Rust source,
codex-rs/config/src/hook_config.rs):the top-level
HooksFilestruct is#[serde(deny_unknown_fields)]and permits onlyhooks(plus an optionaldescription). Theversionfield was an unverified assumption —Codex never wanted it.
Fix (Codex-only)
version, and strip any leftoverversionon the nextinstall/uninstall — so a previously-broken
hooks.jsonself-heals on reinstall (not just"stop adding it": upgraders already have
version: 1on disk).timeoutunit: Codex readstimeoutin seconds (itstimeout_secfield, default 600), so the old
60000meant ~16.7h, not 60s. Now60.__failproofai_hook__marker: Codex's internally-taggedHookHandlerConfig::Commandhas nodeny_unknown_fields, so the marker is tolerated; itstays as the primary install-detection key shared with every other integration.
.codex/hooks.json; corrected stale schema comments and theCLAUDE.mdCodex section.Copilot and Cursor legitimately carry
version: 1in their own schemas and are not touched.Verification
Tested against real Codex CLI v0.142.5:
version: 1) → reproduces the exact parse error above.version, marker present) → parses cleanly and Codex runs the hooks(
SessionStart/UserPromptSubmitfire).writeHookEntriescode path → parses cleanly.Plus: unit 1907 passed, e2e 298 passed,
tsc --noEmitclean, eslint 0 errors,bun run buildgreen, and the Docker clean-install smoke test exits 0.🤖 Generated with Claude Code
https://claude.ai/code/session_01X6cq77Ku4Zg7Dx6z57hNzr
Summary by CodeRabbit
Bug Fixes
versionfield.60seconds, improving compatibility and preventing rejected configurations.Documentation
Tests