fix(spawn): inline --settings hooks must use DISPATCHED_EVENT_MATCHERS too (Fix D completion) - #1513
Conversation
…S too (Fix D completion) dog-fooder-da66 verdict 2026-04-29 surfaced that #1479 (Mac CPU Fix D — narrow inject matchers) only narrowed ONE of TWO injection layers. The team-level ~/.claude/teams/<team>/settings.json injection done by inject.ts:injectIntoFile was correctly narrowed. But provider-adapters.ts:buildSettingsObject — which emits an INLINE --settings JSON to the claude CLI command at spawn time — still hardcoded the wide matchers: PreToolUse: matcher='*' (correct, has handlers) PostToolUse: matcher='*' (WRONG, only SendMessage handler exists) UserPromptSubmit: wired (WRONG, no handlers in DISPATCHED_EVENT_MATCHERS) Stop: wired (WRONG, same) Net effect: every spawn-time --settings injection still wired the wasted matchers, so claude sessions still spawned bun-fork hook dispatchers for PostToolUse:Bash/Read/Write/Edit, UserPromptSubmit, and Stop — all going through the F1 fallback path with no useful work. Fix: source DISPATCHED_EVENT_MATCHERS from hooks/types.js (lazy require to avoid import cycles) and iterate it to build the hooks object. Both layers now stay aligned automatically when the matcher map is updated. Empirical (post-fix): bun run src/genie.ts spawn engineer --provider claude --model opus --no-interactive → emitted --settings now contains PostToolUse:[{matcher:"SendMessage"}] → UserPromptSubmit and Stop entries removed entirely Evidence (from da66 verdict): /home/genie/workspace/agents/genie/.genie/agents/dog-fooder/state/phaseb-413-20260429T143731Z/ Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Code Review
This pull request updates the buildSettingsObject function in src/lib/provider-adapters.ts to dynamically source hook matchers from DISPATCHED_EVENT_MATCHERS. This change ensures that the inline --settings codepath used during CLI spawn remains consistent with the team-level configuration, replacing previously hardcoded wide matchers. I have no feedback to provide as the implementation correctly addresses the alignment discrepancy.
…lowup) dog-fooder-da66 verdict 2026-04-29 found a THIRD injection layer with the same wide-matcher leak after my first commit fixed two: 1. inject.ts:injectIntoFile (claude team settings.json) — fixed in #1479 2. provider-adapters.ts:buildSettingsObject (claude inline --settings) — fixed in this PRs first commit 3. codex-inject.ts:buildCodexHookFragment (~/.codex/config.toml) — STILL leaking SessionStart, PermissionRequest with matcher='*' even though no handlers exist Fix: - New CODEX_DISPATCHED_EVENT_MATCHERS in hooks/types.ts mirrors the claude DISPATCHED_EVENT_MATCHERS but is wider — codex has handlers for UserPromptSubmit (codex-inbox-deliver) and Stop (runtime-emit-assistant-response) that claude does not have. - Codex matchers: PreToolUse:*, PostToolUse:SendMessage, UserPromptSubmit:*, Stop:* - Dropped SessionStart + PermissionRequest (no handlers). - codex-inject.ts:CODEX_DISPATCHED_EVENTS now derived from the matcher map so list and matchers can never drift. - Test updated to assert the new contract + added matcher narrowing assertion. All 3 injection layers now sourced from the same matcher maps. Validation: 7/7 codex-inject tests pass. tsc clean. biome clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Surfaced by dog-fooder-da66 in 4.260429.13 Phase B verification — #1479 (Fix D narrow matchers) only landed in ONE of TWO injection layers.
Two-layer injection problem
inject.ts:injectIntoFile— writes~/.claude/teams/<team>/settings.jsonfor native teams. Already narrowed via DISPATCHED_EVENT_MATCHERS in fix(hooks): narrow inject matchers — Mac CPU fix D #1479 ✓provider-adapters.ts:buildSettingsObject— emits inline--settingsJSON to the claude CLI at spawn time. Still hardcoded the wide matchers ❌Every spawn was still wiring
PostToolUse:*,UserPromptSubmit, andStopfor inline-settings-driven sessions, defeating Fix D for the spawn-time path.Fix
buildSettingsObjectnow sourcesDISPATCHED_EVENT_MATCHERSfromhooks/types.jsand iterates it. Both layers stay aligned when the matcher map is updated.Empirical
(was
PostToolUse:[{matcher:"*"}]+ extra UserPromptSubmit/Stop entries before)Evidence
dog-fooder-da66 verdict 2026-04-29 —
state/phaseb-413-20260429T143731Z/