Skip to content

fix(codex): write runtime currentHash for mirrored hook trust - #16568

Closed
innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/codex-runtime-hook-trust-hash
Closed

innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/codex-runtime-hook-trust-hash

Conversation

@innocarpe

@innocarpe innocarpe commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca mirrors user Codex hooks into a managed CODEX_HOME. On Windows, the same approved hook can have a different runtime hash and slash spelling, so Codex repeatedly asks to review it. This change asks Codex for the runtime hash, writes it through app-server RPC, and verifies the result without weakening approval checks.

What Changed

  • Preserve signature-based system approval, then require the system hooks/list current hash to match the stored approved hash.
  • Clear both Windows slash/backslash trust-key variants before granting or repairing runtime trust.
  • Use hooks/list → config/batchWrite → hooks/list with exact normalized key, command, trusted status, enabled state, and unchanged current hash verification.
  • Preserve disabled mirrored hooks through RPC verification and cache reuse.
  • Restore the exact TOML snapshot on failure and surface rollback failures.
  • Scope verified fingerprints and transient cooldowns by execution host and managed account home; cache unchanged stale approvals without granting them, and avoid cache reuse without a binary identity.
  • Keep unsupported app-server fallback behavior conservative so Codex still prompts when a runtime hash cannot be verified.

Why

Copying the system trusted_hash into Orca's remapped runtime home leaves Codex seeing a modified hook on every launch. Trust must instead use Codex's runtime currentHash, but only after proving the current system hook is still the one the user approved.

Linked Issue

Fixes #16428

Linear: STA-5443

Visual Proof

N/A — this is a non-visual Windows app-server/config trust flow with no renderer UI change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, including stale approval, disabled state, Windows key variants, rollback, cache/cooldown isolation, and exact post-write verification

Node 24 verification at e156bd72a073bc06f3ff53fcf6d6dde74696a1e6:

  • vitest ... src/main/codex: 1,221 passed; 6 expected skips
  • Focused trust/mirroring slice: 28 passed across 3 files
  • pnpm tc: passed
  • pnpm run check:code-quality:changed: passed
  • pnpm run check:max-lines-ratchet: passed
  • oxfmt --check on review-modified files: passed
  • git diff --check: passed

Live Windows/WSL/SSH Codex binaries were not available in this macOS worktree; those environments remain a CI/manual QA gap.

AI Disclosure

Review

A fresh adversarial review-until-clean pass plus independent correctness, platform, and performance reviews completed at the exact head. Proven disabled-state propagation, stale-approval negative-cache, and Windows moved-hook separator-cleanup issues were fixed; the final pass found no remaining in-scope issues.

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

No wire, provider, renderer, telemetry, credential, or remote protocol shape changes. SSH/folder workspaces are unaffected; Windows and WSL path normalization are covered by unit tests.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Exact-head CI result

At e156bd72a073bc06f3ff53fcf6d6dde74696a1e6, PR test LoC passed and 42 PR Checks jobs passed, including Windows packaging/boundaries, static analysis, typecheck, managed hooks on Node 18, Git compatibility, shell contracts, and cross-version wire compatibility. The overall PR Checks workflow is red from two deterministic runtime export-parity failures on Node 24/26 and one Node 26-only WebRTC egress Electron probe failure; all implicated files are byte-identical to base 026389a3bc03 and outside the Codex PR diff.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Mirrored user-hook trust entries now use the runtime hook’s currentHash when the normalized trust key and command match. If runtime listing is unavailable, the resolver preserves hashes found in TOML trust entries. The changes also clear or update trust-key separator variants and use resolved entries during hook installation and refresh. Tests cover matching, fallback behavior, separator variants, and trust persistence across installations.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 088cf

The change is mergeable after normal checks. An incomplete hook listing may occasionally cause a repeat review prompt; live Windows, WSL, and SSH behavior remains unvalidated.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue #16428 requires runtime trust to use Codex currentHash while signature matching remains the approval boundary. The changed code satisfies the matching, runtime-hash stamping, separator cleanup… Add the required app-server write and post-write hooks/list verification to the mirrored-hook install and maintenance flows. Verify the normalized key, command, trusted status, enabled state, and unchanged current hash before accepting th…
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: writing the runtime currentHash for mirrored hook trust.
Description check Passed The description includes all required sections, explains the user impact and implementation, links issue #16428, marks visual proof as not applicable, documents automated testing and known CI gaps, an…
Out of Scope Changes check Passed The changed source and tests address issue #16428. They implement mirrored runtime-hash resolution, Windows and WSL trust-key variant cleanup, stale-trust handling, cooldown isolation, and related tes…
Full details: Description check

Explanation

The description includes all required sections, explains the user impact and implementation, links issue #16428, marks visual proof as not applicable, documents automated testing and known CI gaps, and covers compatibility and security considerations.

Full details: Out of Scope Changes check

Explanation

The changed source and tests address issue #16428. They implement mirrored runtime-hash resolution, Windows and WSL trust-key variant cleanup, stale-trust handling, cooldown isolation, and related test harness support. No unrelated product area is changed.

Full details: Linked Issues check

Explanation

Issue #16428 requires runtime trust to use Codex currentHash while signature matching remains the approval boundary. The changed code satisfies the matching, runtime-hash stamping, separator cleanup, stale-entry, and unsupported/transient cooldown parts. However, both integration paths call listCodexHooks once and then call upsertHookTrustEntries with the TOML path. The reviewed changes do not establish the required hooks/list → config/batchWrite → hooks/list verification, including post-write key, command, trusted, enabled, and unchanged-hash checks. The new retry maps cache only failure cooldowns. They do not cache a verified runtime configuration fingerprint.

Resolution

Add the required app-server write and post-write hooks/list verification to the mirrored-hook install and maintenance flows. Verify the normalized key, command, trusted status, enabled state, and unchanged current hash before accepting the write. Add a successful verified-fingerprint cache scoped by execution host and managed account home. Add tests for the RPC round trip, post-write mismatch, and scoped cache reuse.

Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 11 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 36c8b7d3-d386-4aba-8e6c-b8624f4f060f
Commits

Reviewing files that changed from the base of the PR and between e156bd7 and 088cf97.

Files selected for processing: 11

  • src/main/codex/codex-hook-local-install.ts
  • src/main/codex/codex-hook-local-maintenance.ts
  • src/main/codex/codex-mirrored-hook-runtime-trust.test.ts
  • src/main/codex/codex-mirrored-hook-runtime-trust.ts
  • src/main/codex/config-toml-trust-hook-removal.test.ts
  • src/main/codex/config-toml-trust-hook-upsert.test.ts
  • src/main/codex/config-toml-trust-key.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service-test-harness.ts
  • src/main/codex/hook-service-user-hook-mirroring.test.ts
  • src/main/codex/hook-trust-promotion.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ccf3d35-262c-4073-88ca-aa13c6bd70b5

📥 Commits

Reviewing files that changed from the base of the PR and between 868fc39 and 283fbf5f49f8f7b4beaa60da59496e6ba26fee83.

📒 Files selected for processing (12)
  • src/main/codex/codex-mirrored-hook-runtime-trust.test.ts
  • src/main/codex/codex-mirrored-hook-runtime-trust.ts
  • src/main/codex/codex-user-hook-trust-rebase-client.test.ts
  • src/main/codex/codex-user-hook-trust-rebase-client.ts
  • src/main/codex/config-toml-hook-trust-edit.ts
  • src/main/codex/config-toml-trust-hook-removal.test.ts
  • src/main/codex/config-toml-trust-hook-upsert.test.ts
  • src/main/codex/config-toml-trust-key.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service-user-hook-mirroring.test.ts
  • src/main/codex/hook-service.ts
  • src/main/codex/hook-trust-promotion.test.ts

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

@innocarpe
innocarpe force-pushed the fix/codex-runtime-hook-trust-hash branch from 283fbf5 to f2b429c Compare August 26, 2026 09:17
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (f2b429c76)

Address CodeRabbit: require listing.command === entry.command before stamping currentHash. Incomplete command:null listings no longer trust a changed hook. Fingerprint-cache of verified listings stays out of this PR (heavy lift).

@brennanb2025
brennanb2025 force-pushed the fix/codex-runtime-hook-trust-hash branch from f2b429c to ed52080 Compare August 27, 2026 10:55
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Exact-head review verification

Verified commit: e156bd72a073bc06f3ff53fcf6d6dde74696a1e6

A fresh adversarial review-until-clean pass covered stale system approvals, exact normalized key and command matching, disabled state, clear/list/batchWrite/verify/rollback behavior, hash-scoped host/account caching, concurrency, mixed Codex versions, Windows/WSL/SSH boundaries, remote-wire neutrality, and performance. It found and fixed three in-scope issues: disabled mirrored hooks were transiently re-enabled and never cache-stable, unchanged stale approvals repeatedly reopened app-server inspection, and moved-hook repair cleared only one Windows separator spelling.

Independent correctness, platform, and performance reviewers were incorporated, and the final exact-head pass found no remaining proven in-scope defects. Live Windows/WSL/SSH Codex validation remains an explicit gap; no such run is claimed.

@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Exact-head QA / evidence

Verified commit: e156bd72a073bc06f3ff53fcf6d6dde74696a1e6

  • Node 24 full Codex suite: 1,221 passed, 6 expected skips across 118 files.
  • Focused trust/mirroring regression slice: 28 passed across 3 files.
  • pnpm tc: passed.
  • pnpm run check:code-quality:changed: 0 findings in all three scans.
  • pnpm run check:max-lines-ratchet: passed.
  • oxfmt --check on the six review-modified files: passed.
  • git diff --check: passed.
  • Coverage includes hooks/list → config/batchWrite → hooks/list, stale edited system content, exact command matching, disabled-state preservation and cache reuse, positive and negative cache behavior, equivalent/conflicting Windows slash variants, clearing both separator spellings during moved-hook repair, exact rollback plus rollback failure, transient/unsupported cooldown, and account/host isolation.

Exact-head GitHub Actions:

  • PR test LoC: passed.
  • PR Checks: failed overall with 42 successful jobs, 1 skipped e2e job, and 3 underlying test-job failures plus the verify aggregator.
  • Node 24 and Node 26 shard 10 both fail src/shared/runtime-client-export-parity.test.ts because three terminal exports are missing from the expected list. The test and runtime export sources are byte-identical to base 026389a3bc03; the failure also reproduces locally and is outside this PR's Codex diff.
  • Node 26 shard 15 fails src/main/browser/browser-route-webrtc-egress.electron.test.ts with AssertionError: no result; the corresponding Node 24 shard passes and the file is byte-identical to base. This is an unrelated Electron probe failure.
  • Relevant CI jobs passed, including Windows packaging and Windows-specific boundaries, static analysis, typecheck, managed hooks on Node 18, Git compatibility, shell contracts, and cross-version wire compatibility.

Electron/visual proof: N/A. This patch changes no renderer UI, and the motivating flow requires a Windows managed CODEX_HOME plus a real Codex binary; Playwright CDP cannot faithfully exercise that platform-specific config boundary from this macOS worktree. Live Windows/WSL/SSH validation remains the explicit QA gap; no desktop-control fallback was used.

@innocarpe
innocarpe force-pushed the fix/codex-runtime-hook-trust-hash branch from e156bd7 to 088cf97 Compare October 29, 2026 09:50
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[High impact] Modifies hook trust verification and storage logic.

The trust-update failure path should be made transactional before merging because a write error can delete previously valid mirrored-hook approvals.

Findings

  1. P1 Trust updates lack rollback ▶

Summary

The PR resolves mirrored Codex hooks to their runtime currentHash, normalizes Windows trust-key spellings, and preserves runtime trust state across unsupported app-server fallbacks. One failure-path issue remains:

  • Trust-key variants are deleted before multiple fallible writes, with no rollback if a later write fails.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Resolve mirrored runtime hashes] --> B[Remove slash and backslash trust entries]
  B --> C[Upsert resolved trust entries]
  C --> D[Remove stale entries]
  D --> E[Apply enabled states]
  C -->|failure| F[Return error with removed state exposed]
  D -->|failure| F
  E -->|failure| F
Loading

Reviews (1) · Last reviewed commit: "fix(codex): verify mirrored runtime hook..." · Reviewed by Greptile

Comment on lines +173 to +182
clearHookTrustKeySeparatorVariants(
tomlPath,
resolvedMirroredTrustEntries.map((entry) => computeTrustKey(entry))
)
const trustEntries: CodexTrustEntry[] = [
...resolvedMirroredTrustEntries,
...managedTrustEntries
]
// Reconcile revoked system approvals too; retaining old runtime trust would leave hooks approved.
upsertHookTrustEntries(tomlPath, mirroredTrustEntries)
upsertHookTrustEntries(tomlPath, resolvedMirroredTrustEntries)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Trust updates lack rollback

When a trust-config write, stale-entry cleanup, or enabled-state update fails after clearHookTrustKeySeparatorVariants succeeds, the catch returns an error without restoring the removed approvals, causing mirrored hooks to lose their trust or enabled state and prompt for review until repaired. Apply the clear, upsert, cleanup, and state update transactionally or restore the exact prior TOML snapshot on failure; the maintenance path has the same issue.

Approved system hooks still match by signature (stablyai#7110), but the
managed runtime trust entry is written with Codex's hooks/list
currentHash instead of the system trusted_hash. Both Windows
separator variants of the key are cleared before that write so
slash/backslash copies cannot stay conflicted.

Fixes stablyai#16428
Incomplete hooks/list records with command:null must not trust a
changed hook at the same key.
@innocarpe
innocarpe force-pushed the fix/codex-runtime-hook-trust-hash branch from 088cf97 to 590faed Compare November 10, 2026 12:23
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (590faede55)

Rebased onto current main. Mirrored runtime hook trust is written from Codex hooks/list currentHash, and both Windows separator variants of the key are cleared before that write.

@brennanb2025

Copy link
Copy Markdown
Contributor

Thank you for this, @innocarpe. Your fix pointed at the right place. We landed a narrower version in #43877, which credits you as co-author: on Windows, Orca's hook trust reader now lets the backslash key that Codex itself reads and writes win over Orca's slash copy, so re-approvals stick. Closing this one in favor of that.

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.

[Bug]: mirrored user hooks reuse system trusted_hash and trigger review after runtime remap

2 participants