Skip to content

Commit b1e2bd6

Browse files
committed
fix(telegram): recover stale ingress claims after restart
1 parent 1a7669b commit b1e2bd6

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

extensions/telegram/src/polling-session.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ describe("TelegramPollingSession", () => {
891891
});
892892
});
893893

894-
it("keeps claims owned by another live process blocked", async () => {
894+
it("recovers restart-stale claims that reused the current process pid", async () => {
895895
await withTempSpool(async (tempDir) => {
896896
const interruptedUpdate = topicUpdate(42, 10, "active topic 10 turn");
897897
await writeSpooledTestUpdates(tempDir, [
@@ -916,7 +916,7 @@ describe("TelegramPollingSession", () => {
916916
receivedAt: interrupted.receivedAt,
917917
update: interruptedUpdate,
918918
claim: {
919-
processId: "other-process",
919+
processId: "previous-gateway-instance",
920920
processPid: process.pid,
921921
claimedAt: Date.now(),
922922
},
@@ -930,10 +930,10 @@ describe("TelegramPollingSession", () => {
930930
shouldRecover: (claim) => !isTelegramSpooledUpdateClaimOwnedByOtherLiveProcess(claim),
931931
});
932932

933-
expect(recovered).toBe(0);
934-
expect(await pendingUpdateIds(tempDir)).toEqual([43]);
933+
expect(recovered).toBe(1);
934+
expect(await pendingUpdateIds(tempDir)).toEqual([42, 43]);
935935
expect((await fs.readdir(tempDir)).toSorted()).toEqual([
936-
"0000000000000042.json.processing",
936+
"0000000000000042.json",
937937
"0000000000000043.json",
938938
]);
939939
});

extensions/telegram/src/telegram-ingress-spool.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ describe("Telegram ingress spool", () => {
242242
});
243243
});
244244

245-
it("does not treat stale claims with reused pids as live-owned", () => {
245+
it("does not treat current-pid claims from older process identities as live-owned", () => {
246246
const now = Date.now();
247247
expect(
248248
isTelegramSpooledUpdateClaimOwnedByOtherLiveProcess({
@@ -254,7 +254,7 @@ describe("Telegram ingress spool", () => {
254254
claim: {
255255
processId: "other-process",
256256
processPid: process.pid,
257-
claimedAt: now - TELEGRAM_SPOOLED_UPDATE_PROCESSING_STALE_MS - 1,
257+
claimedAt: now,
258258
},
259259
}),
260260
).toBe(false);

extensions/telegram/src/telegram-ingress-spool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export function isTelegramSpooledUpdateClaimOwnedByOtherLiveProcess(
181181
return Boolean(
182182
claim.claim &&
183183
claim.claim.processId !== TELEGRAM_SPOOLED_UPDATE_PROCESS_ID &&
184+
claim.claim.processPid !== process.pid &&
184185
isFreshClaimOwner(claim.claim) &&
185186
processExists(claim.claim.processPid),
186187
);

0 commit comments

Comments
 (0)