🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(chat-input): tell queued follow-ups on CLI agents they wait for the whole run (#21430)
AmAzing-35470e84ce07
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex cc2bd3b18c4..f8752ba77ab 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -1623,6 +1623,8 @@"inputQueue.enqueueRejected": "Queue is full. Try again after the current run finishes.","inputQueue.queuedHint": "Sends when the current step finishes","inputQueue.queuedMergeHint": "Merged and sent when the current step finishes",+ "inputQueue.queuedRunEndHint": "Sends when the current run finishes",+ "inputQueue.queuedRunEndMergeHint": "Merged and sent when the current run finishes","inputQueue.sendNow": "Send now (interrupts current run)","inputQueue.withdrawFailed": "Couldn’t take the message back. Try again.","intentUnderstanding.title": "Understanding your intent...",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex ceabdafbd8c..0a169495dba 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -1623,6 +1623,8 @@"inputQueue.enqueueRejected": "队列已满。请在当前运行完成后再试。","inputQueue.queuedHint": "当前步骤完成后发送","inputQueue.queuedMergeHint": "当前步骤完成后合并发送",+ "inputQueue.queuedRunEndHint": "当前运行完成后发送",+ "inputQueue.queuedRunEndMergeHint": "当前运行完成后合并发送","inputQueue.sendNow": "立即发送(中断当前运行)","inputQueue.withdrawFailed": "没能撤回这条消息,请重试","intentUnderstanding.title": "正在理解你的意图…",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 81a2bb5e7d4..b0ea077a1e1 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -988,6 +988,8 @@ export default {'inputQueue.enqueueRejected': 'Queue is full. Try again after the current run finishes.','inputQueue.queuedHint': 'Sends when the current step finishes','inputQueue.queuedMergeHint': 'Merged and sent when the current step finishes',+ 'inputQueue.queuedRunEndHint': 'Sends when the current run finishes',+ 'inputQueue.queuedRunEndMergeHint': 'Merged and sent when the current run finishes','inputQueue.sendNow': 'Send now (interrupts current run)','inputQueue.alreadyDelivered': 'Already sent to the agent','inputQueue.withdrawFailed': 'Couldn’t take the message back. Try again.',diff --git a/src/features/Conversation/ChatInput/QueueTray.tsx b/src/features/Conversation/ChatInput/QueueTray.tsxindex 09f67636c0a..0cff5be0e3f 100644--- a/src/features/Conversation/ChatInput/QueueTray.tsx+++ b/src/features/Conversation/ChatInput/QueueTray.tsx@@ -19,7 +19,12 @@ import { useFileStore } from '@/store/file';import { useConversationResourceAccess } from '../hooks/useConversationResourceAccess';import { useConversationStore } from '../store';-import { createQueueSendNowGate, putQueuedMessageInEditor, sendQueuedMessageNow } from './utils';+import {+ createQueueSendNowGate,+ getQueuedHintKey,+ putQueuedMessageInEditor,+ sendQueuedMessageNow,+} from './utils';const PREVIEW_SIZE = 28;@@ -201,6 +206,7 @@ const QueueTray = memo(() => {);const queuedMessages = useChatStore((s) => operationSelectors.getQueuedMessages(context)(s));+ const waitsForRunEnd = useChatStore(operationSelectors.isQueueDrainedAtRunEnd(context));const withdrawQueuedMessage = useChatStore((s) => s.withdrawQueuedMessage);const dispatchChatUploadFileList = useFileStore((s) => s.dispatchChatUploadFileList);const editor = useConversationStore((s) => s.editor);@@ -267,10 +273,9 @@ const QueueTray = memo(() => {if (!canUseResource) return null;// The queue drains as one take-all and is merged into a single send, so a- // multi-item queue has to say "merges" instead of "sends".- const hintText = t(- queuedMessages.length > 1 ? 'inputQueue.queuedMergeHint' : 'inputQueue.queuedHint',- );+ // multi-item queue has to say "merges" instead of "sends". A heterogeneous+ // CLI run only drains once the whole run ends, not after the current step.+ const hintText = t(getQueuedHintKey({ count: queuedMessages.length, waitsForRunEnd }));return (<Flexbox className={styles.container} gap={0}>diff --git a/src/features/Conversation/ChatInput/utils.test.ts b/src/features/Conversation/ChatInput/utils.test.tsindex ee721513718..b4cf037c0c6 100644--- a/src/features/Conversation/ChatInput/utils.test.ts+++ b/src/features/Conversation/ChatInput/utils.test.ts@@ -8,6 +8,7 @@ import {getContextWindowMessages,getConversationChatInputUiState,getConversationSendButtonProps,+ getQueuedHintKey,putQueuedMessageInEditor,sendQueuedMessageNow,toChatInputMessages,@@ -57,6 +58,35 @@ describe('createQueueSendNowGate', () => {});});+describe('getQueuedHintKey', () => {+ it('promises the next step boundary for the built-in runtime', () => {+ expect(getQueuedHintKey({ count: 1, waitsForRunEnd: false })).toBe('inputQueue.queuedHint');+ expect(getQueuedHintKey({ count: 2, waitsForRunEnd: false })).toBe(+ 'inputQueue.queuedMergeHint',+ );+ });++ /**+ * @example A follow-up is queued while a Claude Code run is still calling tools.+ */+ it('promises the end of the whole run for heterogeneous agents', () => {+ // ROOT CAUSE:+ //+ // A Claude Code / Codex CLI turn cannot be handed back at a step boundary:+ // the queue drains only once the CLI run ends. QueueTray still captioned+ // the row "Sends when the current step finishes".+ //+ // Before: one caption for every runtime.+ // After: heterogeneous agents say the follow-up waits for the current run.+ expect(getQueuedHintKey({ count: 1, waitsForRunEnd: true })).toBe(+ 'inputQueue.queuedRunEndHint',+ );+ expect(getQueuedHintKey({ count: 3, waitsForRunEnd: true })).toBe(+ 'inputQueue.queuedRunEndMergeHint',+ );+ });+});+describe('toChatInputMessages', () => {it('preserves user, assistant, and tool messages with their real roles', () => {expect(toChatInputMessages(tokenMessages).map((message) => message.role)).toEqual([diff --git a/src/features/Conversation/ChatInput/utils.ts b/src/features/Conversation/ChatInput/utils.tsindex 5adc16d7195..8cdf8df86ad 100644--- a/src/features/Conversation/ChatInput/utils.ts+++ b/src/features/Conversation/ChatInput/utils.ts@@ -61,6 +61,37 @@ export const createQueueSendNowGate = (): QueueSendNowGate => {};};+/**+ * Resolves the locale key that tells a queued follow-up when it will be sent.+ *+ * Use when:+ * - Captioning a QueueTray row with the queue's send timing.+ *+ * Expects:+ * - `count` is the number of queued items; more than one is merged into a single send.+ * - `waitsForRunEnd` is true when the queue waits behind a heterogeneous CLI run (Claude Code,+ * Codex, …; see `operationSelectors.isQueueDrainedAtRunEnd`). That run cannot hand the turn+ * back at a step boundary, so the queue only drains once the whole run ends, whereas the+ * built-in runtime hands the turn back after the current tool step.+ *+ * Returns:+ * - A `chat` namespace key under `inputQueue`.+ */+export const getQueuedHintKey = ({+ count,+ waitsForRunEnd,+}: {+ count: number;+ waitsForRunEnd: boolean;+}) => {+ const merged = count > 1;++ if (waitsForRunEnd)+ return merged ? 'inputQueue.queuedRunEndMergeHint' : 'inputQueue.queuedRunEndHint';++ return merged ? 'inputQueue.queuedMergeHint' : 'inputQueue.queuedHint';+};+const isSupportedChatInputMessage = (message: UIChatMessage,): message is UIChatMessage & { role: SupportedChatInputRole } =>diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.tsindex 9f329a42480..932c9d18586 100644--- a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts@@ -82,6 +82,7 @@ import {markGatewayMuxUnavailable,} from './muxRegistry';import { flagQueuedMessagesOnRunStart, syncQueuedMessagesFlag } from './queuedMessagesFlag';+import { gatewayRunOperationMetadata } from './runOperationMetadata';import { isCompletedRuntimeEnd } from './runtimeEndReason';import * as serverSteerQueue from './serverSteerQueue';@@ -1392,13 +1393,11 @@ export class GatewayActionImpl {});}- // Create a dedicated operation for gateway execution with correct context.- // Stash the server operation id in metadata so human-intervention flows- // (approve/reject/reject_continue) can look it up and call the server- // without needing an out-of-band lookup.+ // Create a dedicated operation for gateway execution with correct context,+ // carrying the server run's identity (see gatewayRunOperationMetadata).const { operationId: gatewayOpId } = this.#get().startOperation({context: resolvedMessageContext,- metadata: { heteroAutoRetryAvailable: true, serverOperationId: result.operationId },+ metadata: { heteroAutoRetryAvailable: true, ...gatewayRunOperationMetadata(result) },parentOperationId,type: 'execServerAgentRuntime',});@@ -1796,7 +1795,7 @@ export class GatewayActionImpl {const { operationId: gatewayOpId } = this.#get().startOperation({context,metadata: {- serverOperationId: operationId,+ ...gatewayRunOperationMetadata({ heteroType, operationId }),...(startTime !== undefined ? { startTime } : {}),},type: 'execServerAgentRuntime',diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.test.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.test.tsnew file mode 100644index 00000000000..8f14f8b1b92--- /dev/null+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.test.ts@@ -0,0 +1,18 @@+import { describe, expect, it } from 'vitest';++import { gatewayRunOperationMetadata } from './runOperationMetadata';++describe('gatewayRunOperationMetadata', () => {+ it('keeps the server run id and its producer type on the local op', () => {+ expect(gatewayRunOperationMetadata({ heteroType: 'claude-code', operationId: 'op-1' })).toEqual(+ { heteroType: 'claude-code', serverOperationId: 'op-1' },+ );+ });++ it('preserves an explicit native-runtime marker', () => {+ expect(gatewayRunOperationMetadata({ heteroType: null, operationId: 'op-1' })).toEqual({+ heteroType: null,+ serverOperationId: 'op-1',+ });+ });+});diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.tsnew file mode 100644index 00000000000..f8988cf704c--- /dev/null+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/runOperationMetadata.ts@@ -0,0 +1,29 @@+import type { OperationMetadata } from '@/store/chat/slices/operation/types';++/**+ * Builds the metadata a local operation mirroring a top-level Gateway run starts with.+ *+ * Use when:+ * - Starting the `execServerAgentRuntime` op for a freshly dispatched or a reconnected run.+ *+ * Expects:+ * - `operationId` is the server-side run id. Human-intervention flows (approve / reject /+ * reject_continue) read it back as `serverOperationId` to call the server without an+ * out-of-band lookup.+ * - `heteroType` is the server's producer discriminator: an external CLI type, `null` for the+ * native runtime, `undefined` when an older server or topic marker omitted it.+ *+ * Returns:+ * - The run identity fields of the op's metadata; QueueTray reads `heteroType` to tell when+ * queued follow-ups will be sent.+ */+export const gatewayRunOperationMetadata = ({+ heteroType,+ operationId,+}: {+ heteroType?: string | null;+ operationId: string;+}): Pick<OperationMetadata, 'heteroType' | 'serverOperationId'> => ({+ heteroType,+ serverOperationId: operationId,+});diff --git a/src/store/chat/slices/operation/selectors.queueDrain.test.ts b/src/store/chat/slices/operation/selectors.queueDrain.test.tsnew file mode 100644index 00000000000..043f422b2fa--- /dev/null+++ b/src/store/chat/slices/operation/selectors.queueDrain.test.ts@@ -0,0 +1,143 @@+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it } from 'vitest';++import { useChatStore } from '@/store/chat/store';+import { messageMapKey } from '@/store/chat/utils/messageMapKey';++import { operationSelectors } from './selectors';+import type { OperationMetadata, OperationType } from './types';++const context = { agentId: 'agent1', topicId: 'topic1' };++const startQueuedRun = (type: OperationType, metadata?: OperationMetadata) => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ result.current.startOperation({ context, metadata, type });+ result.current.enqueueMessage(messageMapKey(context), {+ content: 'follow up',+ createdAt: Date.now(),+ id: 'q1',+ interruptMode: 'soft',+ });+ });++ return operationSelectors.isQueueDrainedAtRunEnd(context)(result.current);+};++describe('isQueueDrainedAtRunEnd', () => {+ beforeEach(() => {+ useChatStore.setState(useChatStore.getInitialState());+ });++ // ROOT CAUSE:+ //+ // QueueTray picked its send-timing caption from the conversation agent's+ // config (`heterogeneousProvider`). That differs from the run actually+ // blocking the queue: a legacy CLI agent recovered from its model id has no+ // provider field, and an `@Agent` route runs another agent under the owner's+ // context. Those CLI runs still promised "current step".+ //+ // Before: the caption followed the owner agent's config.+ // After: it follows the queue-blocking operation's runtime.+ it('waits for a local CLI run, whatever the agent config says', () => {+ expect(startQueuedRun('execHeterogeneousAgent')).toBe(true);+ });++ it('waits for a Gateway run the server dispatched to a CLI producer', () => {+ expect(startQueuedRun('execServerAgentRuntime', { heteroType: 'claude-code' })).toBe(true);+ });++ it('hands back at the next step for the native runtime', () => {+ expect(startQueuedRun('execServerAgentRuntime', { heteroType: null })).toBe(false);+ expect(startQueuedRun('execAgentRuntime')).toBe(false);+ });++ // ROOT CAUSE:+ //+ // During a rolling deploy an older server returns no `heteroType` for either+ // runtime. Reading that as native promised "current step" behind a CLI run+ // that only drains its queue at run end.+ //+ // Before: an unreported producer counted as the native runtime.+ // After: it may be a CLI run, so the caption promises the later timing.+ it('treats an unreported producer as a possible CLI run', () => {+ expect(startQueuedRun('execServerAgentRuntime')).toBe(true);+ });++ it('follows the supervisor, not a group member run under it', () => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ const { operationId: supervisorId } = result.current.startOperation({+ context,+ metadata: { heteroType: null },+ type: 'execServerAgentRuntime',+ });+ result.current.startOperation({+ context,+ parentOperationId: supervisorId,+ type: 'execServerAgentRuntime',+ });+ result.current.enqueueMessage(messageMapKey(context), {+ content: 'follow up',+ createdAt: Date.now(),+ id: 'q1',+ interruptMode: 'soft',+ });+ });++ expect(operationSelectors.isQueueDrainedAtRunEnd(context)(result.current)).toBe(false);+ });++ // ROOT CAUSE:+ //+ // A Gateway CLI socket that closes without its terminal completes the local+ // op but leaves the external producer and its queue alive until+ // `heteroFinish`. Requiring a queue-blocking op flipped the still-visible+ // queue back to "current step".+ //+ // Before: only a running queue-blocking op could promise run-end timing.+ // After: with nothing running, the queue's idle host decides.+ it('keeps waiting for a CLI run whose socket closed before its terminal', () => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ const { operationId } = result.current.startOperation({+ context,+ metadata: { heteroType: 'claude-code' },+ type: 'execServerAgentRuntime',+ });+ result.current.enqueueMessage(messageMapKey(context), {+ content: 'follow up',+ createdAt: Date.now(),+ id: 'q1',+ interruptMode: 'soft',+ });+ result.current.completeOperation(operationId);+ });++ expect(operationSelectors.isQueueDrainedAtRunEnd(context)(result.current)).toBe(true);+ });++ it('does not let an idle native host promise run-end timing', () => {+ const { result } = renderHook(() => useChatStore());++ act(() => {+ const { operationId } = result.current.startOperation({+ context,+ metadata: { heteroType: null },+ type: 'execServerAgentRuntime',+ });+ result.current.enqueueMessage(messageMapKey(context), {+ content: 'follow up',+ createdAt: Date.now(),+ id: 'q1',+ interruptMode: 'soft',+ });+ result.current.completeOperation(operationId);+ });++ expect(operationSelectors.isQueueDrainedAtRunEnd(context)(result.current)).toBe(false);+ });+});diff --git a/src/store/chat/slices/operation/selectors.ts b/src/store/chat/slices/operation/selectors.tsindex 3bfe0ff9435..0870d2931fe 100644--- a/src/store/chat/slices/operation/selectors.ts+++ b/src/store/chat/slices/operation/selectors.ts@@ -329,6 +329,48 @@ const getRunningQueueBlockingOperationIds =.map((op) => op.id);};+/**+ * Whether the run a context's queue waits behind sends it only once the whole+ * run ends, instead of at the next step boundary.+ *+ * Heterogeneous CLI runs (Claude Code, Codex, …) cannot hand the turn back+ * mid-run: a local `execHeterogeneousAgent` drains the queue after the CLI+ * exits, and a Gateway run the server dispatched to an external producer+ * (`heteroType`) drains it in `heteroFinish`. Read from the running operation,+ * not the conversation's agent config, which can differ from what actually+ * runs (an `@Agent` route, a legacy CLI agent recovered from its model id).+ *+ * A Gateway run whose producer went unreported (`heteroType` undefined: an+ * older server or topic marker) may be a CLI run, so it promises the later+ * timing, as the Gateway lifecycle treats it (`heteroType !== null`). A group+ * member's run is skipped: its supervisor's run owns the queue.+ *+ * With nothing holding the queue locally, the queue still waits behind its+ * idle host: a Gateway CLI socket that closes without its terminal completes+ * the local op, yet the server keeps the producer running until `heteroFinish`.+ */+const isQueueDrainedAtRunEnd =+ (context: MessageMapKeyInput) =>+ (s: ChatStoreState): boolean => {+ if (!context.agentId) return false;+ const hasQueuedMessages = getQueuedMessages(context)(s).length > 0;+ const isCliRun = (op: Operation) => {+ if (op.type === 'execHeterogeneousAgent') return true;+ if (op.type !== 'execServerAgentRuntime') return false;++ const parent = op.parentOperationId ? s.operations[op.parentOperationId] : undefined;+ return parent?.type !== 'execServerAgentRuntime' && op.metadata.heteroType !== null;+ };++ const blocking = getOperationsByContext(context)(s).filter((op) =>+ isQueueBlockingOperation(op, { hasQueuedMessages }),+ );+ if (blocking.length > 0) return blocking.some(isCliRun);++ const host = getIdleQueueHost(context)(s);+ return !!host && isCliRun(host);+ };+const getOperationTurnStartTime = (op: Operation) =>op.metadata.turnStartTime ?? op.metadata.startTime;@@ -1056,6 +1098,7 @@ export const operationSelectors = {isMessageProcessing,isMessageRegenerating,isRegenerating,+ isQueueDrainedAtRunEnd,isQueueDrainPending,isSendingMessage,isSteerHandoffPending,diff --git a/src/store/chat/slices/operation/types.ts b/src/store/chat/slices/operation/types.tsindex 20602ebd53e..e67cc756621 100644--- a/src/store/chat/slices/operation/types.ts+++ b/src/store/chat/slices/operation/types.ts@@ -157,6 +157,15 @@ export interface OperationMetadata {*/heteroAutoRetryAvailable?: boolean;+ /**+ * External heterogeneous producer (e.g. `claude-code`) the server dispatched+ * this Gateway run to. `null` denotes the native AgentRuntime; `undefined`+ * means an older server or topic marker did not report it, so it may still+ * be an external producer.+ * @default undefined+ */+ heteroType?: string | null;+// UI state (for sendMessage operation)inputEditorTempState?: any | null; // Editor state snapshot for cancel restorationinputSendErrorMsg?: string; // Error message to display in UI