Repository navigation
fix(telegram): release polling leases at in-process gateway restart boundary - #81533
SymbolStar wants to merge 1 commit into
Conversation
…oundary The Telegram polling lease registry lives on a process-global Symbol so it survives gateway restarts that recycle the lifecycle without exiting Node (SIGUSR1 in-process restart, OPENCLAW_NO_RESPAWN reload). When the previous lifecycle's monitor task is dropped before its `finally` releases the lease, the next lifecycle's `acquireTelegramPollingLease()` sees a stale same-token entry and rejects every Telegram account with the duplicate-poller error indefinitely. Add a generic `in-process-restart-hooks` registry on `process` and run it from the gateway run-loop's restart iteration hook, alongside the existing `resetAllLanes` / `resetGatewayRestartStateForInProcessRestart` / `reloadTaskRegistryFromStore` calls. Telegram's polling-lease module self-registers a hook on first load that drains the lease registry. Late `release()` calls from dropped previous-lifecycle tasks remain safe (release is owner-checked and idempotent), and the same-lifecycle live duplicate guard is unchanged. Regression tests cover both the cleanup behavior and the same-lifecycle guard, plus the run-loop wiring. Fixes openclaw#81507
Dependency Changes DetectedThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: Do we have a high-confidence way to reproduce the issue? Partly: the package/SDK review finding is source-reproducible from current-main contracts, and the Telegram lease leak has a clear source path, but I did not establish a live in-process gateway restart reproduction in this read-only review. Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Land a revised fix that keeps the restart drain core-owned, exposes only the minimal plugin registration seam if a public SDK subpath is needed, aligns the SDK entrypoint manifest/package exports/API contracts, and includes redacted real restart proof. Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? Partly: the package/SDK review finding is source-reproducible from current-main contracts, and the Telegram lease leak has a clear source path, but I did not establish a live in-process gateway restart reproduction in this read-only review. Is this the best way to solve the issue? Is this the best way to solve the issue? Not yet: restart-boundary cleanup is the right general shape, but the PR should use the existing SDK manifest/build contracts and avoid making global drain/test helpers public plugin APIs. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 6602884b0635. |
|
Thanks @SymbolStar for the PR and for the root-cause writeup. Your analysis of the process-global We landed the fix via #81890 instead of this PR. The final patch keeps the solution inside the Telegram plugin lifecycle: Telegram The merged PR includes focused regression coverage and remote Linux proof for the stale-lease reproduction. Closing this as superseded by #81890. |
Fixes #81507
Root cause
Telegram polling leases live on a process-global
Symbol.for("openclaw.telegram.pollingLeases")Map. The registry survives any gateway restart that recycles the lifecycle without exiting the Node process (SIGUSR1 in-process restart, OPENCLAW_NO_RESPAWN reload, etc.).When the previous lifecycle's
monitorTelegramProvidertask is dropped before itsfinally pollingLease.release()runs, the entry stays. The next lifecycle then callsacquireTelegramPollingLease(), finds a same-token entry whose abort signal hasn't observed an abort yet, and throws the duplicate-poller error indefinitely. This matches the reporter's "855 errors/day" symptom.Fix
Lifecycle-owned cleanup at the in-process restart boundary, per Codex review.
src/infra/in-process-restart-hooks.ts— small process-global registry of synchronous, idempotent reset hooks. Hooks are best-effort (errors swallowed) and the registry is stored on aSymbol.for(...)key so it deduplicates across module reloads.openclaw/plugin-sdk/lifecycle-restart-hooksre-export so plugins can register without importing internal infra.extensions/telegram/src/polling-lease.ts— exportsreleaseTelegramPollingLeasesForLifecycleReset()and self-registers it on first module load (process-symbol-guarded so duplicate ESM loads don't double-register).src/cli/gateway-cli/run-loop.ts— invokesrunInProcessRestartHooks()from the existing restart iteration hook, alongsideresetAllLanes()/resetGatewayRestartStateForInProcessRestart()/reloadTaskRegistryFromStore().The cleanup is only invoked at the in-process restart boundary. Steady-state
acquireTelegramPollingLease()still rejects two live pollers for the same bot token within one lifecycle. Laterelease()calls from dropped previous-lifecycle tasks are safe —release()is owner-checked and idempotent, so they won't delete a fresh lease that the new lifecycle just acquired.Tests
extensions/telegram/src/polling-lease.test.ts— three new regressions:release()does NOT delete the fresh lease;src/cli/gateway-cli/run-loop.test.ts— addsrunInProcessRestartHooksmock + assertion that it's called once per restart iteration alongside the existing lane/registry resets.Verification
pnpm test extensions/telegram/src/polling-lease.test.tspnpm test src/cli/gateway-cli/run-loop.test.ts(Local pnpm not available — relying on CI for the full run.)