Skip to content

Commit f1b4250

Browse files
author
R2
committed
Flush buffered Telegram finals after segmented delivery
1 parent 220d3ec commit f1b4250

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

extensions/telegram/src/bot-message-dispatch.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,46 @@ describe("dispatchTelegramMessage draft streaming", () => {
15871587
expect(answerDraftStream.update).toHaveBeenCalledWith("Answer");
15881588
});
15891589

1590+
it("flushes buffered final answers after a skipped reasoning segment", async () => {
1591+
deliverInboundReplyWithMessageSendContext
1592+
.mockResolvedValueOnce({ status: "handled_no_send" })
1593+
.mockResolvedValueOnce({
1594+
status: "handled_visible",
1595+
delivery: { messageIds: ["1001"], visibleReplySent: true },
1596+
});
1597+
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {
1598+
await dispatcherOptions.deliver(
1599+
{ text: "<think>Hidden reasoning</think>Visible answer" },
1600+
{ kind: "final" },
1601+
);
1602+
return { queuedFinal: true };
1603+
});
1604+
1605+
await dispatchWithContext({
1606+
context: createContext({
1607+
ctxPayload: {
1608+
SessionKey: "agent:main:telegram:direct:123",
1609+
ChatType: "direct",
1610+
} as unknown as TelegramMessageContext["ctxPayload"],
1611+
}),
1612+
cfg: { agents: { defaults: { reasoningDefault: "on" } } },
1613+
streamMode: "off",
1614+
telegramDeps: telegramDepsForTest,
1615+
});
1616+
1617+
expect(deliverInboundReplyWithMessageSendContext).toHaveBeenCalledTimes(2);
1618+
expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext, 0), {
1619+
info: { kind: "final" },
1620+
});
1621+
expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext, 0).payload, {
1622+
text: "Reasoning:\n_Hidden reasoning_",
1623+
});
1624+
expectRecordFields(mockCallArg(deliverInboundReplyWithMessageSendContext, 1).payload, {
1625+
text: "Visible answer",
1626+
});
1627+
expect(deliverReplies).not.toHaveBeenCalled();
1628+
});
1629+
15901630
it("suppresses reasoning-only finals without raw text fallback", async () => {
15911631
setupDraftStreams({ answerMessageId: 2001, reasoningMessageId: 3001 });
15921632
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {

extensions/telegram/src/bot-message-dispatch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,9 @@ export const dispatchTelegramMessage = async ({
13831383
};
13841384

13851385
if (segments.length > 0) {
1386+
if (info.kind === "final") {
1387+
await flushBufferedFinalAnswer();
1388+
}
13861389
trackBlockMedia(blockDelivered);
13871390
return;
13881391
}

0 commit comments

Comments
 (0)