Skip to content

Commit 07f43d4

Browse files
committed
fix(feishu): preserve later silent skip ordering
1 parent 08f21ac commit 07f43d4

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎extensions/feishu/src/reply-dispatcher.test.ts‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,32 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
21412141
});
21422142
});
21432143

2144+
it("preserves a later silent skip when an earlier queued block fails", async () => {
2145+
useNonStreamingBlockAccount();
2146+
const runtime = createRuntimeLogger();
2147+
const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" });
2148+
2149+
options.onSkip?.(
2150+
{ text: "NO_REPLY" },
2151+
{ kind: "block", reason: "silent", assistantMessageIndex: 2 },
2152+
);
2153+
sendMessageFeishuMock.mockRejectedValueOnce(new Error("send failed"));
2154+
2155+
await expect(
2156+
options.deliver(
2157+
{ text: "Earlier visible block" },
2158+
{ kind: "block", assistantMessageIndex: 1 },
2159+
),
2160+
).rejects.toThrow("send failed");
2161+
await expect(result.ensureNoVisibleReplyFallback("failed-block")).resolves.toBe(false);
2162+
2163+
expect(sendMessageFeishuMock).toHaveBeenCalledTimes(1);
2164+
expect(result.getVisibleReplyState()).toEqual({
2165+
visibleReplySent: false,
2166+
skippedFinalReason: "silent",
2167+
});
2168+
});
2169+
21442170
it("sends no-visible-reply fallback when a final fails after an earlier silent skip", async () => {
21452171
useNonStreamingAutoAccount();
21462172
const runtime = createRuntimeLogger();
@@ -2172,11 +2198,14 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
21722198
const runtime = createRuntimeLogger();
21732199
const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" });
21742200

2175-
options.onSkip?.({ text: "NO_REPLY" }, { kind: "block", reason: "silent" });
2201+
options.onSkip?.(
2202+
{ text: "NO_REPLY" },
2203+
{ kind: "block", reason: "silent", assistantMessageIndex: 1 },
2204+
);
21762205
sendMessageFeishuMock.mockRejectedValueOnce(new Error("send failed"));
21772206

21782207
await expect(
2179-
options.deliver({ text: "Later visible block" }, { kind: "block" }),
2208+
options.deliver({ text: "Later visible block" }, { kind: "block", assistantMessageIndex: 2 }),
21802209
).rejects.toThrow("send failed");
21812210
await expect(result.ensureNoVisibleReplyFallback("failed-block")).resolves.toBe(true);
21822211

‎extensions/feishu/src/reply-dispatcher.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
285285
let streamingCloseErroredForReply = false;
286286
let visibleReplySent = false;
287287
let skippedFinalReason: string | null = null;
288+
let skippedFinalAssistantMessageIndex: number | undefined;
288289
let idleSideEffectsPromise: Promise<void> = Promise.resolve();
289290
let replyLifecycleStateInitialized = false;
290291
type StreamTextUpdateMode = "snapshot" | "delta";
@@ -672,6 +673,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
672673
onSkip: (_payload, info) => {
673674
if (info.kind === "final" || (info.kind === "block" && info.reason === "silent")) {
674675
skippedFinalReason = info.reason;
676+
skippedFinalAssistantMessageIndex = info.assistantMessageIndex;
675677
}
676678
},
677679
onReplyStart: async () => {
@@ -683,14 +685,24 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
683685
streamingCloseErroredForReply = false;
684686
visibleReplySent = false;
685687
skippedFinalReason = null;
688+
skippedFinalAssistantMessageIndex = undefined;
686689
}
687690
if (streamingEnabled && renderMode === "card") {
688691
startStreaming();
689692
}
690693
await Promise.resolve(typingCallbacks?.onReplyStart?.());
691694
},
692695
deliver: async (payload: ReplyPayload, info) => {
693-
skippedFinalReason = null;
696+
// Delivery is serialized after enqueue-time skips. An older queued send
697+
// must not erase a silent decision from a later assistant message.
698+
if (
699+
skippedFinalAssistantMessageIndex === undefined ||
700+
info.assistantMessageIndex === undefined ||
701+
info.assistantMessageIndex >= skippedFinalAssistantMessageIndex
702+
) {
703+
skippedFinalReason = null;
704+
skippedFinalAssistantMessageIndex = undefined;
705+
}
694706
const payloadText =
695707
payload.isReasoning && payload.text ? formatReasoningMessage(payload.text) : payload.text;
696708
const reply = resolveSendableOutboundReplyParts({ ...payload, text: payloadText });

0 commit comments

Comments
 (0)