fix(telegram): rotate previews after visible tool output

This commit is contained in:
Vincent Koc
2026-05-05 16:08:21 -07:00
parent dd643b52df
commit 1470b439e2
2 changed files with 12 additions and 7 deletions

View File

@@ -555,6 +555,7 @@ export const dispatchTelegramMessage = async ({
let splitReasoningOnNextStream = false;
let skipNextAnswerMessageStartRotation = false;
let pendingCompactionReplayBoundary = false;
let discardAnswerPreviewOnNextRotation = false;
let draftLaneEventQueue = Promise.resolve();
const reasoningStepState = createTelegramReasoningStepState();
const enqueueDraftLaneEvent = (task: () => Promise<void>): Promise<void> => {
@@ -600,6 +601,7 @@ export const dispatchTelegramMessage = async ({
const materializedId = await answerLane.stream?.materialize?.();
const previewMessageId = materializedId ?? answerLane.stream?.messageId();
if (
!discardAnswerPreviewOnNextRotation &&
typeof previewMessageId === "number" &&
activePreviewLifecycleByLane.answer === "transient"
) {
@@ -613,6 +615,7 @@ export const dispatchTelegramMessage = async ({
answerLane.stream?.forceNewMessage();
didForceNewMessage = true;
}
discardAnswerPreviewOnNextRotation = false;
resetDraftLaneState(answerLane);
answerLaneHasAssistantContent = false;
if (didForceNewMessage) {
@@ -967,11 +970,12 @@ export const dispatchTelegramMessage = async ({
if (isDispatchSuperseded()) {
return;
}
const clearPendingCompactionReplayBoundaryOnVisibleBoundary = (
didDeliver: boolean,
) => {
const markVisibleNonPreviewBoundary = (didDeliver: boolean) => {
if (didDeliver && info.kind !== "final") {
pendingCompactionReplayBoundary = false;
if (answerLane.hasStreamedMessage) {
discardAnswerPreviewOnNextRotation = true;
}
}
};
if (payload.isError === true) {
@@ -1047,6 +1051,8 @@ export const dispatchTelegramMessage = async ({
});
if (info.kind === "final") {
emitPreviewFinalizedHook(result);
} else if (segment.lane === "answer" && result.kind === "sent") {
markVisibleNonPreviewBoundary(true);
}
if (segment.lane === "reasoning") {
if (result.kind !== "skipped") {
@@ -1069,7 +1075,7 @@ export const dispatchTelegramMessage = async ({
if (reply.hasMedia) {
const payloadWithoutSuppressedReasoning =
typeof payload.text === "string" ? { ...payload, text: "" } : payload;
clearPendingCompactionReplayBoundaryOnVisibleBoundary(
markVisibleNonPreviewBoundary(
await sendPayload(payloadWithoutSuppressedReasoning),
);
}
@@ -1093,9 +1099,7 @@ export const dispatchTelegramMessage = async ({
}
return;
}
clearPendingCompactionReplayBoundaryOnVisibleBoundary(
await sendPayload(payload),
);
markVisibleNonPreviewBoundary(await sendPayload(payload));
if (info.kind === "final") {
await flushBufferedFinalAnswer();
pendingCompactionReplayBoundary = false;