Repository navigation
Conversation
Cherry-pick from upstream d22279d: - Add early return in ensureRuntimePluginsLoaded() if active plugin registry already exists - Prevents redundant plugin re-registration on every agent message run Fixes: feishu plugin duplicate registration bug
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92dbcc39d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (feishuToolsRegistered) { | ||
| return; | ||
| } | ||
| feishuToolsRegistered = true; |
There was a problem hiding this comment.
Remove global Feishu registration latch on reload
The module-level feishuToolsRegistered flag persists across plugin-registry rebuilds, so after any cache miss/config change loadOpenClawPlugins will clear all plugin commands (clearPluginCommands() in src/plugins/loader.ts) and then registerFull returns early here without re-registering Feishu tools. This leaves Feishu tools missing for the rest of the process lifetime after the first real reload.
Useful? React with 👍 / 👎.
| if (getActivePluginRegistryKey()) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Keep runtime plugin load keyed by workspace/options
This early return makes ensureRuntimePluginsLoaded effectively one-shot: once any registry key is set, later calls with a different workspaceDir or allowGatewaySubagentBinding never invoke loadOpenClawPlugins. That bypasses the loader’s cache-key logic (which explicitly includes workspace and runtime subagent mode), so long-lived processes can run with a stale plugin registry for subsequent sessions/workspaces.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR adds two layered guards to prevent feishu plugin tools from being re-registered every second when
Confidence Score: 4/5Safe to merge for the immediate regression, but the feishu guard can silently drop tools if the registry is rebuilt while the module is cached. The upstream guard in extensions/feishu/index.ts — the module-level boolean guard; consider a WeakSet keyed on the api object to be registry-aware.
|
| Filename | Overview |
|---|---|
| extensions/feishu/index.ts | Adds a module-level boolean guard to prevent registerFull from re-registering feishu tools on repeated calls. Effective when the same jiti module instance is reused, but silently drops tool registration if the registry is rebuilt with a new api object while the module is already loaded. |
| src/agents/runtime-plugins.ts | Adds an idempotency guard using getActivePluginRegistryKey() — the global Symbol-based state — to short-circuit ensureRuntimePluginsLoaded once the registry is active. This is the cleaner upstream fix. |
| package.json | Adds discord-api-types to root devDependencies; unrelated to the feishu fix and already declared in extensions/discord/package.json. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/feishu/index.ts
Line: 49-61
Comment:
**Module-level guard prevents re-registration in a fresh registry**
`feishuToolsRegistered` is a plain module-level variable scoped to a single jiti module instance. If the plugin registry is legitimately rebuilt (e.g., after a state reset that sets `state.key = null`) while the same jiti context is reused, `registerFull` will return early and the new registry will silently contain **no feishu tools**.
In contrast, the `Symbol.for("openclaw.pluginRegistryState")` global in `src/plugins/runtime.ts` is explicitly designed to survive across module instances. A more robust guard here would tie the registration to the registry identity rather than a static boolean:
```ts
const registeredApis = new WeakSet<object>();
registerFull(api) {
if (registeredApis.has(api)) {
return;
}
registeredApis.add(api);
// ...
}
```
This way the guard is scoped to the specific `api` object, so a fresh registry (different `api`) will always get its tools registered, while duplicate calls on the same registry are still no-ops. The PR description already acknowledges this is a workaround — the above pattern would make the workaround less likely to silently misbehave under a registry rebuild.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: package.json
Line: 653
Comment:
**Unrelated dependency added**
`discord-api-types` is already declared as a direct dependency in `extensions/discord/package.json`. Adding it here to the root workspace `devDependencies` is unrelated to the feishu duplicate-registration fix and should probably be a separate PR unless there's a specific root-level test or tooling reason for it.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(feishu): prevent duplicate tool regi..." | Re-trigger Greptile
| let feishuToolsRegistered = false; | ||
|
|
||
| export default defineChannelPluginEntry({ | ||
| id: "feishu", | ||
| name: "Feishu", | ||
| description: "Feishu/Lark channel plugin", | ||
| plugin: feishuPlugin, | ||
| setRuntime: setFeishuRuntime, | ||
| registerFull(api) { | ||
| if (feishuToolsRegistered) { | ||
| return; | ||
| } | ||
| feishuToolsRegistered = true; |
There was a problem hiding this comment.
Module-level guard prevents re-registration in a fresh registry
feishuToolsRegistered is a plain module-level variable scoped to a single jiti module instance. If the plugin registry is legitimately rebuilt (e.g., after a state reset that sets state.key = null) while the same jiti context is reused, registerFull will return early and the new registry will silently contain no feishu tools.
In contrast, the Symbol.for("openclaw.pluginRegistryState") global in src/plugins/runtime.ts is explicitly designed to survive across module instances. A more robust guard here would tie the registration to the registry identity rather than a static boolean:
const registeredApis = new WeakSet<object>();
registerFull(api) {
if (registeredApis.has(api)) {
return;
}
registeredApis.add(api);
// ...
}This way the guard is scoped to the specific api object, so a fresh registry (different api) will always get its tools registered, while duplicate calls on the same registry are still no-ops. The PR description already acknowledges this is a workaround — the above pattern would make the workaround less likely to silently misbehave under a registry rebuild.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/index.ts
Line: 49-61
Comment:
**Module-level guard prevents re-registration in a fresh registry**
`feishuToolsRegistered` is a plain module-level variable scoped to a single jiti module instance. If the plugin registry is legitimately rebuilt (e.g., after a state reset that sets `state.key = null`) while the same jiti context is reused, `registerFull` will return early and the new registry will silently contain **no feishu tools**.
In contrast, the `Symbol.for("openclaw.pluginRegistryState")` global in `src/plugins/runtime.ts` is explicitly designed to survive across module instances. A more robust guard here would tie the registration to the registry identity rather than a static boolean:
```ts
const registeredApis = new WeakSet<object>();
registerFull(api) {
if (registeredApis.has(api)) {
return;
}
registeredApis.add(api);
// ...
}
```
This way the guard is scoped to the specific `api` object, so a fresh registry (different `api`) will always get its tools registered, while duplicate calls on the same registry are still no-ops. The PR description already acknowledges this is a workaround — the above pattern would make the workaround less likely to silently misbehave under a registry rebuild.
How can I resolve this? If you propose a fix, please make it concise.| "@types/ws": "^8.18.1", | ||
| "@typescript/native-preview": "7.0.0-dev.20260317.1", | ||
| "@vitest/coverage-v8": "^4.1.0", | ||
| "discord-api-types": "^0.38.42", |
There was a problem hiding this comment.
discord-api-types is already declared as a direct dependency in extensions/discord/package.json. Adding it here to the root workspace devDependencies is unrelated to the feishu duplicate-registration fix and should probably be a separate PR unless there's a specific root-level test or tooling reason for it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: package.json
Line: 653
Comment:
**Unrelated dependency added**
`discord-api-types` is already declared as a direct dependency in `extensions/discord/package.json`. Adding it here to the root workspace `devDependencies` is unrelated to the feishu duplicate-registration fix and should probably be a separate PR unless there's a specific root-level test or tooling reason for it.
How can I resolve this? If you propose a fix, please make it concise.|
Superseded by #65398. I opened a new PR from a dedicated branch so the follow-up Feishu fix could land without rewriting my fork's Closing this PR in favor of #65398. |
Summary
loadOpenClawPluginscache missesSymptom
Root Cause
When
loadOpenClawPlugins(insrc/plugins/loader.ts) misses its cache, it recreates the registry and callsregisterFull(api)again. The feishu plugin'sregisterFullhad no idempotency guard, so tools get re-registered on every cache miss.Fix
Add a module-level guard in
extensions/feishu/index.tsto ensure tools are only registered once.Note: This is a workaround. The real fix should be in
loadOpenClawPluginscache logic to prevent cache misses in the first place, or ensureregisterFullis only called once per plugin lifetime.