Skip to content

Commit 627864b

Browse files
authored
Merge pull request #15 from Kilo-Org/fix/guard-registration-logs
Fix(logging) guard registration logs
2 parents e350850 + cfa8b06 commit 627864b

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Fixed
1212

13+
- Plugin registration no longer spams "Registered …" info lines on
14+
every call to `register()`. OpenClaw invokes `register(api)` once
15+
per distinct `loadOpenClawPlugins` cache key (gateway startup,
16+
provider discovery, metadata registry, web-fetch/web-search runtimes,
17+
etc.), which produced ~44 redundant log lines per KiloClaw boot. A
18+
module-scoped `registrationLogged` flag now gates the three info
19+
lines so they fire at most once per process.
1320
- `getPublicIp()` now clears its 5-second abort timer on error paths as
1421
well as success, so repeated checkups on a flaky network don't leak
1522
dangling timeouts.

index.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ import pkg from "./package.json" with { type: "json" };
1919
const PLUGIN_VERSION: string = pkg.version;
2020
const DEFAULT_API_BASE = "https://api.kilo.ai";
2121

22+
// OpenClaw invokes a plugin's `register(api)` once per distinct
23+
// `loadOpenClawPlugins` cacheKey (gateway startup, provider discovery,
24+
// metadata registry, web-fetch/web-search runtimes, etc.), so in a
25+
// single process `register` typically runs ~15 times. Without this
26+
// guard the three "Registered …" info lines below fire every time,
27+
// which produced the 44-line log spam observed in KiloClaw boots.
28+
// Module scope survives across all register() calls in the same
29+
// process, so we log once and stay quiet after that.
30+
//
31+
// Scope note: this guard covers logging only. Re-invoking
32+
// `api.registerTool(...)` and `api.registerCommand(...)` on every
33+
// register() call is intentional — each `loadOpenClawPlugins` pass
34+
// builds its own registry, and the plugin must register into every
35+
// one to be visible in that context.
36+
let registrationLogged = false;
37+
2238
type ToolResult = {
2339
content: Array<{ type: "text"; text: string }>;
2440
};
@@ -470,8 +486,11 @@ export default definePluginEntry({
470486
handler: runSlashCommand,
471487
});
472488

473-
api.logger.info?.("Registered tool: kilocode_shell_security");
474-
api.logger.info?.("Registered command: /shell-security");
475-
api.logger.info?.("Registered command: /security-checkup (legacy alias)");
489+
if (!registrationLogged) {
490+
api.logger.info?.("Registered tool: kilocode_shell_security");
491+
api.logger.info?.("Registered command: /shell-security");
492+
api.logger.info?.("Registered command: /security-checkup (legacy alias)");
493+
registrationLogged = true;
494+
}
476495
},
477496
});

0 commit comments

Comments
 (0)