Repository navigation
fix(plugins): scope Codex relay with tool matchers - #109603
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 1:15 PM ET / 17:15 UTC. ClawSweeper reviewWhat this changesThis PR adds optional canonical tool-name matchers to plugin tool hooks, trusted tool policies, and tool-result middleware, then uses their combined scope to prevent Codex from spawning native relay processes for unrelated tools. Merge readinessKeep this PR open for maintainer review. The latest branch repairs the earlier alias and mixed-runtime scope blockers, preserves unscoped match-all behavior, and includes credible real Codex relay proof; the remaining blocker is confirming that an exact tool-name matcher is the intended permanent public contract across three plugin APIs. Priority: P1 Review scores
Verification
How this fits togetherPlugin registrations feed the active hook and policy registries used during agent tool calls. For Codex app-server sessions, the relay adapter projects the active registrations into Codex hook configuration so Codex can skip launching an OpenClaw relay process when no registered local behavior covers that tool. flowchart LR
A[Plugin hook or policy registration] --> B[Matcher validation]
B --> C[Active plugin registries]
C --> D[Combined event matcher scope]
D --> E[Codex native hook configuration]
E --> F[Codex tool call]
F --> G{Tool matches scope?}
G -->|Yes| H[OpenClaw relay and local policy]
G -->|No| I[No relay process]
Decision needed
Why: The implementation is intentionally shared across three public registration surfaces, so maintainers must choose the permanent SDK semantics before merge; tests can verify the selected contract but cannot choose it. Before merge
Agent review detailsSecurityNone. PR surfaceSource +413, Tests +536, Docs +9. Total +958 across 27 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt the matcher as a runtime-neutral plugin contract only if the relay owners approve its canonical-ID semantics, then refresh the branch on current main and merge after exact-head checks confirm the documented live Codex behavior. Do we have a high-confidence way to reproduce the issue? No independent current-main run was possible in this review environment because read-only shell execution failed. The PR supplies a concrete exact-head Codex 0.146.0 process-count reproduction path and source-level tests for matcher selection, alias normalization, and paired runtime scopes. Is this the best way to solve the issue? Unclear pending maintainer direction: the implementation is a narrow, coherent fix for relay fan-out and appears to repair prior review blockers, but only maintainers can decide whether the shared public matcher API is the intended long-term product boundary. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against a47d81e7b33b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
a9167eb to
d1065f2
Compare
9635fda to
a6a2d42
Compare
a6a2d42 to
c45c06c
Compare
c45c06c to
35a8de1
Compare
c5ff6ad to
c2c0bce
Compare
Preserve contributor branch ancestry while replaying the reviewed matcher implementation.
|
Merged via squash.
|
* commit 'e80fe942c8dae4b264acb2b501466224e842aa61': fix(gateway): stop start-time repair from retargeting managed services (openclaw#115935) fix(plugins): scope Codex relay with tool matchers (openclaw#109603) fix(discord): bound webhook send body reads (openclaw#109076) fix(ui): preserve initials for missing user avatars (openclaw#115976) feat(ui): add provider icons to coding catalogs (openclaw#115956) fix(daemon): refuse duplicate launchd gateway managers (openclaw#97285) fix(memory-lancedb): share the recall cooldown with the auto-recall prompt-build hook (openclaw#112927) fix(test): isolate plugin install fixtures (openclaw#116008) fix(feishu): guard Object.assign against prototype pollution in webhook payload merge (openclaw#111729) fix(sms): isolate validated webhook quotas per sender (openclaw#104862) fix(sessions): recover deleted chats without endless retries (openclaw#115974) fix(restart): log errors from restart hook callbacks instead of swallowing (openclaw#108847) feat(ui): enable tool-loop detection from Labs (openclaw#115983) fix(telegram): catch unhandled rejections in webhook and ingress worker shutdown (openclaw#100998) fix(memory): keep rollbacks compatible after recall metadata upgrade (openclaw#116003)
* origin/main: refactor(agents): remove retired Codex CLI parser (openclaw#116017) feat(mac): hand off gateway-owned settings panes to the dashboard (openclaw#115999) fix(gateway): declare viewer presence explicitly instead of deriving it from subscriptions (openclaw#116001) test(plugins): include dreaming sidecar in startup expectation (openclaw#116018) fix(openai): prevent GPT-Live errors from stalling (openclaw#115582) fix(gateway): stop start-time repair from retargeting managed services (openclaw#115935) fix(plugins): scope Codex relay with tool matchers (openclaw#109603)
* origin/main: (823 commits) fix(memory): return early for blank searches (openclaw#116034) fix(tool-search): long-lived gateways leak heap from finished embedded runs (openclaw#114767) feat(harness): report copilot code-mode engagement on the attempt result (openclaw#115913) fix(ui): compact the macOS gateway picker menu (openclaw#115977) perf(codex): stream large CLI session JSONL scans (openclaw#115997) cron: reject webhook URLs with embedded credentials (openclaw#51822) refactor(agents): remove retired Codex CLI parser (openclaw#116017) feat(mac): hand off gateway-owned settings panes to the dashboard (openclaw#115999) fix(gateway): declare viewer presence explicitly instead of deriving it from subscriptions (openclaw#116001) test(plugins): include dreaming sidecar in startup expectation (openclaw#116018) fix(openai): prevent GPT-Live errors from stalling (openclaw#115582) fix(gateway): stop start-time repair from retargeting managed services (openclaw#115935) fix(plugins): scope Codex relay with tool matchers (openclaw#109603) fix(discord): bound webhook send body reads (openclaw#109076) fix(ui): preserve initials for missing user avatars (openclaw#115976) feat(ui): add provider icons to coding catalogs (openclaw#115956) fix(daemon): refuse duplicate launchd gateway managers (openclaw#97285) fix(memory-lancedb): share the recall cooldown with the auto-recall prompt-build hook (openclaw#112927) fix(test): isolate plugin install fixtures (openclaw#116008) fix(feishu): guard Object.assign against prototype pollution in webhook payload merge (openclaw#111729) ...
* fix(plugins): scope Codex relay matchers Co-authored-by: Masato Naka <[email protected]> * fix(plugins): reject sparse tool hook matchers * test(plugins): cover mixed relay matcher scopes * fix(plugins): fail closed on invalid policy matchers * test(plugins): prove composed relay policy scope * fix(plugins): keep matcher scope internal * fix(plugins): satisfy matcher static checks * fix(plugins): enforce canonical tool hook matchers * fix(codex): project native hook matcher aliases * fix(plugins): scope Codex relay with tool matchers * chore: keep release changelog maintainer-owned --------- Co-authored-by: Vincent Koc <[email protected]>
Closes #109522
What Problem This Solves
Codex app-server tool calls can spawn
openclaw hooks relayfor every tool once any tool hook, trusted tool policy, or tool-result middleware is registered, even when the registration only applies to one tool. On constrained hosts, that unnecessary relay fan-out contributes to the process and memory pressure tracked in #91009.Why This Change Was Made
Adds an optional exact tool-name matcher to the three tool-scoped registration surfaces:
api.on("before_tool_call" | "after_tool_call", handler, { matcher })registerTrustedToolPolicy({ matcher })registerAgentToolResultMiddleware(handler, { matcher })One canonical matcher implementation now owns dispatch filtering, trusted-policy identity, tool-result middleware filtering, and the Codex native relay configuration. OpenClaw/Codex aliases such as
exec,Bash, andexec_command, plusapply_patch,Write, andEdit, normalize through the same table.Omitted, empty, and wildcard matchers preserve the existing match-all contract. Malformed runtime matcher values are rejected instead of silently broadening a scoped registration to match all. The final validation fix also rejects sparse arrays: JavaScript array iteration had skipped holes, allowing an invalid matcher collection to reach the native relay. Custom tool names are escaped and anchored before being forwarded as a Codex regex.
User Impact
Plugins that scope tool hooks can avoid relay processes for unrelated tool calls without weakening policy coverage. Existing unscoped registrations remain match-all.
Evidence
Exact head:
9d6b7eda8ec0d8f9fd62e390f0b6573b35956a7fbefore_agent_replyeligibleTriggerscontract and legacy-hook registration ownership while composing independent tool matcher filtering. The rebased tree passed 216 focused tests; a final 95-test conflict-surface smoke passed after the last conflict-free main replay.git diff --checkpassed. The release-owned root changelog entry was removed; release-note context remains in this PR body.c2c0bce881f10a07c1e770646213e4e2446a8315:before_tool_callmatcher["exec_command"]produced native matcherBash|exec|exec_command.bash: relayed exactly once and completed.apply_patch: zero relay hook processes.rust-v0.145.0(annotated tag1635de866c61d1b76e50b31928ee6d61482435a8, source commit25af12f7e61572b0bc18ddb1008be543b91519b0):codex-rs/hooks/src/events/common.rs: omitted, wildcard, and empty matchers are match-all; exact alternatives support|.codex-rs/hooks/src/engine/dispatcher.rs: matching handlers are selected once before execution.codex-rs/hooks/src/engine/command_runner.rs: selected handlers spawn piped child processes with kill-on-drop and timeout handling.codex-rs/hooks/src/events/pre_tool_use.rs: no matching handler returns without spawning a hook process.codex-rs/core/src/tools/hook_names.rs: shell and patch identities include the expected aliases.codex-rs/core/src/hook_runtime.rsandcodex-rs/app-server/src/bespoke_event_handling.rs: hook started/completed events are emitted and forwarded through app-server notifications.Current-Main Codex 0.146.0 Proof
Exact head:
9d6b7eda8ec0d8f9fd62e390f0b6573b35956a7fBase replayed:
c6dfee1b78b465ff858fdb6396537d7c2227b36fThe proof used an actual Codex app-server
0.146.0, the generatedopenclaw hooks relaycommand, and a local mock Responses endpoint. The disposable exact-head build passed; all changed files passed formatting andgit diff --check.Direct dependency contract inspected at Codex tag
rust-v0.146.0, commite363b08c9175ac1cbe5893615dd2cb9ddf95043b:codex-rs/hooks/src/events/common.rscodex-rs/hooks/src/engine/dispatcher.rscodex-rs/hooks/src/events/pre_tool_use.rscodex-rs/core/src/tools/hook_names.rscodex-rs/app-server/src/bespoke_event_handling.rsFocused Vitest and oxlint replay on this head were queued behind the repository's active maintainer prepare gate; the pre-replay identical patch had 221 focused tests and exact-head CI green. The release-owned root changelog entry was removed; release-note context remains in this PR body. Fresh hosted CI is required for this pushed head.