Skip to content

fix(plugins): preserve mutable hook context - #97281

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
outdog-hwh:codex/fix-register-hook-context-75245
Jun 28, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
outdog-hwh:codex/fix-register-hook-context-75245

Conversation

@outdog-hwh

@outdog-hwh outdog-hwh commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #75245

What Problem This Solves

Fixes an issue where plugin registerHook() handlers could mutate the event.context object they received, but core would silently ignore those mutations when the handler ran through the plugin registry wrapper. In practice this broke agent:bootstrap plugins that replace bootstrapFiles: the plugin logged success, but child runs still received the original bootstrap file set.

Why This Change Was Made

The plugin registry wrapper now passes the original mutable hook context object to each handler, temporarily injects that handler's pluginConfig, and restores/removes pluginConfig in a finally block after the handler returns. That preserves the documented mutable hook contract while keeping per-handler config isolated so one plugin's config does not leak into later handlers.

AI-assisted: prepared with Codex and verified locally.

User Impact

Plugins that intentionally mutate hook context now work the way the hook contract and docs imply they should. For agent:bootstrap, bootstrap file replacements/removals now survive into the final injected context used by the agent run, while pluginConfig remains visible only to the owning handler.

Evidence

  • node scripts/run-vitest.mjs src/plugins/loader.test.ts -t "injects plugin config into internal hook event context"
  • node scripts/run-vitest.mjs src/plugins/loader.test.ts -t "preserves plugin hook context mutations for bootstrap hooks"
  • node scripts/run-vitest.mjs src/plugins/loader.test.ts -t "runs consecutive plugin hook handlers with shared mutable context but isolated plugin config"
  • node scripts/run-vitest.mjs src/agents/bootstrap-hooks.test.ts
  • npm run tsgo:test:src
  • node scripts/run-oxlint.mjs src/plugins/registry.ts
  • node_modules\.bin\oxfmt.cmd --check --threads=1 src/plugins/registry.ts src/plugins/loader.test.ts
  • git diff --check

Real loader proof with temporary local plugins loaded through loadOpenClawPlugins and redacted paths:

[proof] loaded plugins via loadOpenClawPlugins: hook-bootstrap-proof, hook-context-first, hook-context-second
[proof] bootstrap before: AGENTS.md, SOUL.md
[proof] bootstrap after: SENTINEL.md
[proof] sentinel content: SENTINEL_BOOTSTRAP_CONTEXT
[proof] startup messages: first-config=visible-to-first | second-config=visible-to-second | note=mutation-from-first
[proof] startup final context keys: note
[proof] PASS registerHook mutable context propagation and pluginConfig cleanup

Not run:

  • broader pnpm check / pnpm check:changed lanes were not run in this worktree; focused source tests, lint/format, and tsgo:test:src were used instead.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@clawsweeper

clawsweeper Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 27, 2026, 1:41 PM ET / 17:41 UTC.

Summary
The PR changes the plugin registry hook wrapper to pass the original mutable hook context while temporarily injecting and restoring per-handler pluginConfig, with loader regression tests for bootstrap mutation propagation and config isolation.

PR surface: Source +12, Tests +159. Total +171 across 2 files.

Reproducibility: yes. Source inspection shows current main clones plugin hook context while documented bootstrap hooks expect mutable context and the bootstrap consumer reads the original event after dispatch.

Review metrics: 1 noteworthy metric.

  • Plugin hook contract behavior: 1 behavior changed. The PR changes whether external api.registerHook handlers receive the original mutable context object or a cloned context.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #75245
Summary: This PR is the active candidate fix for the canonical mutable registerHook context bug; older similar PRs are closed unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] The PR intentionally changes external api.registerHook context identity and mutation propagation; maintainers should accept shared mutable hook context with per-handler pluginConfig cleanup as the compatibility direction before merge.

Maintainer options:

  1. Accept mutable context with cleanup (recommended)
    Merge after maintainers accept that plugin hook handlers may mutate the shared event context while pluginConfig remains scoped and restored in finally.
  2. Pause for immutable hook API design
    If maintainers do not want shared mutable hook context as the plugin contract, pause this PR and design an explicit return-value or context-patch API with migration guidance.

Next step before merge

  • [P2] Maintainer review is needed for the mutable registerHook context compatibility direction; no narrow automated repair remains after the lint fix and proof update.

Security
Cleared: The diff is limited to in-process plugin registry behavior and tests; it adds no dependency, workflow, permission, secret, install, package, or downloaded-code surface.

Review details

Best possible solution:

Land the focused registry-wrapper repair after maintainer acceptance of the mutable hook-context contract and normal exact-head CI completion.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main clones plugin hook context while documented bootstrap hooks expect mutable context and the bootstrap consumer reads the original event after dispatch.

Is this the best way to solve the issue?

Yes, pending maintainer compatibility acceptance. Fixing the generic registry wrapper is narrower than a bootstrap-only workaround or field-by-field merge, and the finally cleanup addresses the pluginConfig leakage concern that caused the clone.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1bdde6695030.

Label changes

Label justifications:

  • P2: The PR fixes a source-reproducible plugin hook contract bug with bounded registry and loader-test scope.
  • merge-risk: 🚨 compatibility: The diff intentionally changes context object identity and mutation propagation observed by external api.registerHook handlers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes redacted after-fix live output from temporary plugins loaded through loadOpenClawPlugins, showing mutation propagation and pluginConfig cleanup.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted after-fix live output from temporary plugins loaded through loadOpenClawPlugins, showing mutation propagation and pluginConfig cleanup.
Evidence reviewed

PR surface:

Source +12, Tests +159. Total +171 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 15 3 +12
Tests 1 159 0 +159
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 174 3 +171

What I checked:

  • Root and scoped policy read: Root AGENTS.md and scoped src/plugins and src/agents AGENTS.md were read; plugin loader/registry behavior is compatibility-sensitive and must align with the public Plugin SDK contract. (AGENTS.md:18, 1bdde6695030)
  • Current main wrapper drops mutation identity: Current main wraps plugin hook handlers with a shallow-copied context, so assignments to event.context fields happen on the clone rather than the original event context. (src/plugins/registry.ts:743, 1bdde6695030)
  • Hook runner dispatches one event sequentially: triggerInternalHook awaits each handler with the same event object in registration order, so the registry wrapper is the layer changing plugin-visible context identity. (src/hooks/internal-hooks.ts:298, 1bdde6695030)
  • Bootstrap consumer expects readback: applyBootstrapHookOverrides creates one hook event, triggers hooks, then reads event.context.bootstrapFiles, establishing the source-level failure path for cloned plugin contexts. (src/agents/bootstrap-hooks.ts:31, 1bdde6695030)
  • Public hook docs support mutable context: The automation hook docs describe agent:bootstrap context.bootstrapFiles as a mutable array. Public docs: docs/automation/hooks.md. (docs/automation/hooks.md:142, 1bdde6695030)
  • PR implementation preserves mutation and cleanup: PR head reuses evt.context, sets context.pluginConfig for the handler, and restores or deletes pluginConfig in a finally block. (src/plugins/registry.ts:743, 2d7f2a5597bc)

Likely related people:

  • Ayumi Server: Authored the change from in-place pluginConfig injection to shallow-copy context isolation, which explains the current lost-mutation behavior. (role: introduced wrapper behavior; confidence: high; commits: ed0b098d7596, c1187109c8fb; files: src/plugins/registry.ts)
  • steipete: Authored the bootstrap hook path and committed the wrapper-isolation change that this PR revises. (role: feature-history owner and committer; confidence: high; commits: ad3c12a43a70, c1187109c8fb; files: src/agents/bootstrap-hooks.ts, src/hooks/internal-hooks.ts, src/plugins/registry.ts)
  • 100yenadmin: Co-authored the generic plugin host-hook contract work and opened the canonical issue with real-run evidence for this behavior. (role: adjacent plugin hook contract contributor; confidence: medium; commits: 1adaa28dc86b; files: docs/plugins/hooks.md, src/plugins/types.ts, src/plugins/registry.ts)
  • vincentkoc: Current-line blame for the registry and bootstrap hook code points to a recent main merge/reapply, useful for current-main provenance but not the root cause by itself. (role: recent current-line contributor; confidence: medium; commits: ff1837429300; files: src/plugins/registry.ts, src/agents/bootstrap-hooks.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 27, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 27, 2026
@vincentkoc
vincentkoc merged commit 35fcfe8 into openclaw:main Jun 28, 2026
120 of 128 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
* fix(plugins): preserve mutable hook context

* fix(plugins): satisfy hook context lint
@outdog-hwh
outdog-hwh deleted the codex/fix-register-hook-context-75245 branch June 29, 2026 08:58
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
* fix(plugins): preserve mutable hook context

* fix(plugins): satisfy hook context lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registerHook wrapper drops mutable context changes for agent:bootstrap hooks

2 participants