From 173359a496ce5c75d5071f9ae2c34c578623a727 Mon Sep 17 00:00:00 2001 From: Cypherm <28184436+Cypherm@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:33:09 +0800 Subject: [PATCH] fix: cancel pending compacting reaction before resuming thinking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compaction finishes before the debounce window (700ms), the queued setCompacting() emoji could fire after compaction ended, showing ✍ instead of 🤔. This adds cancelPending() to StatusReactionController and calls it in onCompactionEnd before setThinking() to prevent the race condition. Addresses review feedback from chatgpt-codex-connector. --- src/channels/status-reactions.ts | 8 ++++++++ src/discord/monitor/message-handler.process.ts | 1 + src/telegram/bot-message-dispatch.ts | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/channels/status-reactions.ts b/src/channels/status-reactions.ts index 4dd29a36c7c..060555a997c 100644 --- a/src/channels/status-reactions.ts +++ b/src/channels/status-reactions.ts @@ -40,6 +40,8 @@ export type StatusReactionController = { setThinking: () => Promise | void; setTool: (toolName?: string) => Promise | void; setCompacting: () => Promise | void; + /** Cancel any pending debounced emoji (useful before forcing a state transition). */ + cancelPending: () => void; setDone: () => Promise; setError: () => Promise; clear: () => Promise; @@ -314,6 +316,11 @@ export function createStatusReactionController(params: { scheduleEmoji(emojis.compacting); } + function cancelPending(): void { + clearDebounceTimer(); + pendingEmoji = ""; + } + function finishWithEmoji(emoji: string): Promise { if (!enabled) { return Promise.resolve(); @@ -384,6 +391,7 @@ export function createStatusReactionController(params: { setThinking, setTool, setCompacting, + cancelPending, setDone, setError, clear, diff --git a/src/discord/monitor/message-handler.process.ts b/src/discord/monitor/message-handler.process.ts index 8aaa2c5d764..36978628b7a 100644 --- a/src/discord/monitor/message-handler.process.ts +++ b/src/discord/monitor/message-handler.process.ts @@ -779,6 +779,7 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext) if (isProcessAborted(abortSignal)) { return; } + statusReactions.cancelPending(); await statusReactions.setThinking(); }, }, diff --git a/src/telegram/bot-message-dispatch.ts b/src/telegram/bot-message-dispatch.ts index 4b2fce02b95..424f98caefc 100644 --- a/src/telegram/bot-message-dispatch.ts +++ b/src/telegram/bot-message-dispatch.ts @@ -717,7 +717,10 @@ export const dispatchTelegramMessage = async ({ ? () => statusReactionController.setCompacting() : undefined, onCompactionEnd: statusReactionController - ? () => statusReactionController.setThinking() + ? async () => { + statusReactionController.cancelPending(); + await statusReactionController.setThinking(); + } : undefined, onModelSelected, },