Skip to content

fix(spawn): inline --settings hooks must use DISPATCHED_EVENT_MATCHERS too (Fix D completion) - #1513

Merged
namastex888 merged 2 commits into
devfrom
fix/inline-settings-narrow-matchers
Apr 29, 2026
Merged

namastex888 merged 2 commits into
devfrom
fix/inline-settings-narrow-matchers

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

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

  1. inject.ts:injectIntoFile — writes ~/.claude/teams/<team>/settings.json for native teams. Already narrowed via DISPATCHED_EVENT_MATCHERS in fix(hooks): narrow inject matchers — Mac CPU fix D #1479 ✓
  2. provider-adapters.ts:buildSettingsObject — emits inline --settings JSON to the claude CLI at spawn time. Still hardcoded the wide matchers ❌

Every spawn was still wiring PostToolUse:*, UserPromptSubmit, and Stop for inline-settings-driven sessions, defeating Fix D for the spawn-time path.

Fix

buildSettingsObject now sources DISPATCHED_EVENT_MATCHERS from hooks/types.js and iterates it. Both layers stay aligned when the matcher map is updated.

Empirical

$ bun run src/genie.ts spawn engineer --provider claude --model opus --no-interactive
... --settings ...PostToolUse:[{matcher:"SendMessage"}]...

(was PostToolUse:[{matcher:"*"}] + extra UserPromptSubmit/Stop entries before)

Evidence

dog-fooder-da66 verdict 2026-04-29 — state/phaseb-413-20260429T143731Z/

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

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e7836152-37c9-49ba-80d9-46a46ea37c89

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inline-settings-narrow-matchers

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist 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.

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>
@namastex888
namastex888 merged commit 8bcfc8e into dev Apr 29, 2026
11 checks passed
@automagik-genie
automagik-genie deleted the fix/inline-settings-narrow-matchers branch September 25, 2026 04:52
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.

1 participant