Repository navigation
fix(hooks): type untyped flat command handlers for Codex - #3385
Daniel Meppiel (danielmeppiel) merged 3 commits into
Conversation
|
Thank you for contributing this Codex hook correction. Issue #3249 has a current maintainer-approved scope record for flat command handlers and owned legacy-output repair. The requested reviewers include Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam). This is a recommendation for human review only, not merge approval. Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors. |
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Shared default-type helper and legacy-shape ownership matching are correct, minimal, and respect single-canonical-owner discipline. |
| Test Coverage Expert | 0 | 1 | 0 | Unit + contract-guard + lifecycle coverage is strong; denied consent is not exercised with untyped flat Codex hooks. |
| Doc Writer | 0 | 2 | 0 | Hook doc matches the code; fix the CHANGELOG entry format and tighten the apm-guide wording. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Test Coverage Expert] Add a denied-consent assertion for untyped flat Codex hook input in installed-CLI lifecycle coverage. -- The approved scope names "preserve denied-consent behavior"; no test proves it for the new input shape.
- [Doc Writer] Fix the CHANGELOG entry: merge into the existing Fixed heading and end with
-- by @Parth-Vasave (#3385). -- Repo convention requires the PR number; the main merge also left a duplicate Fixed section under [Unreleased]. - [Doc Writer] Align the apm-guide package-authoring section with the hooks doc: state the shared flat-command default and that nested source groups must supply
type. -- The guide is the agent-facing authoring surface and currently omits the nested-group instruction.
Recommendation
Ship after the three recommended items are folded -- the denied-consent test gap, the CHANGELOG format fix, and the apm-guide alignment. All three are in-scope and bounded; the merge worker is folding them into this PR. The code itself is clean per architecture review and well covered by unit, contract and lifecycle tests. No blocking findings.
Full per-persona findings
Python Architect
No findings.
Test Coverage Expert
- [recommended] Denied-consent path not tested with untyped flat Codex hook input at
tests/integration/test_hook_path_package_lifecycle.py:315
The existing denied-consent block exercisesallowExecutables={}for Codex with a typed nested descriptor only. The gate is upstream of rendering, so risk is low, but the approved scope lists it explicitly.
Suggested: Consumer withallowExecutables={}, install the untyped flat source, assert no.codex/hooks.json, no hook-executed sentinel,exec_statusgated_pending_approval.
Proof (missing at):tests/integration/test_hook_path_package_lifecycle.py::test_hook_path_install_restore_update_remove-- proves: denied consent prevents hook deployment for untyped flat Codex hooks [secure-by-default]
Doc Writer
- [recommended] CHANGELOG entry ends with
(closes #3249)instead of(#3385)and adds a second### Fixedheading under [Unreleased] atCHANGELOG.md:10
changelog.instructions.mdrequires-- by @username (#PR_NUMBER); one heading per type.
Suggested: Move the bullet into the existing Fixed list and end it with-- by @Parth-Vasave (#3385). - [recommended] apm-guide repeats the type-default rule per target, names the nested scope inconsistently, and omits "supply type yourself in nested groups" at
packages/apm-guide/.apm/skills/apm-usage/package-authoring.md:235
The code checks nesting in the source entry for both targets; the docs page already says so.
Suggested: One paragraph stating the shared flat-command default, per-target wrapping, and that nested source groups must supplytype.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Codex's HookHandlerConfig is an internally tagged enum (#[serde(tag = "type")]) with no default, so the nested handler APM generated from a flat command entry without `type` matched no variant. Share the flat-command type default introduced for Claude in microsoft#3153 with the Codex renderer: untyped flat command entries now render as `"type": "command"` handlers in .codex/hooks.json, including when they join existing groups. Explicit types, non-command entries and handlers already nested in the source are unchanged, as are other targets. Ownership matching on reinstall and update now recognises both earlier Codex shapes APM wrote (the original flat entry and the nested untyped group), so proven APM-owned output converges to one typed entry. Manual and unowned hooks are not rewritten or removed. Fixes microsoft#3249
Address review panel follow-ups on microsoft#3385: - Add an installed-CLI lifecycle test proving that with allowExecutables={} an untyped flat Codex hook source deploys no .codex/hooks.json, runs nothing, and records exec_status gated_pending_approval; after approval it renders a typed handler. - Merge the CHANGELOG bullet into the existing [Unreleased] Fixed list and credit the PR number. - Collapse the apm-guide Claude/Codex paragraphs into one shared flat-command default and state that nested source groups must supply type.
22ed02d to
9797ba1
Compare
|
Thanks for the review. I've addressed all three follow-ups in 9797ba1 and rebased onto
|
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Test Coverage Expert | 0 | 0 | 0 | Prior denied-consent follow-up closed by the new lifecycle test; #3249 done-when criteria covered. |
| Doc Writer | 0 | 0 | 0 | Both prior doc follow-ups resolved and accurate against the renderer. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
All three follow-ups from the lean advisory are folded, both re-spawned panelists return zero findings, and CI is green. Ship. The pre-existing approve-key identity mismatch for aliased github-hosted dependencies is worth a separate issue but is outside #3249 scope and does not affect this PR.
Full per-persona findings
Test Coverage Expert
No findings.
Doc Writer
No findings.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Bring PR microsoft#3385 up to date with main. Clean merge; main's CHANGELOG entries preserved and the microsoft#3385 entry stays in Unreleased Fixed. Co-authored-by: Copilot App <[email protected]>
|
Merged current main into this branch at 2b14652 -> eda49ca (merge-of-main fallback, since the branch history already contains merge-from-main commits; no history rewrite). Conflicting paths: none. Lint contract: Exact-head evidence at eda49ca:
Post-push mergeability: Ready for maintainer review. Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors. |
29f323b
into
microsoft:main
Description
A flat hook entry may omit
type(Cursor defaults it tocommand). APM already wraps such entries in Codex's{ "matcher", "hooks": [...] }groups, but the generated handler had notype. In the pinned Codex source (hook_config.rsat36512a34),HookHandlerConfigis#[serde(tag = "type")]with no default, so an untyped handler matches no variant.This is the Codex counterpart of #3130 / #3153. It reuses the renderer and ownership code merged there; there is no second implementation.
_with_default_command_type) also runs in_to_codex_hook_entries. Untyped flat command entries render as"type": "command"in.codex/hooks.jsonand its sidecar, including when they join groups from a Codex-shaped hook file in the same package.command,prompt,mcp_tool), untyped non-command entries, handlers already nested in the source, matchers, timeouts, and other targets (Cursor and Gemini are checked by a guard test)._legacy_hook_entriesfor Codex now returns both earlier shapes APM wrote: the original flat entry (before fix(hooks): render Codex hooks in native shape #3060) and the nested untyped group. Proven APM-owned output, including stale root-package sources healed by content match, therefore converges to one typed entry on reinstall andapm update. Hooks with no ownership record are never rewritten or removed, even when they are byte-identical to old APM output.Before (from the issue):
{ "matcher": "Write", "hooks": [ { "command": "node \".codex/hooks/demo-pkg/.apm/hooks/scripts/gate.mjs\"", "timeout": 10 } ] }After:
{ "matcher": "Write", "hooks": [ { "type": "command", "command": "node \".codex/hooks/demo-pkg/.apm/hooks/scripts/gate.mjs\"", "timeout": 10 } ] }Evidence and its limits: this establishes that the generated output matches Codex's source schema. I have not observed a Codex runtime rejecting the old output or accepting the new output.
Issue and approved scope
Issue: #3249
Human scope-approval comment: #3249 (comment) (clarified in #3249 (comment))
This PR completes the approved scope. Out of scope, as agreed: defaults inside already-nested source handlers, camelCase event-name mapping, a shared default across all targets, guessing non-command types, and #2111.
Fixes #3249
Type of change
Testing
New and updated tests:
tests/unit/integration/test_hook_integrator_issue3249.py(14 cases):9 of these fail without the fix. If only the new nested-untyped legacy matching is removed, the stale-root case fails.
test_required_codex_untyped_hook_upgrade_preserves_ownership_and_convergesruns the installed CLI with{standalone, merged} × {nested-untyped, flat}legacy output. It covers first install, two reinstalls andapm updateto a new revision, and checks that:.apmsources are unchanged;All 4 variants fail without the fix.
test_codex_native_edge_types_untyped_flat_commandscovers the renderer and the legacy shapes.In the [BUG] Flat hook entries without
typereach.claude/settings.jsonwithout the requiredtype: command#3130 suite, the guard asserting Codex did not get the default now targets Cursor and Gemini.Run locally, mirroring
ci.yml:relative_tochecks, pylint R0801, and the auth-signal and architecture-boundary linters.apm audit --ci.Not run locally: the Windows jobs and the PyInstaller-built binary (I used the dev install's
apm).Docs:
hooks-and-commands.mdand the apm-guidepackage-authoring.mdnow describe the Claude and Codex input/output contract. The CHANGELOG has an entry under Unreleased.Spec conformance (OpenAPM v0.1)