fix(telegram): scope polling offsets per bot and await shared runner stop (#24549)

* Telegram: scope polling offsets and await shared runner stop

* Changelog: remove unrelated session-fix entries from PR

* Update CHANGELOG.md
This commit is contained in:
Vincent Koc
2026-02-23 09:43:47 -05:00
committed by GitHub
parent 3a3c2da916
commit 8e821a061c
4 changed files with 100 additions and 10 deletions

View File

@@ -135,6 +135,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
let lastUpdateId = await readTelegramUpdateOffset({
accountId: account.accountId,
botToken: token,
});
const persistUpdateId = async (updateId: number) => {
if (lastUpdateId !== null && updateId <= lastUpdateId) {
@@ -145,6 +146,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
await writeTelegramUpdateOffset({
accountId: account.accountId,
updateId,
botToken: token,
});
} catch (err) {
(opts.runtime?.error ?? console.error)(
@@ -257,9 +259,18 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
const runner = run(bot, runnerOptions);
activeRunner = runner;
let stopPromise: Promise<void> | undefined;
const stopRunner = () => {
stopPromise ??= Promise.resolve(runner.stop())
.then(() => undefined)
.catch(() => {
// Runner may already be stopped by abort/retry paths.
});
return stopPromise;
};
const stopOnAbort = () => {
if (opts.abortSignal?.aborted) {
void runner.stop();
void stopRunner();
}
};
opts.abortSignal?.addEventListener("abort", stopOnAbort, { once: true });
@@ -304,11 +315,7 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
}
} finally {
opts.abortSignal?.removeEventListener("abort", stopOnAbort);
try {
await runner.stop();
} catch {
// Runner may already be stopped by abort/retry paths.
}
await stopRunner();
}
}
} finally {