Repository navigation
feat(hooks): record Codex hook trust on sync with --trust - #829
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da9d766c65
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for key, r := range state.Records { | ||
| if r.Root != "" || s.agentOf(r.Target) != "codex" { | ||
| continue |
There was a problem hiding this comment.
Restrict trust to records owned by the active config
When two global configs are selected through SKILLSHARE_CONFIG, they intentionally share StateDir, so this loop also collects the other config's Codex records. Running hooks sync --trust -g for config B therefore trusts config A's hooks even if B has no Codex entries in its source or preview; the normal planner avoids crossing this boundary by checking r.Owner against the source config. Filter records by the active config's absolute owner and preserve that ownership in codex-trust.json so trust reconciliation cannot cross config scopes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a6433dd. TrustCodex filters ledger records by the active absolute config owner and persists hashes per owner and hooks.json path. Legacy v1 hashes are cleanup-only. Covered by TestCodexTrustIsScopedByConfigOwner and TestCodexTrustMigratesLegacyStateForRemovedHooks.
| entry, ok := positions[codexPosition(h.Key)] | ||
| if !ok { | ||
| continue | ||
| } | ||
| result := CodexTrust{Target: target, Entry: entry, Key: h.Key, Action: "unchanged", Disabled: !h.Enabled} |
There was a problem hiding this comment.
Revalidate hook identity after Codex reads hooks.json
If another editor or tool prepends or replaces a group in hooks.json while codex app-server starts, positions still describes the earlier file while hooks/list returns the new handlers. Matching solely by source path and event/group index then assigns the old owned entry to the new unmanaged handler and records that handler's currentHash, allowing --trust to authorize a hook Skillshare does not own. Verify that the native snapshot used to locate ownership is still the snapshot represented by the listing before constructing trust edits.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a6433dd. TrustCodex rereads hooks.json after hooks/list and aborts before constructing edits if its existence or bytes changed since the ownership snapshot. Covered by TestCodexTrustRevalidatesHooksSnapshotAfterList, which prepends an unmanaged group during listing and verifies no trust write.
| if err := server.SetTrust(edits); err != nil { | ||
| return results, written, err |
There was a problem hiding this comment.
Report trust changes only after the batch write succeeds
If config/batchWrite rejects the edit batch or times out, results already contains trusted and cleared actions even though those writes have not been confirmed. Returning these rows unchanged causes printHooksTrust and --json to report completed trust changes despite the failed operation. Append successful mutation actions only after SetTrust succeeds, or explicitly mark those actions as failed or unconfirmed while preserving any genuinely unchanged rows.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a6433dd. On SetTrust failure, TrustCodex returns only unchanged rows; trusted and cleared actions are reported only after config/batchWrite succeeds. Covered by TestCodexTrustDoesNotReportUnconfirmedEdits for both failed trust and failed clear calls.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6433dd63a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| homes := map[string]string{} | ||
| owned := map[string]map[string]record{} | ||
| for key, r := range state.Records { | ||
| if r.Owner != owner || r.Root != "" || s.agentOf(r.Target) != "codex" { |
There was a problem hiding this comment.
Locate all file records before applying the owner filter
If configs A and B manage the same Codex home, the documented hooks edit ... --sync workflow (website/docs/reference/commands/hooks.md:25) can make B's existing group identical to A's; planShared permits this in-place update. Filtering out A's record before trustCodexHome calls locate leaves one holder for two identical native groups, so the ownership predicate at internal/hooks/plan.go:372 rejects B's record. Consequently, B's hooks sync --trust -g succeeds without recording trust for its hook, which remains untrusted. Locate against all per-file records, then restrict the resulting positions to the active owner.
AGENTS.md reference: AGENTS.md:L36-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a50ca323: locate now sees every record for the canonical hooks file before applying the active-owner filter; TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners covers shared-path and symlink-alias cases.
There was a problem hiding this comment.
The earlier a50ca323 fix is already in this PR as rebased commit 6ff2322d: git range-diff a6433dd6..a50ca323 03719577..6ff2322d reports the patches equal. The branch was subsequently updated to c369ce70; the fix was not lost.
The current follow-up eb992186bdbec67b43a410347f2426964146a19a preserves locating all records for the canonical file before applying the active-owner filter and corrects the alias test's expected keys. TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners covers both shared-path and symlink-alias cases. ac3af435 merges current upstream main without rewriting the published branch.
|
Reviewed at a6433dd. I reproduced two P2 issues:
Verification: the existing |
|
Fixed in |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Re-reviewed at a50ca32 (changes since a6433dd). Both P2 issues from the last round are fixed:
Two small notes, neither blocking:
Verification: read against Before merge: please tick the "reviewed every line of the diff" box once you have read it, and update the branch, which is behind |
Codex runs a user-level hook only after its trusted_hash is stored in that home's config.toml, keyed by the hook's position in hooks.json. Only the TUI's /hooks review writes it, so every hook Skillshare adds or moves starts untrusted and codex exec skips it without a word. `hooks sync --trust` (global mode, opt-in) asks each Codex home's `codex app-server` for the current hash of the hooks Skillshare owns and writes trusted_hash through config/batchWrite, the same calls /hooks makes, so the hash is always the one Codex computes. It changes nothing else in config.toml: disabled hooks stay disabled and are reported. Trust it wrote is remembered in the hooks state directory, so when a hook moves or is removed the next --trust sync clears the old position, unless that trust has changed since. Without codex on PATH the hook files are still written and the command fails saying trust was not recorded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scope trust selection and saved hashes to the active config owner so a global config cannot trust or reconcile another config’s hooks. Recheck hooks.json after hooks/list to avoid trusting a handler from a stale position, and only report trusted or cleared actions after config/batchWrite succeeds. Keep v1 ownerless hashes cleanup-only so upgraded installs clear stale trust after hook removal without trusting foreign hooks.
Locate hooks using all records for their canonical file before selecting the active config owner, so identical hooks remain identifiable across shared and symlinked homes. Keep cleanup receipts for parked registrations whose native group still matches, including when duplicate counts make locate ambiguous, while clearing receipts for removed hooks. Add regressions for identical hooks across config owners, symlink aliases, parked-home restoration, ambiguous duplicates, and stale receipt cleanup.
Canonicalize current-owner and legacy trust receipts so symlink spellings of one hooks.json are processed once. Remove the redundant parked-position branch because the hash-matching fallback below covers it. Add regression coverage for current and legacy receipts.
a50ca32 to
c369ce7
Compare
|
Fixed in |
|
Verification: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c369ce709f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| firstKey := fmt.Sprintf("%s:session_start:%d:0", hooksPath, firstIndex) | ||
| secondKey := fmt.Sprintf("%s:session_start:%d:0", hooksPath, secondIndex) |
There was a problem hiding this comment.
Build the alias test's expected keys from the canonical home
On symlink-capable platforms, this subtest retains codex-alias/hooks.json in hooksPath, but TrustCodex now starts the fake server under the canonical home, and fakeCodexServer.ListHooks constructs keys from that home. Consequently, the assertion immediately below compares a .codex/hooks.json key against a codex-alias/hooks.json key and fails; the subsequent hash assertion uses the wrong prefix too. Canonicalize the path used for both expected keys so the required make check can pass. Go tests could not be run here because the devcontainer is unavailable.
AGENTS.md reference: AGENTS.md:L80-L81
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in eb992186bdbec67b43a410347f2426964146a19a. The shared-owner alias test now derives both expected native keys from the canonical hooks path. Related trust-key and receipt assertions also use canonical paths so a symlinked temporary-home prefix is handled consistently. Covered by TestCodexTrustLocatesIdenticalHooksAcrossConfigOwners, including its shared-path and symlink-alias cases.
| e.service.ConfigDirs["codex"] = alias | ||
| save(t, e.service, Mutation{Name: "owned", Entry: codexTrustEntry(t, "echo owned")}) |
There was a problem hiding this comment.
Avoid the alias resync in the coalescing test fixture
When this test changes the configured home to the alias, the existing ledger still contains the real .codex/hooks.json path. The subsequent save retains that path for planning, but planShared checks it against the new alias base, so checkPath returns an “outside” error and the helper fails before the coalescing assertions are reached. The duplicate receipts already exercise coalescing without this extra resync; remove that dependency on unsupported ledger-path migration so this new test does not block the required make check.
AGENTS.md reference: AGENTS.md:L80-L81
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in eb992186bdbec67b43a410347f2426964146a19a. TestCodexTrustCoalescesSymlinkedHomes now changes the home spelling only for trust reconciliation; it no longer resyncs the real-path ledger through an alias. The duplicate receipts still exercise coalescing, and the test retains its one-app-server and one-canonical-receipt assertions.
Follow-up e3afd64c6ee3be229bda690731032756d92ebebd fixes the CI assertion fixture: it decodes the reconciled on-disk JSON into a fresh state value, because json.Unmarshal into the seeded nonempty map retains deleted alias entries. The one-home, canonical-path and one-app-server assertions remain intact. Upstream Nix, unit and Docker-offline logs all identified that same fixture failure; exact-head Test run 43156808237 and Nix 43156808189 now pass, including the named regression.
| if path == "" { | ||
| continue | ||
| } | ||
| path = canonicalPath(path) |
There was a problem hiding this comment.
Canonicalize the home when hooks.json no longer exists
When reconciling real-path and symlink legacy receipts after removing the last hook from a Skillshare-created file, planShared deletes hooks.json. canonicalPath then cannot resolve the complete path and returns its original spelling, leaving the two receipts in separate groups despite their parent directories identifying the same home. Cleanup consequently starts Codex twice, and the newly added TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks fails its starts == 1 assertion. Resolve the existing parent directory and append hooks.json so missing-file cleanup coalesces too and the required make check can pass.
AGENTS.md reference: AGENTS.md:L80-L81
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in eb992186bdbec67b43a410347f2426964146a19a. canonicalCodexHooksPath resolves the hooks file when present and otherwise resolves its parent home before appending the filename. Trust grouping, active-home matching and receipt coalescing use that same boundary, including after the last hook file is removed. TestCodexTrustCoalescesLegacySymlinkedHomesForRemovedHooks retains its single-app-server assertion, alongside the active-owner coalescing and parked-home regressions.
Resolve existing home directories when hook files have been removed so trust receipts for symlink aliases reconcile once. Correct canonical key expectations and exercise coalescing without unsupported ledger migration.
|
@codex review Please review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
JSON decoding retains existing map entries, so reusing the seeded receipt map makes the alias appear to survive reconciliation. Decode the persisted state into a new value to verify its actual contents.
|
@runkids please check |
|
Thanks for the fixes since my last review. I re-reviewed the changes since a50ca32 (c369ce7, eb99218, e3afd64). The symlink coalescing and the removed redundant branch look right, and CI is green. Two things for the next round:
Verification: I read the delta and the Codex source; I did not run the tests locally. |
|
Thanks for all the work on this, and for turning the review rounds around so quickly. I'm going to take the branch from here and push the remaining changes myself, so you don't need to do the two items I asked for on the 15th. Your commits stay as they are. Please hold off on pushing to The direction:
flowchart TD
A["hooks sync --trust -g"] --> B["Write hook files, same as today"]
B --> C["Ask Codex for the trust status of the hooks Skillshare owns, per Codex home"]
C --> D{"Any hook new or changed?"}
D -- No --> E["Report unchanged, done"]
D -- Yes --> F["List those hooks with their commands"]
F --> G{"--yes given?"}
G -- Yes --> K["Record trusted_hash through Codex"]
G -- No --> H{"Terminal attached?"}
H -- No --> I["Trust nothing, exit with an error that names --yes"]
H -- Yes --> J{"Confirm once"}
J -- Yes --> K
J -- No --> L["Trust nothing"]
In the dashboard, the dialog takes the place of the terminal question. You asked for the clearing in #828, so if dropping it breaks something in your setup, tell me and I'll look at it again. |
…eipts file `hooks sync --trust` recorded trust for every owned hook without showing what it was trusting, and tracked its own writes in codex-trust.json so it could clear them later. Codex's review exists so that a person sees a command before it runs, and the receipts file was the source of most of the edge cases found in review. Trust is now two steps. A preview asks Codex which owned hooks are new or changed and returns them with their commands and a revision; the write takes that revision and is refused when the hooks changed since. The CLI lists the hooks and asks once, `--yes` skips the question, and without a terminal nothing is trusted unless `--yes` is given. The dashboard gets the same two steps as API routes. Nothing is cleared any more: a leftover entry only matches a hook with the same event, matcher and handler at that position, which is the hook the user already approved. That removes codex-trust.json. The app-server is started without CODEX_HOME for the default home. Codex resolves the symlinks of CODEX_HOME but not of ~/.codex, so a symlinked default home got a trust key the user's own Codex never looks up. A home whose write fails no longer stops the other homes, and the error names which were recorded. A preview releases the hooks operation lock before it waits on Codex, so a slow Codex does not fail other hooks operations. Refs runkids#828
The dashboard could sync Codex hooks but left them untrusted, so Codex skipped them until the user ran the CLI or approved each one in Codex. The Sync box now offers "Trust Codex hooks" in the global scope when a hook is bound to a Codex target. The dialog shows each hook that needs trust with its full command and records trust for exactly that list; a change since the list was shown is refused. The button is hidden while changes are pending, because trust covers the hooks on disk and the next sync would invalidate it. Refs runkids#828
…states Only the happy path was tested, so a regression in the states where the dialog must not offer a write would have passed. The docs sentence on several Codex homes now says what is isolated: a failed write, not a home that cannot be listed. Refs runkids#828
…he handlers hooks_handlers.go had grown past 500 lines and mixed orchestration with the confirmation prompt and every print function, which the CLI layering rule asks to keep apart. The code is moved unchanged: the prompt goes to hooks_prompt.go and the printing to hooks_render.go.
…topping With several Codex homes, one home Codex could not list aborted the whole trust run, so a broken account home kept every other home untrusted. A home that fails to list is now reported and left out, and the other homes are previewed and trusted as usual. The CLI warns before the question and exits with an error that names the home; the dashboard dialog shows the same note. When no home can be listed the preview still fails. Codex answers a home it cannot load, such as one with an invalid config.toml, with a successful reply that has no hooks and the reason in `errors`. That was read as a home without hooks and passed silently. It is now a failed listing that carries Codex's own message. Refs runkids#828
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65b5c9eb6b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if revision != plan.Revision { | ||
| return plan, fmt.Errorf("Codex hooks changed since they were listed: %w", ErrStaleRevision) |
There was a problem hiding this comment.
Preserve healthy-home progress when a re-list fails
When two homes have untrusted hooks in the preview but one fails its second hooks/list call during TrustCodex (for example, an app-server timeout after confirmation), the failed home's edits are omitted from needed, changing plan.Revision. This guard then returns ErrStaleRevision before any SetTrust, so the healthy home is not trusted and the actual listing error is masked. Both trustCodexHooks and CodexTrustDialog use this preview-then-apply flow, meaning failure isolation only works when the same homes fail in both passes. Validate the reviewed keys and hashes per home so a failed re-list can be reported without stopping unchanged, reviewed homes.
Useful? React with 👍 / 👎.
The revision was one digest over every home's hooks. When a home was listed in the preview but failed to list again at the write, its hooks dropped out of the digest, so the write was refused as stale: the homes the user had just reviewed stayed untrusted and the real listing error was hidden behind "changed since they were listed". The revision now has one part per home. A home is refused only when its own hooks changed; a home that cannot be listed any more is reported and the reviewed homes are still trusted. Refs runkids#828
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.10
The squash commit of #829 carries this footer in the middle of its message, followed by co-author trailers, so Release Please did not read it and moved the release to 0.31.0. Keep the next release on the patch version the maintainer asked for. Release-As: 0.30.10
Type
proposals/only — see CONTRIBUTING.md)approvedlabel)What changed
--trustflag onskillshare hooks sync, global mode only. After the sync writes, it asks Codex which of the hooks Skillshare owns are new or changed, in every Codex home it manages, account homes likecodex-2included.--yes(-y) skips the question. Without a terminal and without--yes, nothing is trusted and the command exits with an error that names--yes.--jsonnever asks: without--yesit reports the hooks asneededand exits non-zero. A hook that is already trusted needs no answer.codex app-serverper home,hooks/listfor each hook'scurrentHash, thenconfig/batchWriteonhooks.state."<key>".trusted_hash. Same calls the TUI's/hooksreview makes, so Skillshare never computes or guesses the hash.trusted_hashchanges.enabledand the rest ofconfig.tomlstay as they are; a Skillshare hook that's disabled in Codex is reported, not switched on. Hooks Skillshare doesn't own are never touched.config.toml. It only ever matches a hook with the same event, matcher and handler at that position, which is the hook the user already approved.~/.codexthe app-server is started withoutCODEX_HOME. Codex resolves the symlinks ofCODEX_HOMEbut not of~/.codex, so a symlinked default home used to get a trust key the user's own Codex never looks up.config.toml) inside a successful reply, and that is treated as a failed listing.POST /api/hooks/codex-trust/previewandPOST /api/hooks/codex-trust.codexisn't onPATHor the app-server fails, the hook files are still written and the command fails with "hook files were written, but Codex trust was not recorded".--jsonresults get acodexTrustlist.sync hooks,hooks listand project mode reject--trust. Plainhooks syncis unchanged and never starts Codex.Why
Codex won't run a user-level hook until it's trusted, and trust is keyed by the hook's position in
hooks.json. Only/hooksin the TUI writes it, so every hook Skillshare adds or moves starts untrusted andcodex execskips it silently. Today that means opening/hooksin every Codex home after every sync, or running with--dangerously-bypass-hook-trust, which trusts everything.feat-hooks-record-Codex-hook-trust-on-sync-with-trust.mp4
Usage
Needs
codexonPATH. Default is off.Closes #828
Not covered
.codex/hooks.json) andhooks.projectsroots. Their trust also depends on Codex trusting the project, so--trustrefuses project mode.config.toml(see above).--jsonmode the reason for a trust failure is not printed; the exit code and theneededrows are the signal. This is how every--jsonhooks result reports an error.Checks
On
65b5c9eb, inside the devcontainer:make checkpassed.python3 scripts/ai-context.py checkpassed.--yes --json: both homestrusted; a second run reports bothunchanged.config.toml: the default home is trusted, the account home is named in the error, exit code 1.codex-trust.jsonis created.Earlier on this branch, before the last three commits (the code paths they exercise did not change since), also against real Codex 0.167.0:
--yes: the commands are listed, the command fails, nothing is written.CODEX_HOMEunset: the key is written as~/.codex/...and the user's Codex reports the hooktrusted.Noleaves the hookmodified,Yesmakes ittrusted.Not done: the dashboard dialog has component tests but no browser screenshot, the interactive question has no automated test, and the website build was not run.
Checklist
make check)