diff --git a/CHANGELOG.md b/CHANGELOG.md index 178cd262955..68335362a9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Docs: https://docs.openclaw.ai - Discord: keep slash command follow-up chunks ephemeral when the command is configured for ephemeral replies, so long `/status` output no longer leaks fallback model or runtime details into the public channel. (#69869) thanks @gumadeiras. - Plugins/discovery: reject package plugin source entries that escape the package directory before explicit runtime entries or inferred built JavaScript peers can be used. (#69868) thanks @gumadeiras. - CLI/channels: resolve channel presence through a shared policy that keeps ambient env vars and stale persisted auth from surfacing disabled bundled plugins in status, doctor, security audit, and cron delivery validation unless the channel or plugin is effectively enabled or explicitly configured. (#69862) Thanks @gumadeiras. +- Doctor/plugins: hydrate legacy partial interactive handler state before plugin reload clears dedupe caches, so `openclaw doctor` and post-update doctor runs no longer crash with `Cannot read properties of undefined (reading 'clear')`. (#70135) Thanks @ngutman. - Control UI/config: preserve intentionally empty raw config snapshots when clearing pending updates so reset restores the original bytes instead of synthesizing JSON for blank config files. (#68178) Thanks @BunsDev. - memory-core/dreaming: surface a `Dreaming status: blocked` line in `openclaw memory status` when dreaming is enabled but the heartbeat that drives the managed cron is not firing for the default agent, and add a Troubleshooting section to the dreaming docs covering the two common causes (per-agent `heartbeat` blocks excluding `main`, and `heartbeat.every` set to `0`/empty/invalid), so the silent failure described in #69843 becomes legible on the status surface. - Cron/run-log: report generic `message` tool sends under the resolved delivery channel when they match the cron target, while preserving account-specific mismatch checks for delivery traces. (#69940) Thanks @davehappyminion. diff --git a/src/plugins/interactive-state.ts b/src/plugins/interactive-state.ts index 7b6d339d548..26e4ea9d288 100644 --- a/src/plugins/interactive-state.ts +++ b/src/plugins/interactive-state.ts @@ -1,5 +1,5 @@ import { createDedupeCache, resolveGlobalDedupeCache } from "../infra/dedupe.js"; -import { resolveGlobalSingleton } from "../shared/global-singleton.js"; +import type { DedupeCache } from "../infra/dedupe.js"; import type { PluginInteractiveHandlerRegistration } from "./types.js"; export type RegisteredInteractiveHandler = PluginInteractiveHandlerRegistration & { @@ -15,19 +15,56 @@ type InteractiveState = { }; const PLUGIN_INTERACTIVE_STATE_KEY = Symbol.for("openclaw.pluginInteractiveState"); +const PLUGIN_INTERACTIVE_CALLBACK_DEDUPE_KEY = Symbol.for( + "openclaw.pluginInteractiveCallbackDedupe", +); + +function createInteractiveCallbackDedupe(): DedupeCache { + return resolveGlobalDedupeCache(PLUGIN_INTERACTIVE_CALLBACK_DEDUPE_KEY, { + ttlMs: 5 * 60_000, + maxSize: 4096, + }); +} + +function createInteractiveState(): InteractiveState { + return { + interactiveHandlers: new Map(), + callbackDedupe: createInteractiveCallbackDedupe(), + inflightCallbackDedupe: new Set(), + }; +} + +function hydrateInteractiveState(value: unknown): InteractiveState { + const state = + typeof value === "object" && value !== null + ? (value as Partial) + : ({} as Partial); + + return { + interactiveHandlers: + state.interactiveHandlers instanceof Map + ? state.interactiveHandlers + : new Map(), + callbackDedupe: createInteractiveCallbackDedupe(), + inflightCallbackDedupe: + state.inflightCallbackDedupe instanceof Set + ? state.inflightCallbackDedupe + : new Set(), + }; +} function getState() { - return resolveGlobalSingleton(PLUGIN_INTERACTIVE_STATE_KEY, () => ({ - interactiveHandlers: new Map(), - callbackDedupe: resolveGlobalDedupeCache( - Symbol.for("openclaw.pluginInteractiveCallbackDedupe"), - { - ttlMs: 5 * 60_000, - maxSize: 4096, - }, - ), - inflightCallbackDedupe: new Set(), - })); + const globalStore = globalThis as Record; + const existing = globalStore[PLUGIN_INTERACTIVE_STATE_KEY]; + if (existing !== undefined) { + const hydrated = hydrateInteractiveState(existing); + globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = hydrated; + return hydrated; + } + + const created = createInteractiveState(); + globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = created; + return created; } export function getPluginInteractiveHandlersState() { diff --git a/src/plugins/interactive.test.ts b/src/plugins/interactive.test.ts index a3672bc11d1..d4ede08ef74 100644 --- a/src/plugins/interactive.test.ts +++ b/src/plugins/interactive.test.ts @@ -480,6 +480,61 @@ describe("plugin interactive handlers", () => { vi.restoreAllMocks(); }); + it("hydrates legacy interactive state shapes before clearing handlers", async () => { + const globalStore = globalThis as Record; + const stateKey = Symbol.for("openclaw.pluginInteractiveState"); + const originalState = globalStore[stateKey]; + + globalStore[stateKey] = { + interactiveHandlers: new Map(), + }; + + try { + expect(() => clearPluginInteractiveHandlers()).not.toThrow(); + const hydrated = globalStore[stateKey] as { + interactiveHandlers?: Map; + callbackDedupe?: { clear: () => void }; + inflightCallbackDedupe?: Set; + }; + expect(hydrated.interactiveHandlers).toBeInstanceOf(Map); + expect(hydrated.callbackDedupe?.clear).toEqual(expect.any(Function)); + expect(hydrated.inflightCallbackDedupe).toBeInstanceOf(Set); + + const handler = vi.fn(async () => ({ handled: true })); + expect( + registerPluginInteractiveHandler("codex-plugin", { + channel: "telegram", + namespace: "legacy", + handler, + }), + ).toEqual({ ok: true }); + + await expect( + dispatchInteractive( + createTelegramDispatchParams({ + data: "legacy:resume", + callbackId: "legacy-state-cb", + }), + ), + ).resolves.toEqual({ matched: true, handled: true, duplicate: false }); + await expect( + dispatchInteractive( + createTelegramDispatchParams({ + data: "legacy:resume", + callbackId: "legacy-state-cb", + }), + ), + ).resolves.toEqual({ matched: true, handled: true, duplicate: true }); + } finally { + if (originalState === undefined) { + delete globalStore[stateKey]; + } else { + globalStore[stateKey] = originalState; + } + clearPluginInteractiveHandlers(); + } + }); + it.each([ { name: "routes Telegram callbacks by namespace and dedupes callback ids",