Skip to content

fix: 修复 register() 重入导致 compat 和 runtime 日志重复输出#47

Open
neo1027144-creator wants to merge 1 commit intoTencent:mainfrom
neo1027144-creator:fix/deduplicate-register-logs
Open

fix: 修复 register() 重入导致 compat 和 runtime 日志重复输出#47
neo1027144-creator wants to merge 1 commit intoTencent:mainfrom
neo1027144-creator:fix/deduplicate-register-logs

Conversation

@neo1027144-creator
Copy link
Copy Markdown

@neo1027144-creator neo1027144-creator commented Apr 10, 2026

问题描述

Fixes #46

OpenClaw 宿主在配置热重载、模型列表刷新、控制台重连等场景下会多次调用插件的 register(),导致以下两条初始化日志每次都以 info 级别重复输出:

  • [compat] Host OpenClaw 2026.4.5 >= 2026.3.22, OK.
  • [runtime] setWeixinRuntime called, runtime set successfully

这会产生大量日志噪音,干扰排查真正的异常信息。

修复方案

对两处日志做进程内去重,首次输出保持 info 级别不变,后续重入调用降级为 debug

src/compat.ts

  • 新增模块级 Set<string> 记录已检查过的宿主版本
  • 同一版本首次检查通过:info(行为不变)
  • 后续重复检查:降级为 debug

src/runtime.ts

  • 新增 boolean 标记是否已完成首次初始化
  • 首次 setWeixinRuntime() 调用:info(行为不变)
  • 后续重入调用:降级为 debug

测试验证

  • ✅ 现有全部 14 个 compat 测试通过,无需修改
  • ✅ 改动仅影响日志级别,对运行时功能逻辑零影响
  • ⚠️ 仓库中已有 5 个预先失败的测试(state-dirsync-buf),与本次修改无关(Windows 路径分隔符和超时问题)

When the OpenClaw host invokes register() multiple times (e.g. during
config hot-reload or model list refresh), the compat OK and runtime set
logs were emitted at info level every time, causing significant log spam.

This change:
- compat.ts: tracks already-checked host versions in a module-level Set;
  subsequent checks for the same version are logged at debug instead of info.
- runtime.ts: tracks whether runtime has been initialized; subsequent
  re-entrant calls are logged at debug instead of info.

First-time initialization continues to log at info level as before.

Closes Tencent#46
@neo1027144-creator neo1027144-creator changed the title fix: deduplicate compat and runtime logs on re-entrant register() calls fix: 修复 register() 重入导致 compat 和 runtime 日志重复输出 Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openclaw-weixin 在正常启动过程中会重复输出初始化日志,疑似 register 重入导致

1 participant