From 107935dc512a43ae415a716963728de1d885b4c3 Mon Sep 17 00:00:00 2001 From: Rai Butera Date: Mon, 9 Mar 2026 14:40:32 +0000 Subject: [PATCH] fix(discord): preserve fast-path chunk settings --- src/discord/monitor/reply-delivery.test.ts | 20 ++++++++++++++++++++ src/discord/monitor/reply-delivery.ts | 19 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/discord/monitor/reply-delivery.test.ts b/src/discord/monitor/reply-delivery.test.ts index 3274a669cf2..8b19372cdfe 100644 --- a/src/discord/monitor/reply-delivery.test.ts +++ b/src/discord/monitor/reply-delivery.test.ts @@ -256,6 +256,26 @@ describe("deliverDiscordReply", () => { expect(sendDiscordTextMock.mock.calls[1]?.[1]).toBe("789"); }); + it("passes maxLinesPerMessage and chunkMode through the fast path", async () => { + const fakeRest = {} as import("@buape/carbon").RequestClient; + + await deliverDiscordReply({ + replies: [{ text: Array.from({ length: 18 }, (_, index) => `line ${index + 1}`).join("\n") }], + target: "channel:789", + token: "token", + rest: fakeRest, + runtime, + textLimit: 2000, + maxLinesPerMessage: 120, + chunkMode: "newline", + }); + + expect(sendMessageDiscordMock).not.toHaveBeenCalled(); + expect(sendDiscordTextMock).toHaveBeenCalledTimes(1); + expect(sendDiscordTextMock.mock.calls[0]?.[5]).toBe(120); + expect(sendDiscordTextMock.mock.calls[0]?.[8]).toBe("newline"); + }); + it("falls back to sendMessageDiscord when rest is not provided", async () => { await deliverDiscordReply({ replies: [{ text: "single chunk" }], diff --git a/src/discord/monitor/reply-delivery.ts b/src/discord/monitor/reply-delivery.ts index 11fc1733ef1..d3e7ef9bf61 100644 --- a/src/discord/monitor/reply-delivery.ts +++ b/src/discord/monitor/reply-delivery.ts @@ -130,9 +130,11 @@ async function sendDiscordChunkWithFallback(params: { text: string; token: string; accountId?: string; + maxLinesPerMessage?: number; rest?: RequestClient; replyTo?: string; binding?: DiscordThreadBindingLookupRecord; + chunkMode?: ChunkMode; username?: string; avatarUrl?: string; /** Pre-resolved channel ID to bypass redundant resolution per chunk. */ @@ -169,7 +171,18 @@ async function sendDiscordChunkWithFallback(params: { if (params.channelId && params.request && params.rest) { const { channelId, request, rest } = params; await sendWithRetry( - () => sendDiscordText(rest, channelId, text, params.replyTo, request), + () => + sendDiscordText( + rest, + channelId, + text, + params.replyTo, + request, + params.maxLinesPerMessage, + undefined, + undefined, + params.chunkMode, + ), params.retryConfig, ); return; @@ -294,8 +307,10 @@ export async function deliverDiscordReply(params: { token: params.token, rest: params.rest, accountId: params.accountId, + maxLinesPerMessage: params.maxLinesPerMessage, replyTo, binding, + chunkMode: params.chunkMode, username: persona.username, avatarUrl: persona.avatarUrl, channelId, @@ -329,8 +344,10 @@ export async function deliverDiscordReply(params: { token: params.token, rest: params.rest, accountId: params.accountId, + maxLinesPerMessage: params.maxLinesPerMessage, replyTo: resolveReplyTo(), binding, + chunkMode: params.chunkMode, username: persona.username, avatarUrl: persona.avatarUrl, channelId,