diff --git a/src/telegram/thread-bindings.ts b/src/telegram/thread-bindings.ts index 68218e9045d..5719409e18b 100644 --- a/src/telegram/thread-bindings.ts +++ b/src/telegram/thread-bindings.ts @@ -62,8 +62,24 @@ export type TelegramThreadBindingManager = { stop: () => void; }; -const MANAGERS_BY_ACCOUNT_ID = new Map(); -const BINDINGS_BY_ACCOUNT_CONVERSATION = new Map(); +type TelegramThreadBindingsState = { + managersByAccountId: Map; + bindingsByAccountConversation: Map; +}; + +/** + * Keep Telegram thread binding state shared across bundled chunks so routing, + * binding lookups, and binding mutations all observe the same live registry. + */ +const _g = globalThis as typeof globalThis & { + __openclaw_telegram_thread_bindings_state__?: TelegramThreadBindingsState; +}; +const threadBindingsState = (_g.__openclaw_telegram_thread_bindings_state__ ??= { + managersByAccountId: new Map(), + bindingsByAccountConversation: new Map(), +}); +const MANAGERS_BY_ACCOUNT_ID = threadBindingsState.managersByAccountId; +const BINDINGS_BY_ACCOUNT_CONVERSATION = threadBindingsState.bindingsByAccountConversation; function normalizeDurationMs(raw: unknown, fallback: number): number { if (typeof raw !== "number" || !Number.isFinite(raw)) {