Skip to content

🤯 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.

🐛 fix(chat-input): show a queued follow-up the agent already took as on its way (#22884)

Rdmclin29281ed09a91c
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index fbbde4b4211..457ad2066a7 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -1703,7 +1703,9 @@
"input.warp": "New Line",
"input.warpWithKey": "Press <key/> to insert a line break",
"inputQueue.alreadyDelivered": "Already sent to the agent",
+ "inputQueue.alreadyDelivering": "The agent already has this message. It shows in the chat once the agent reads it.",
"inputQueue.delete": "Delete",
+ "inputQueue.deliveringHint": "With the agent, shows in the chat once it reads it",
"inputQueue.edit": "Edit",
"inputQueue.enqueueRejected": "Queue is full. Try again after the current run finishes.",
"inputQueue.queuedHint": "Sends when the current step finishes",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 1ab169aee66..ee8738ce8a1 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -1703,7 +1703,9 @@
"input.warp": "换行",
"input.warpWithKey": "按 <key/> 换行",
"inputQueue.alreadyDelivered": "已经发给助理了",
+ "inputQueue.alreadyDelivering": "助理已经收到这条消息,读取后会显示在对话里",
"inputQueue.delete": "删除",
+ "inputQueue.deliveringHint": "已交给助理,读取后显示在对话里",
"inputQueue.edit": "编辑",
"inputQueue.enqueueRejected": "队列已满。请在当前运行完成后再试。",
"inputQueue.queuedHint": "当前步骤完成后发送",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 9859d32af5f..08d165d4c05 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -1044,6 +1044,7 @@ export default {
'input.warp': 'New Line',
'input.warpWithKey': 'Press <key/> to insert a line break',
'inputQueue.delete': 'Delete',
+ 'inputQueue.deliveringHint': 'With the agent, shows in the chat once it reads it',
'inputQueue.edit': 'Edit',
'inputQueue.enqueueRejected': 'Queue is full. Try again after the current run finishes.',
'inputQueue.queuedHint': 'Sends when the current step finishes',
@@ -1053,6 +1054,8 @@ export default {
'inputQueue.sendNow': 'Send now (interrupts current run)',
'inputQueue.sendNowFailed': 'Couldn’t interrupt the current run. Try again.',
'inputQueue.alreadyDelivered': 'Already sent to the agent',
+ 'inputQueue.alreadyDelivering':
+ 'The agent already has this message. It shows in the chat once the agent reads it.',
'inputQueue.withdrawFailed': 'Couldn’t take the message back. Try again.',
'intentUnderstanding.title': 'Understanding your intent...',
'inviteMembers': 'Invite members',
diff --git a/src/features/Conversation/ChatInput/QueueTray.test.tsx b/src/features/Conversation/ChatInput/QueueTray.test.tsx
new file mode 100644
index 00000000000..e6250bc3028
--- /dev/null
+++ b/src/features/Conversation/ChatInput/QueueTray.test.tsx
@@ -0,0 +1,80 @@
+import { act, render, screen } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import type { QueuedMessage } from '@/store/chat/slices/operation/types';
+import { useChatStore } from '@/store/chat/store';
+import { messageMapKey } from '@/store/chat/utils/messageMapKey';
+
+import QueueTray from './QueueTray';
+
+const context = { agentId: 'agt-1', topicId: 'tpc-1' };
+const key = messageMapKey(context);
+
+vi.mock('../hooks/useConversationResourceAccess', () => ({
+ useConversationResourceAccess: () => ({ canUseResource: true }),
+}));
+
+vi.mock('../store', () => ({
+ useConversationStore: (selector: (s: unknown) => unknown) => selector({ context, editor: null }),
+}));
+
+const serverQueued = (patch: Partial<QueuedMessage> = {}): QueuedMessage => ({
+ content: 'next step please',
+ createdAt: 1,
+ id: 'q1',
+ interruptMode: 'soft',
+ serverDelivery: 'server',
+ serverRequest: { agentId: 'agt-1', appContext: { topicId: 'tpc-1' }, prompt: 'next' },
+ ...patch,
+});
+
+const setQueue = (messages: QueuedMessage[]) =>
+ act(() => {
+ useChatStore.setState({ queuedMessages: { [key]: messages } });
+ });
+
+const actionLabels = ['inputQueue.edit', 'inputQueue.sendNow', 'inputQueue.delete'];
+
+describe('QueueTray', () => {
+ beforeEach(() => {
+ useChatStore.setState(useChatStore.getInitialState());
+ });
+
+ // ROOT CAUSE:
+ //
+ // A follow-up a live run already took (typed into a Claude Code session the
+ // agent had not read yet) kept the waiting caption and its actions; each
+ // click answered "Already sent to the agent" while the row stayed.
+ //
+ // Before: the row ignored the server's `delivering` state.
+ // After: it says it is with the agent and offers nothing until given back.
+ it('shows a follow-up a run already took as with the agent, without actions', () => {
+ setQueue([serverQueued({ serverDelivering: true })]);
+ render(<QueueTray />);
+
+ expect(screen.getAllByText('inputQueue.deliveringHint').length).toBeGreaterThan(0);
+ expect(screen.queryByText('inputQueue.queuedHint')).toBeNull();
+ for (const label of actionLabels) expect(screen.queryByLabelText(label)).toBeNull();
+ });
+
+ it('offers the actions again once the server gives it back', () => {
+ setQueue([serverQueued({ serverDelivering: true })]);
+ render(<QueueTray />);
+
+ setQueue([serverQueued()]);
+
+ expect(screen.getAllByText('inputQueue.queuedHint').length).toBeGreaterThan(0);
+ expect(screen.queryByText('inputQueue.deliveringHint')).toBeNull();
+ for (const label of actionLabels) expect(screen.getByLabelText(label)).toBeTruthy();
+ });
+
+ it('counts only waiting rows in the merged hint and keeps their actions', () => {
+ setQueue([serverQueued({ serverDelivering: true }), serverQueued({ id: 'q2' })]);
+ render(<QueueTray />);
+
+ // One waiting row: it sends on its own, not merged with the delivering one.
+ expect(screen.getAllByText('inputQueue.queuedHint').length).toBeGreaterThan(0);
+ expect(screen.queryByText('inputQueue.queuedMergeHint')).toBeNull();
+ for (const label of actionLabels) expect(screen.getAllByLabelText(label)).toHaveLength(1);
+ });
+});
diff --git a/src/features/Conversation/ChatInput/QueueTray.tsx b/src/features/Conversation/ChatInput/QueueTray.tsx
index 3b0d2986b70..eaab6dbb136 100644
--- a/src/features/Conversation/ChatInput/QueueTray.tsx
+++ b/src/features/Conversation/ChatInput/QueueTray.tsx
@@ -10,6 +10,7 @@ import { useSingleton } from '@/hooks/useSingleton';
import { useChatStore } from '@/store/chat';
import { operationSelectors } from '@/store/chat/selectors';
import {
+ isServerDeliveringQueuedMessage,
type QueuedFile,
type QueuedMessage,
reconstructUploadFilesFromQueue,
@@ -218,6 +219,24 @@ const QueueTray = memo(() => {
// when the user clicks the pencil.
// A follow-up queued on the server may already be on its way into the run;
// then it is neither edited nor sent again.
+ // Still in the tray: a run took it and the agent has not read it yet.
+ // Gone: it already landed in the conversation.
+ const toastAlreadyDelivered = useCallback(
+ (id: string) => {
+ const pending = useChatStore
+ .getState()
+ .queuedMessages[contextKey]?.find((queued) => queued.id === id);
+ toast.info(
+ t(
+ pending && isServerDeliveringQueuedMessage(pending)
+ ? 'inputQueue.alreadyDelivering'
+ : 'inputQueue.alreadyDelivered',
+ ),
+ );
+ },
+ [contextKey, t],
+ );
+
const withdraw = useCallback(
async (msg: QueuedMessage) => {
const withdrawn = await withdrawQueuedMessage(contextKey, msg.id).catch((error) => {
@@ -225,10 +244,10 @@ const QueueTray = memo(() => {
toast.error(t('inputQueue.withdrawFailed'));
return undefined;
});
- if (withdrawn === false) toast.info(t('inputQueue.alreadyDelivered'));
+ if (withdrawn === false) toastAlreadyDelivered(msg.id);
return !!withdrawn;
},
- [contextKey, t, withdrawQueuedMessage],
+ [contextKey, toastAlreadyDelivered, withdrawQueuedMessage],
);
const handleEdit = useCallback(
@@ -267,7 +286,7 @@ const QueueTray = memo(() => {
msg,
withdraw: (queued) => withdrawQueuedMessage(contextKey, queued.id),
});
- if (outcome === 'delivered') toast.info(t('inputQueue.alreadyDelivered'));
+ if (outcome === 'delivered') toastAlreadyDelivered(msg.id);
} finally {
setSendingId(undefined);
}
@@ -277,7 +296,7 @@ const QueueTray = memo(() => {
toast.error(t('inputQueue.sendNowFailed'));
});
},
- [context, contextKey, sendNowGate, t, withdrawQueuedMessage],
+ [context, contextKey, sendNowGate, t, toastAlreadyDelivered, withdrawQueuedMessage],
);
if (queuedMessages.length === 0) return null;
@@ -289,12 +308,19 @@ const QueueTray = memo(() => {
// 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". A heterogeneous
// CLI run only drains once the whole run ends, not after the current step.
- const hintText = t(getQueuedHintKey({ count: queuedMessages.length, waitsForRunEnd }));
+ // One a run already took is no longer part of that merge: it says where it
+ // is instead and offers nothing to do with it.
+ const waitingCount = queuedMessages.filter((msg) => !isServerDeliveringQueuedMessage(msg)).length;
+ const hintText = t(getQueuedHintKey({ count: waitingCount, waitsForRunEnd }));
return (
<Flexbox className={styles.container} gap={0}>
{queuedMessages.map((msg, index) => {
const previews = msg.filesPreview ?? [];
+ // A "send now" in progress keeps its row as is: it is interrupting the
+ // run to take this message back, and shows that with its spinner.
+ const delivering = isServerDeliveringQueuedMessage(msg) && sendingId !== msg.id;
+ const rowHint = delivering ? t('inputQueue.deliveringHint') : hintText;
return (
<Flexbox
horizontal
@@ -332,39 +358,43 @@ const QueueTray = memo(() => {
{/* Collapsed form. It is display:none while the sentence fits, so
it adds no tab stop there; when it shows it is a real
focusable control carrying the wording as its name. */}
- <Tooltip title={hintText}>
- <button aria-label={hintText} className={styles.hintGlyph} type={'button'}>
+ <Tooltip title={rowHint}>
+ <button aria-label={rowHint} className={styles.hintGlyph} type={'button'}>
<Icon icon={Info} size={13} />
</button>
</Tooltip>
- <span className={styles.hintText}>{hintText}</span>
+ <span className={styles.hintText}>{rowHint}</span>
</span>
<div style={{ flex: 1 }} />
- <ActionIcon
- aria-label={t('inputQueue.edit')}
- disabled={sendingId === msg.id}
- icon={Pencil}
- size="small"
- title={t('inputQueue.edit')}
- onClick={() => handleEdit(msg)}
- />
- <ActionIcon
- aria-label={t('inputQueue.sendNow')}
- disabled={!!sendingId}
- icon={ArrowUp}
- loading={sendingId === msg.id}
- size="small"
- title={t('inputQueue.sendNow')}
- onClick={() => handleSendNow(msg)}
- />
- <ActionIcon
- aria-label={t('inputQueue.delete')}
- disabled={sendingId === msg.id}
- icon={Trash2}
- size="small"
- title={t('inputQueue.delete')}
- onClick={() => withdraw(msg)}
- />
+ {!delivering && (
+ <>
+ <ActionIcon
+ aria-label={t('inputQueue.edit')}
+ disabled={sendingId === msg.id}
+ icon={Pencil}
+ size="small"
+ title={t('inputQueue.edit')}
+ onClick={() => handleEdit(msg)}
+ />
+ <ActionIcon
+ aria-label={t('inputQueue.sendNow')}
+ disabled={!!sendingId}
+ icon={ArrowUp}
+ loading={sendingId === msg.id}
+ size="small"
+ title={t('inputQueue.sendNow')}
+ onClick={() => handleSendNow(msg)}
+ />
+ <ActionIcon
+ aria-label={t('inputQueue.delete')}
+ disabled={sendingId === msg.id}
+ icon={Trash2}
+ size="small"
+ title={t('inputQueue.delete')}
+ onClick={() => withdraw(msg)}
+ />
+ </>
+ )}
</Flexbox>
);
})}
diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.test.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.test.ts
index b4e7e0f7208..e71f569226e 100644
--- a/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.test.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.test.ts
@@ -378,9 +378,11 @@ describe('server queue watch while a run delivers', () => {
await handOffQueuedMessage(get, key, context, 'q1', async () => request);
await vi.advanceTimersByTimeAsync(SERVER_QUEUE_POLL_MS);
- expect(queue()).toHaveLength(1);
+ expect(queue()).toEqual([expect.objectContaining({ id: 'q1', serverDelivering: true })]);
await vi.advanceTimersByTimeAsync(SERVER_QUEUE_POLL_MS);
+ // Given back: waiting again, so it can be edited or withdrawn once more.
expect(queue()).toHaveLength(1);
+ expect(queue()[0].serverDelivering).toBeUndefined();
await vi.advanceTimersByTimeAsync(SERVER_QUEUE_POLL_MS);
expect(list).toHaveBeenCalledTimes(3);
expect(queue()).toHaveLength(0);
@@ -448,7 +450,10 @@ describe('server queue watch while a run delivers', () => {
});
await expect(withdrawQueuedMessage(get, key, 'q1')).resolves.toBe(false);
- expect(queue()).toEqual([expect.objectContaining({ id: 'q1', serverDelivery: 'server' })]);
+ // Marked as on its way, so the tray stops offering edit / send now / delete.
+ expect(queue()).toEqual([
+ expect.objectContaining({ id: 'q1', serverDelivering: true, serverDelivery: 'server' }),
+ ]);
});
it('stores the composer state with the follow-up, so a reload can resend it as typed', async () => {
@@ -577,6 +582,17 @@ describe('restoreServerQueuedMessages', () => {
expect(queue()).toHaveLength(0);
});
+ it('restores one a run is already delivering as on its way', async () => {
+ vi.spyOn(aiAgentService, 'listQueuedFollowUps')
+ .mockResolvedValueOnce([pending('q1', { delivering: true })])
+ .mockResolvedValue([pending('q1', { delivering: true })]);
+ startRun();
+
+ await restoreServerQueuedMessages(get, context);
+
+ expect(queue()).toEqual([expect.objectContaining({ id: 'q1', serverDelivering: true })]);
+ });
+
it('brings back the composer state and selections it was sent with', async () => {
const editorData = { root: { type: 'root' } };
vi.spyOn(aiAgentService, 'listQueuedFollowUps')
@@ -738,6 +754,22 @@ describe('withdrawQueuedMessage / reclaimServerQueuedMessages', () => {
expect(queue()).toHaveLength(0);
});
+ it('after a stop, clears the delivering mark of one it took back', async () => {
+ get().enqueueMessage(
+ key,
+ queued('q1', { serverDelivering: true, serverDelivery: 'server', serverRequest: request }),
+ );
+ vi.spyOn(aiAgentService, 'removeQueuedFollowUp').mockResolvedValue({
+ removed: true,
+ state: 'removed',
+ });
+
+ await reclaimServerQueuedMessages(get, key);
+
+ expect(queue()[0].serverDelivering).toBeUndefined();
+ expect(queue()[0].serverDelivery).toBeUndefined();
+ });
+
it('after a stop, keeps here what the server still had and drops what it took', async () => {
holdOnServer('waiting');
holdOnServer('taken');
diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.ts
index 4ad27595101..a673cd6a4fb 100644
--- a/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/serverSteerQueue.ts
@@ -344,11 +344,21 @@ export const watchServerQueue = (get: Get, contextKey: string, context: Conversa
try {
// Taken by a run but not confirmed (`delivering`) still counts as held:
// a failed delivery returns it to the queue.
- const notDelivered = new Set(
- (await aiAgentService.listQueuedFollowUps(surfaceOf(held[0].serverRequest!))).map(
- (entry) => entry.id,
- ),
+ const entries = await aiAgentService.listQueuedFollowUps(surfaceOf(held[0].serverRequest!));
+ const notDelivered = new Set(entries.map((entry) => entry.id));
+ // Mirror which ones a run already took, so the tray stops offering to
+ // edit or withdraw them instead of failing when the user tries.
+ const delivering = new Set(
+ entries.filter((entry) => entry.delivering).map((entry) => entry.id),
);
+ for (const message of held) {
+ if (!notDelivered.has(message.id)) continue;
+ const isDelivering = delivering.has(message.id);
+ if (!!message.serverDelivering !== isDelivering)
+ get().updateQueuedMessage(contextKey, message.id, {
+ serverDelivering: isDelivering || undefined,
+ });
+ }
const settledDelivered = new Set<string>();
for (const message of held) {
if (!message.serverUnconfirmed) continue;
@@ -452,6 +462,7 @@ export const restoreServerQueuedMessages = async (
id: entry.id,
interruptMode: 'soft',
serverDelivery: 'server',
+ ...(entry.delivering && { serverDelivering: true }),
serverRequest: {
agentId,
appContext: { threadId: null, topicId },
@@ -499,6 +510,7 @@ export const reclaimServerQueuedMessages = (get: Get, contextKey: string): Promi
// this client holds it now.
if (ownsWithdrawn(message, state))
get().updateQueuedMessage(contextKey, message.id, {
+ serverDelivering: undefined,
serverDelivery: undefined,
serverUnconfirmed: undefined,
});
@@ -536,7 +548,10 @@ export const withdrawQueuedMessage = async (
id,
});
// Taken but not settled: it stays shown until it lands or comes back.
- if (state === 'delivering') return false;
+ if (state === 'delivering') {
+ get().updateQueuedMessage(contextKey, id, { serverDelivering: true });
+ return false;
+ }
get().removeQueuedMessage(contextKey, id);
return ownsWithdrawn(message, state);
}
diff --git a/src/store/chat/slices/operation/actions.ts b/src/store/chat/slices/operation/actions.ts
index 8827a42692c..d8f055acc8b 100644
--- a/src/store/chat/slices/operation/actions.ts
+++ b/src/store/chat/slices/operation/actions.ts
@@ -1015,7 +1015,12 @@ export class OperationActionsImpl {
updateQueuedMessage = (
contextKey: string,
messageId: string,
- patch: Partial<Pick<QueuedMessage, 'serverDelivery' | 'serverRequest' | 'serverUnconfirmed'>>,
+ patch: Partial<
+ Pick<
+ QueuedMessage,
+ 'serverDelivering' | 'serverDelivery' | 'serverRequest' | 'serverUnconfirmed'
+ >
+ >,
): void => {
this.#set(
produce((state: ChatStore) => {
diff --git a/src/store/chat/slices/operation/types.queuedDelivery.test.ts b/src/store/chat/slices/operation/types.queuedDelivery.test.ts
new file mode 100644
index 00000000000..03f1f8526cd
--- /dev/null
+++ b/src/store/chat/slices/operation/types.queuedDelivery.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from 'vitest';
+
+import { isServerDeliveringQueuedMessage, type QueuedMessage } from './types';
+
+const queued = (patch: Partial<QueuedMessage> = {}): QueuedMessage => ({
+ content: 'next',
+ createdAt: 1,
+ id: 'q1',
+ interruptMode: 'soft',
+ ...patch,
+});
+
+describe('isServerDeliveringQueuedMessage', () => {
+ it('is true for a follow-up the server holds and a run already took', () => {
+ expect(
+ isServerDeliveringQueuedMessage(queued({ serverDelivering: true, serverDelivery: 'server' })),
+ ).toBe(true);
+ });
+
+ it('is false for one still waiting on the server', () => {
+ expect(isServerDeliveringQueuedMessage(queued({ serverDelivery: 'server' }))).toBe(false);
+ });
+
+ // A stop hands it back to this client: the row must offer its actions
+ // again, even if the flag from the last poll was never cleared.
+ it('is false once only this client holds it again', () => {
+ expect(isServerDeliveringQueuedMessage(queued({ serverDelivering: true }))).toBe(false);
+ expect(
+ isServerDeliveringQueuedMessage(
+ queued({ serverDelivering: true, serverDelivery: 'appending' }),
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/src/store/chat/slices/operation/types.ts b/src/store/chat/slices/operation/types.ts
index f65602e5af0..432e8e0de90 100644
--- a/src/store/chat/slices/operation/types.ts
+++ b/src/store/chat/slices/operation/types.ts
@@ -338,6 +338,13 @@ export interface QueuedMessage {
id: string;
interruptMode: 'soft' | 'hard';
metadata?: MessageMetadata;
+ /**
+ * A run already took this follow-up from the server queue and is handing it
+ * to the agent (a live Claude Code session reads it after its current step).
+ * It can no longer be edited, sent now or deleted; it leaves the tray once
+ * the agent confirms it, or turns back into a waiting entry if that fails.
+ */
+ serverDelivering?: boolean;
/**
* Where the server holds this follow-up: `appending` while it is being
* handed to the server queue behind the running Gateway run, `server` once
@@ -362,6 +369,14 @@ export interface QueuedMessage {
export const isClientHeldQueuedMessage = (message: QueuedMessage): boolean =>
!message.serverDelivery;
+/**
+ * Whether a run already took the queued message from the server and is
+ * handing it to the agent. Only a message the server still holds counts: one
+ * taken back to this client is waiting here again, whatever flag it kept.
+ */
+export const isServerDeliveringQueuedMessage = (message: QueuedMessage): boolean =>
+ message.serverDelivery === 'server' && !!message.serverDelivering;
+
/**
* Merged message ready for injection
*/