Repository navigation
Description
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
POST /api/conversations/{id}/load_plugin (and LocalConversation.load_plugin) loads a plugin's hooks by appending them to the conversation's hook_config. Loading the same plugin a second time (both calls answer 200) appends its hooks again, so hook_config holds two identical entries and each hook runs twice per message. The plugin's skills are not duplicated (they are merged by name). A client that retries load_plugin doubles every hook's side effects.
Expected Behavior
After a second load_plugin of the same plugin, hook_config holds one copy of each of the plugin's hooks (as for its skills), and a UserPromptSubmit hook runs once per user message.
Actual Behavior
hook_config.user_prompt_submit holds two identical entries (echo QA_PLUGIN_HOOK), and one user message produces two HookExecutionEvents for that hook. agent.agent_context.skills still lists the plugin's skill once.
Steps to Reproduce
- Register a local marketplace with one plugin that has a
UserPromptSubmithook on the agent'sagent_context.registered_marketplacesand start a conversation. POST /api/conversations/{id}/load_pluginwith{"plugin_ref": "<plugin>@<marketplace>"}:200.- Repeat the same request:
200. GET /api/conversations/{id}:hook_config.user_prompt_submithas length 2 (two identical matchers);GET ...?include_skills=truelists the skill once.- Send a user message: the hook runs twice.
In Python: conv.load_plugin("p@m"); conv.load_plugin("p@m") then conv.state.hook_config.user_prompt_submit has two identical matchers.
With the verify-agent-server skill: control-agent-server map run --file F09 --only F09.load-plugin-twice --fresh reports the known-bug bullet as an expected failure (xfail) while the bug lasts.
Acceptance Criteria
- Loading the same plugin twice leaves one copy of each of its hooks in
hook_config(REST and Python SDKload_plugin), so the hook runs once per message. - Hooks from other sources (explicit
hook_config, other plugins) are still merged as before. - A unit test in
tests/sdk/conversation/test_local_conversation_plugins.pycovers loading the same plugin twice. - The map bullet
F09.load-plugin-twicepasses with its# bugmarker removed.
Installation Method
uv sync in a checkout of main
Version
main at 6a298a4
Additional Context
Root cause: LocalConversation._merge_runtime_plugin_hooks (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:1332) merges with HookConfig.merge([existing_config, plugin_hooks]), and HookConfig.merge (openhands-sdk/openhands/sdk/hooks/config.py:373) concatenates the matchers of every event type without de-duplicating. Skills go through plugin.add_skills_to, which merges by name, so they are not duplicated.
Suggested fix: in _merge_runtime_plugin_hooks, keep only the plugin matchers the live config does not already hold, and return early (no hook processor restart) when nothing is new.
Related: the verify-agent-server feature map (#5621).
Found by the first full agentic run of verify-agent-server; tracked in #5653.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Root cause confirmed in the repository. LocalConversation._merge_runtime_plugin_hooks (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py) merges with HookConfig.merge([existing_config, plugin_hooks]), and HookConfig.merge (openhands-sdk/openhands/sdk/hooks/config.py) concatenates the matchers of each event type without de-duplicating. Skills do not duplicate because Plugin.add_skills_to merges by name, and MCP config merges by server key. LocalConversation.load_plugin is the single path behind both the Python SDK call and POST /api/conversations/{id}/load_plugin (the router delegates to the conversation service), so one fix covers both surfaces.
Scope: make a repeat load_plugin of the same plugin idempotent for hooks, so each of the plugin's matchers is present once and runs once per triggering event. Non-goals: changing the general concatenation semantics of HookConfig.merge for distinct configs; de-duplicating identical matchers contributed by different sources or plugins; changing skill or MCP merge behavior, which is already idempotent; changing the resolved_plugins bookkeeping.
Acceptance Criteria
- Calling
LocalConversation.load_plugin(ref)twice with the same ref leaves exactly one copy of each of that plugin'sHookMatcherentries per event type instate.hook_config; for a plugin whoseUserPromptSubmithook isecho QA_PLUGIN_HOOK,state.hook_config.user_prompt_submithas length 1 after the second call (was 2). -
POST /api/conversations/{id}/load_pluginwith the sameplugin_reftwice returns200both times, and a followingGET /api/conversations/{id}reportshook_config.user_prompt_submitwith length 1. - After the second load, one user message produces exactly one
HookExecutionEventfor the plugin'sUserPromptSubmithook (was two). - Loading the same plugin again is a no-op: it adds no new matchers and does not re-run the plugin's
SessionStarthooks. - Hooks from other sources are preserved: when
hook_configalready holds explicit hooks and/or hooks from a different plugin, a repeat load keeps those matchers and exactly one copy of the re-loaded plugin's matchers; a first load of a plugin with new hooks still installs them and restarts the hook processor.tests/sdk/conversation/test_local_conversation_plugins.py::test_load_plugin_merges_runtime_hooks_and_restarts_processorstill passes. - A unit test in
tests/sdk/conversation/test_local_conversation_plugins.pyloads the same plugin twice and assertsstate.hook_configholds one copy of the plugin's hook(s). - The verify-agent-server feature-map bullet
F09.load-plugin-twicepasses as a normal expectation: its trailing# bug:expected-failure annotation is removed and the run reports it as passing rather than xfail.
Activity