Skip to content

fix(plugins): preserve hook context mutations - #77349

Closed
xuruiray wants to merge 1 commit into
openclaw:mainfrom
xuruiray:codex/75245-preserve-hook-context
Closed

xuruiray wants to merge 1 commit into
openclaw:mainfrom
xuruiray:codex/75245-preserve-hook-context

Conversation

@xuruiray

@xuruiray xuruiray commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #75245.

Summary

  • preserve the original internal hook context while injecting pluginConfig for the active plugin handler
  • restore or remove pluginConfig after the handler so config stays scoped
  • add a loader regression test for agent:bootstrap plugins mutating bootstrapFiles

Testing

  • pnpm test src/agents/bootstrap-hooks.test.ts src/agents/bootstrap-files.test.ts src/plugins/loader.test.ts
  • pnpm exec oxfmt --check --threads=1 src/plugins/registry.ts src/agents/bootstrap-hooks.test.ts src/agents/bootstrap-files.test.ts src/plugins/loader.test.ts CHANGELOG.md
  • pnpm check:changed

Real behavior proof

  • Behavior or issue addressed: Plugin agent:bootstrap hooks can mutate the original hook context while pluginConfig remains visible only during the active plugin handler.
  • Real environment tested: Local OpenClaw plugin loader/runtime from this PR branch (OpenClaw 2026.5.4, commit b92440d) using a temporary on-disk plugin with an agent:bootstrap hook.
  • Exact steps or command run after this patch:
    node --import tsx --input-type=module
    # Created a temp plugin with openclaw.plugin.json, loaded it via plugins.load.paths,
    # triggered agent:bootstrap, and printed the mutated bootstrapFiles plus post-hook context state.
  • Evidence after fix: Console output from the node command:
    loadedPlugins=bootstrap-context-mutator:loaded
    hooks=bootstrap-context-mutator:agent:bootstrap
    diagnostics=
    hook running marker=plugin-config-visible
    bootstrapFiles=AGENTS.md:base,PLUGIN.md:plugin-config-visible
    pluginConfigPresentAfterHook=false
    
  • Observed result after fix: The real plugin hook appended PLUGIN.md to bootstrapFiles, read pluginConfig.marker during execution, and pluginConfig was removed from the shared context after the hook returned.
  • What was not tested: No packaged third-party plugin was installed from npm; the proof uses a temporary local plugin loaded through the normal OpenClaw plugin loader path.

@clawsweeper

clawsweeper Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The branch changes the plugin registry hook wrapper to pass the original event context with scoped pluginConfig cleanup, adds a loader regression test, and adds a changelog entry.

Reproducibility: yes. at source level. A plugin loaded through api.registerHook('agent:bootstrap') can assign event.context.bootstrapFiles, but current main passes a cloned context while bootstrap resolution later reads the original event context.

Real behavior proof
Sufficient (live_output): The PR body includes after-fix live console output from a local plugin-loader run showing the plugin appended PLUGIN.md and pluginConfigPresentAfterHook=false.

Next step before merge
This is a normal open implementation PR with sufficient proof and no blocking review findings; the remaining action is maintainer review and merge gating rather than a separate ClawSweeper repair job.

Security
Cleared: The diff only changes trusted in-process plugin hook context handling plus a regression test and changelog text; it adds no dependency, workflow, secret, package, or external execution surface.

Review details

Best possible solution:

Land this PR or an equivalent narrow registry wrapper fix so mutable hook context survives while pluginConfig remains scoped to each active handler.

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

Yes, at source level. A plugin loaded through api.registerHook('agent:bootstrap') can assign event.context.bootstrapFiles, but current main passes a cloned context while bootstrap resolution later reads the original event context.

Is this the best way to solve the issue?

Yes. Reusing the original context and restoring or deleting pluginConfig in finally is the narrow compatible fix for the documented mutable hook contract; an immutable return-value API would be a larger SDK change.

What I checked:

Likely related people:

  • Ayumi Server: Commit metadata ties this author to both the original plugin hook pluginConfig injection and the later shallow-copy wrapper that drops assignment-style context mutations. (role: introduced wrapper behavior; confidence: high; commits: ed0b098d7596, c1187109c8fb; files: src/plugins/registry.ts)
  • steipete: GitHub commit metadata ties this login to the agent:bootstrap hook/readback path, and current blame/recent history touches adjacent plugin registry and bootstrap files. (role: bootstrap hook feature-history owner and recent adjacent contributor; confidence: high; commits: ad3c12a43a70, 06056926a099; files: src/agents/bootstrap-hooks.ts, src/hooks/internal-hooks.ts, src/plugins/registry.ts)
  • 100yenadmin: This contributor authored merged plugin SDK/session hook work touching registry and hook surfaces, and reported the linked regression with detailed real-run evidence. (role: adjacent plugin hook contributor and reporter; confidence: medium; commits: cb3853587576, 1adaa28dc86b; files: src/plugins/registry.ts, src/plugins/hook-types.ts, src/plugins/host-hooks.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 16e5d6692dcc.

@xuruiray
xuruiray force-pushed the codex/75245-preserve-hook-context branch 2 times, most recently from a9b16b6 to b92440d Compare May 5, 2026 09:02
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026
@xuruiray

xuruiray commented May 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main and addressed the only outstanding review item by adding the required changelog credit (Thanks @xuruiray.). Re-ran focused local validation (pnpm test src/plugins/loader.test.ts, pnpm check:changed). Latest GitHub checks are green and the PR is mergeable; ready for maintainer review.

@xuruiray
xuruiray force-pushed the codex/75245-preserve-hook-context branch from b92440d to 8eacffd Compare May 6, 2026 05:07
@openclaw-barnacle openclaw-barnacle Bot added the proof: supplied External PR includes structured after-fix real behavior proof. label May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@xuruiray xuruiray closed this May 15, 2026
@xuruiray xuruiray reopened this May 15, 2026
@xuruiray xuruiray closed this May 28, 2026
@xuruiray xuruiray reopened this May 28, 2026
@xuruiray xuruiray closed this May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registerHook wrapper drops mutable context changes for agent:bootstrap hooks

1 participant