Skip to content

Deduplicate Codex hook trust blocks - #3196

Merged
brennanb2025 merged 2 commits into
mainfrom
nwparker/issue-3190-codex-trust-dedupe
May 30, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
nwparker/issue-3190-codex-trust-dedupe

Conversation

@nwparker

@nwparker nwparker commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • collapse duplicate [hooks.state."..."] tables for the same Codex hook trust key during upsert
  • preserve unrelated hook-state tables and keep enabled = false if any duplicate copy had been disabled
  • remove all duplicate stale hook trust tables for requested keys during cleanup
  • harden hook trust scanning so headers inside TOML multiline strings, comments, and single-line strings are not treated as real tables
  • cover restart install repair, disabled-status-hook refresh cleanup, Windows-style keys, and TOML scanner edge cases

Fixes #3190.

Design / Review Outcome

  • Design source: docs/codex-hook-trust-duplicate-tables.md in the validation worktree.
  • Design and initial implementation were already present, per reviewer request; I skipped new design/implementation stages and used the doc as the review contract.
  • Completeness verification initially found a missing CodexHookService.install() restart regression; added it.
  • Code review loop ran multiple two-reviewer rounds. Actionable findings fixed:
    • install path could lose enabled = false before dedupe repair
    • stale cleanup removed only one duplicate table per key
    • scanner could match exact hook headers inside TOML multiline strings
    • scanner could be confused by triple quotes in comments or single-line strings
    • readHookTrustEntries needed the same TOML-aware scanner as upsert/remove
  • Final review round: both reviewers returned clean.

Implementation Notes

  • upsertHookTrustEntries now finds every real trust block for the target key, rewrites the first, drops later duplicates, and preserves disabled state if any duplicate was disabled.
  • removeHookTrustEntries now removes all real blocks for a requested key, which also fixes stale duplicate cleanup in hook-service paths.
  • Trust table range detection and trust reads now share TOML-aware multiline state handling.
  • Local install writes current trust before stale cleanup so duplicate repair can preserve disabled managed trust before old keys are removed.
  • No renderer/UI files changed.

Validation

  • pnpm run typecheck
  • pnpm run lint
  • git diff --check
  • pnpm exec vitest run --config config/vitest.config.ts src/main/codex/config-toml-trust.test.ts src/main/codex/hook-service.test.ts src/main/agent-hooks/installer-utils-remote.test.ts (98 tests passed)
  • pnpm vitest run --config config/vitest.config.ts src/main/agent-hooks/remote-hook-service-installers.test.ts (Brennan validation pass)
  • Brennan runtime validation with temp config.toml / hooks.json files exercised:
    • duplicate managed SessionStart trust repair
    • enabled = false preservation
    • stale duplicate managed trust cleanup when status hooks are disabled
    • Windows-style C:\... trust keys
    • TOML multiline/comment/single-line-string scanner resilience

Manual Validation / Product Surface

  • Electron UI validation skipped because the PR changes main-process/runtime config writing only: no renderer files, no visible controls, and no IPC/UI behavior changed.
  • Product runtime surface validated through CodexHookService.install() and refreshRuntimeUserHooks() against real temp filesystem state.

SSH / Cross-Platform

  • Live SSH validation skipped: no SSH transport, relay, remote PTY, or remote filesystem write code changed.
  • Remote behavior uses the same shared TOML content mutator; focused remote hook installer tests passed.
  • Residual risk: live remote filesystem/permission behavior was not re-proved, but the changed logic is content transformation rather than transport.

Verdict

  • Brennan validation verdict: land.

Risk assessment

Risk: HIGH

Historic risk metadata backfill based on the existing risk:high label.

@brennanb2025
brennanb2025 merged commit bcc9c0d into main May 30, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the nwparker/issue-3190-codex-trust-dedupe branch May 30, 2026 18:19
@mubeda

mubeda commented Jun 1, 2026

Copy link
Copy Markdown

Hi there! You are welcome, just tried the latest version 1.4.38 , i updated current installation but still facing the same error:
\AppData\Roaming\orca\codex-runtime-home\launch\host\system\home\config.toml:152:14: duplicate key
\AppData\Roaming\orca\codex-runtime-home\home\hooks.json:session_start:0:0".

I uninstalled the application and installed it again.
Same problem.

Also i notice, not sure if related with this issue, that the app , after closed in windows do not starts again. i need to kill the orca process in other to launch it again

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high High risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate [hooks.state."…"] tables accumulate in codex-runtime-home/config.toml on every close→reopen, breaking Codex startup

3 participants