


















@@ -168,6 +168,11 @@ type TelegramReplyFenceState = {
168168activeDispatches: number;
169169};
170170171+type TelegramReplyFenceKey = {
172+activeKey: string;
173+roomEventKey: string;
174+};
175+171176// Newer accepted turns and authorized aborts can arrive ahead of older same-session reply work.
172177const telegramReplyFenceByKey = new Map<string, TelegramReplyFenceState>();
173178@@ -183,12 +188,16 @@ function resolveTelegramReplyFenceKey(params: {
183188ctxPayload: { SessionKey?: string; CommandTargetSessionKey?: string; InboundTurnKind?: string };
184189chatId: number | string;
185190threadSpec: { id?: number | string | null; scope?: string };
186-}): string {
191+}): TelegramReplyFenceKey {
187192const baseKey =
188193normalizeTelegramFenceKey(params.ctxPayload.CommandTargetSessionKey) ??
189194normalizeTelegramFenceKey(params.ctxPayload.SessionKey) ??
190195`telegram:${String(params.chatId)}:${params.threadSpec.scope ?? "default"}:${params.threadSpec.id ?? "root"}`;
191-return params.ctxPayload.InboundTurnKind === "room_event" ? `${baseKey}:room_event` : baseKey;
196+const roomEventKey = `${baseKey}:room_event`;
197+return {
198+activeKey: params.ctxPayload.InboundTurnKind === "room_event" ? roomEventKey : baseKey,
199+ roomEventKey,
200+};
192201}
193202194203function beginTelegramReplyFence(params: { key: string; supersede: boolean }): number {
@@ -205,6 +214,15 @@ function beginTelegramReplyFence(params: { key: string; supersede: boolean }): n
205214return state.generation;
206215}
207216217+function supersedeTelegramReplyFence(key: string): void {
218+const state = telegramReplyFenceByKey.get(key);
219+if (!state) {
220+return;
221+}
222+state.generation += 1;
223+telegramReplyFenceByKey.set(key, state);
224+}
225+208226function isTelegramReplyFenceSuperseded(params: { key: string; generation: number }): boolean {
209227return (telegramReplyFenceByKey.get(params.key)?.generation ?? 0) !== params.generation;
210228}
@@ -459,14 +477,14 @@ export const dispatchTelegramMessage = async ({
459477const isDispatchSuperseded = () =>
460478replyFenceGeneration !== undefined &&
461479isTelegramReplyFenceSuperseded({
462-key: replyFenceKey,
480+key: replyFenceKey.activeKey,
463481generation: replyFenceGeneration,
464482});
465483const releaseReplyFence = () => {
466484if (replyFenceGeneration === undefined) {
467485return;
468486}
469-endTelegramReplyFence(replyFenceKey);
487+endTelegramReplyFence(replyFenceKey.activeKey);
470488replyFenceGeneration = undefined;
471489};
472490const draftMaxChars = Math.min(textLimit, 4096);
@@ -851,9 +869,13 @@ export const dispatchTelegramMessage = async ({
851869852870const chunkMode = resolveChunkMode(cfg, "telegram", route.accountId);
853871872+const supersedeReplyFence = shouldSupersedeTelegramReplyFence(ctxPayload);
873+if (!isRoomEvent && supersedeReplyFence) {
874+supersedeTelegramReplyFence(replyFenceKey.roomEventKey);
875+}
854876replyFenceGeneration = beginTelegramReplyFence({
855-key: replyFenceKey,
856-supersede: shouldSupersedeTelegramReplyFence(ctxPayload),
877+key: replyFenceKey.activeKey,
878+supersede: supersedeReplyFence,
857879});
858880859881const implicitQuoteReplyTargetId =
@@ -875,6 +897,7 @@ export const dispatchTelegramMessage = async ({
875897outboundAccountId: route.accountId,
876898markInboundTurnDelivered: () => deliveryState.markDelivered(),
877899},
900+{ inboundTurnKind: ctxPayload.InboundTurnKind },
878901);
879902const clearGroupHistory = () => {
880903if (isGroup && historyKey) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。