fix(h5-chat): queue main-session submits while agent is busy
Memind CI / Test, build, and release guards (push) Successful in 4m1s

Prevent silent drops when users send follow-up instructions during waiting or streaming by showing the message immediately, notifying them it is queued, and auto-flushing after the composer returns to idle.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-13 08:51:30 +08:00
parent 53b0d2c62f
commit 558c4ef2ee
4 changed files with 280 additions and 96 deletions
+43
View File
@@ -72,6 +72,49 @@ export function shouldScheduleMissingActiveRequestGrace({
return allowMissingGrace && !agentRunPending;
}
export const QUEUED_CHAT_SUBMIT_NOTICE =
'已收到你的消息,将在当前任务完成后自动继续执行。';
/**
* @param {string | undefined | null} chatState
* @returns {boolean}
*/
export function isChatSubmitBusy(chatState) {
return (
chatState === 'streaming' ||
chatState === 'loading' ||
chatState === 'connecting' ||
chatState === 'waiting'
);
}
/**
* @param {number | undefined | null} queueLength
* @returns {string}
*/
export function buildQueuedChatSubmitNotice(queueLength = 1) {
const length = Math.max(1, Number(queueLength) || 1);
if (length <= 1) return QUEUED_CHAT_SUBMIT_NOTICE;
return `已收到你的消息,当前还有 ${length} 条待执行,将在任务完成后按顺序继续。`;
}
/**
* @param {{ chatState?: string; agentRunPending?: boolean; pendingTool?: boolean; queueLength?: number }} input
* @returns {boolean}
*/
export function canFlushQueuedChatSubmit({
chatState = 'idle',
agentRunPending = false,
pendingTool = false,
queueLength = 0,
} = {}) {
if (!queueLength || queueLength <= 0) return false;
if (isChatSubmitBusy(chatState)) return false;
if (agentRunPending) return false;
if (pendingTool) return false;
return true;
}
/**
* Only transport uncertainty may continue a run after submit fails. A
* deterministic gateway error already has a terminal outcome and must return