fix: preserve block streaming order

This commit is contained in:
Peter Steinberger
2026-01-03 17:14:01 +01:00
parent 3bbdcaf87f
commit 200dd634fb
2 changed files with 12 additions and 5 deletions

View File

@@ -15,6 +15,7 @@
### Fixes
- Telegram: chunk block-stream replies to avoid “message is too long” errors (#124) — thanks @mukhtharcm.
- Block streaming: default to text_end and suppress duplicate block sends while in-flight.
- Block streaming: drop final payloads after soft chunking to keep Discord order intact.
- Gmail hooks: resolve gcloud Python to a real executable when PATH uses mise shims — thanks @joargp.
- Control UI: generate UUIDs when `crypto.randomUUID()` is unavailable over HTTP — thanks @ratulsarna.
- Agent: add soft block-stream chunking (8001200 chars default) with paragraph/newline preference.

View File

@@ -1133,6 +1133,7 @@ export async function getReplyFromConfig(
const streamedPayloadKeys = new Set<string>();
const pendingStreamedPayloadKeys = new Set<string>();
const pendingBlockTasks = new Set<Promise<void>>();
let didStreamBlockReply = false;
const buildPayloadKey = (payload: ReplyPayload) => {
const text = payload.text?.trim() ?? "";
const mediaList = payload.mediaUrls?.length
@@ -2239,6 +2240,7 @@ export async function getReplyFromConfig(
return;
}
pendingStreamedPayloadKeys.add(payloadKey);
didStreamBlockReply = true;
const task = (async () => {
await startTypingOnText(cleaned);
await opts.onBlockReply?.(blockPayload);
@@ -2345,11 +2347,15 @@ export async function getReplyFromConfig(
(payload.mediaUrls && payload.mediaUrls.length > 0),
);
const filteredPayloads = blockStreamingEnabled
? replyTaggedPayloads.filter(
(payload) => !streamedPayloadKeys.has(buildPayloadKey(payload)),
)
: replyTaggedPayloads;
const shouldDropFinalPayloads =
blockStreamingEnabled && blockReplyChunking && didStreamBlockReply;
const filteredPayloads = shouldDropFinalPayloads
? []
: blockStreamingEnabled
? replyTaggedPayloads.filter(
(payload) => !streamedPayloadKeys.has(buildPayloadKey(payload)),
)
: replyTaggedPayloads;
if (filteredPayloads.length === 0) return finalizeWithFollowup(undefined);