Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🎴 feat: Render Background Tasks as Native Tool Cards (#16407)

lia-by-librechat[bot]696ebedce04c
diff --git a/client/src/components/Chat/Messages/Content/BackgroundTaskCard.tsx b/client/src/components/Chat/Messages/Content/BackgroundTaskCard.tsx
new file mode 100644
index 0000000000..b46897aa91
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/BackgroundTaskCard.tsx
@@ -0,0 +1,158 @@
+import type { BackgroundTaskStatus, BackgroundTaskView } from './Parts/background';
+import type { TranslationKeys } from '~/hooks';
+import { backgroundTaskMessageKey, backgroundTaskNoteKey } from './Parts/guidance';
+import { ToolIcon, getToolIconType, OutputRenderer } from './ToolOutput';
+import { formatBackgroundCodeOutput } from './Parts/background';
+import { parseToolName } from '~/utils/toolLabels';
+import { getToolDisplayLabel, cn } from '~/utils';
+import { useLocalize } from '~/hooks';
+
+const STATUS: Record<BackgroundTaskStatus, { label: TranslationKeys; dot: string }> = {
+ dispatched: { label: 'com_ui_subagent_thread_status_dispatched', dot: 'bg-text-tertiary' },
+ running: { label: 'com_ui_background_tasks_running', dot: 'bg-status-info' },
+ stopping: { label: 'com_ui_background_tasks_stopping', dot: 'bg-status-warning' },
+ accepted: { label: 'com_ui_background_tasks_control_queued', dot: 'bg-status-info' },
+ claimed: { label: 'com_ui_background_tasks_result_claimed', dot: 'bg-text-tertiary' },
+ not_running: { label: 'com_ui_background_tasks_not_running', dot: 'bg-status-warning' },
+ control_not_found: {
+ label: 'com_ui_background_tasks_control_not_found',
+ dot: 'bg-status-warning',
+ },
+ completed: { label: 'com_ui_background_tasks_completed', dot: 'bg-status-success' },
+ error: { label: 'com_ui_failed', dot: 'bg-status-error' },
+ failed: { label: 'com_ui_failed', dot: 'bg-status-error' },
+ interrupted: { label: 'com_ui_subagent_thread_status_interrupted', dot: 'bg-status-error' },
+ cancelled: { label: 'com_ui_cancelled', dot: 'bg-status-warning' },
+};
+
+export default function BackgroundTaskCard({
+ task,
+ mcpIconMap,
+ mcpServerNames,
+}: {
+ task: BackgroundTaskView;
+ mcpIconMap?: Map<string, string>;
+ mcpServerNames?: readonly string[];
+}) {
+ const localize = useLocalize();
+ const isSubagent = task.toolName === 'subagent';
+ const parsedName = parseToolName(task.toolName, mcpServerNames);
+ const serverName = parsedName.mcpServer;
+ let title = getToolDisplayLabel(task.toolName, localize, mcpServerNames);
+ if (isSubagent) {
+ title = localize('com_ui_background_tasks_subagent');
+ } else if (serverName) {
+ title = parsedName.toolName;
+ }
+ const subtitle = task.subagentType || serverName;
+ const iconUrl = serverName ? mcpIconMap?.get(serverName) : undefined;
+ const iconType = getToolIconType(task.toolName);
+ const isCode = iconType === 'bash_tool' || iconType === 'execute_code';
+ const state = STATUS[task.status];
+ const failed =
+ task.status === 'error' || task.status === 'failed' || task.status === 'interrupted';
+ const result = task.result?.trim() ? task.result : undefined;
+ const error = task.error?.trim() && task.error !== result ? task.error : undefined;
+ const noteKey = task.note ? backgroundTaskNoteKey(task.note) : undefined;
+ const messageKey = task.message ? backgroundTaskMessageKey(task.message) : undefined;
+ let delivery: string | undefined;
+ if (task.delivery === 'pending') {
+ delivery = localize('com_ui_background_tasks_result_pending');
+ } else if (task.delivery === 'failed') {
+ delivery = localize('com_ui_background_tasks_result_undelivered');
+ }
+
+ return (
+ <div
+ className="min-w-0 rounded-lg border border-border-light bg-surface-secondary/50 p-3"
+ data-testid="background-task-card"
+ >
+ <div className="flex min-w-0 items-start gap-2.5">
+ <span className="flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-tertiary">
+ <ToolIcon type={iconType} iconUrl={iconUrl} className="text-text-primary" />
+ </span>
+ <div className="min-w-0 flex-1 pt-0.5">
+ <div className="truncate text-sm font-semibold text-text-primary" title={title}>
+ {title}
+ </div>
+ {subtitle && <div className="truncate text-xs text-text-secondary">{subtitle}</div>}
+ {delivery && (
+ <div
+ className={cn(
+ 'mt-0.5 text-xs',
+ task.delivery === 'failed' ? 'text-status-warning' : 'text-text-secondary',
+ )}
+ >
+ {delivery}
+ </div>
+ )}
+ </div>
+ <span
+ className={cn(
+ 'inline-flex shrink-0 items-center gap-1.5 rounded-full bg-surface-tertiary px-2 py-1 text-xs text-text-secondary',
+ failed && 'text-status-error',
+ )}
+ >
+ <span className={cn('size-1.5 rounded-full', state.dot)} aria-hidden="true" />
+ {localize(state.label)}
+ </span>
+ </div>
+ {result && (
+ <div className="mt-3 border-t border-border-light pt-2.5">
+ <div
+ className={cn(
+ 'mb-1.5 text-xs font-medium',
+ failed && !error ? 'text-status-error' : 'text-text-secondary',
+ )}
+ >
+ {localize(failed && !error ? 'com_ui_error' : 'com_ui_output')}
+ </div>
+ <div className="min-w-0 rounded-md bg-surface-primary p-2.5">
+ <OutputRenderer
+ text={isCode ? formatBackgroundCodeOutput(result) : result}
+ copyText={result}
+ />
+ </div>
+ </div>
+ )}
+ {error && (
+ <div className="mt-3 border-t border-border-light pt-2.5">
+ <div className="mb-1.5 text-xs font-medium text-status-error">
+ {localize('com_ui_error')}
+ </div>
+ <div className="min-w-0 rounded-md bg-surface-primary p-2.5">
+ <OutputRenderer
+ text={isCode ? formatBackgroundCodeOutput(error) : error}
+ copyText={error}
+ />
+ </div>
+ </div>
+ )}
+ {!result && !error && task.resultClaimed && task.status !== 'claimed' && (
+ <p className="mt-2 text-xs text-text-secondary">
+ {localize('com_ui_background_tasks_result_claimed')}
+ </p>
+ )}
+ {!result && !error && task.resultAvailable && !task.resultClaimed && (
+ <p className="mt-2 text-xs text-text-secondary">
+ {localize('com_ui_background_tasks_result_available')}
+ </p>
+ )}
+ {noteKey && <p className="mt-2 text-xs text-text-secondary">{localize(noteKey)}</p>}
+ {messageKey && messageKey !== noteKey && (
+ <p className="mt-2 text-xs text-text-secondary">{localize(messageKey)}</p>
+ )}
+ {!result &&
+ !error &&
+ !task.resultAvailable &&
+ !task.resultClaimed &&
+ task.result === '' &&
+ !task.note &&
+ !task.message && (
+ <p className="mt-2 text-xs text-text-secondary">
+ {localize('com_ui_background_tasks_no_output')}
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsx
index 21500f0b5e..480f81b340 100644
--- a/client/src/components/Chat/Messages/Content/Part.tsx
+++ b/client/src/components/Chat/Messages/Content/Part.tsx
@@ -31,6 +31,7 @@ import {
getActivityLabelText,
getPartKeyIndex,
} from '~/utils';
+import BackgroundTaskCall from './Parts/BackgroundTaskCall';
import { getAskUserQuestionPart } from '~/utils/approval';
import AskUserQuestionCall from './AskUserQuestionCall';
import { isBashProgrammaticToolCall } from './routing';
@@ -302,6 +303,21 @@ const Part = memo(function Part({
onExpand={onToolExpand}
/>
);
+ } else if (toolCall.name === Constants.CHECK_BACKGROUND_TASK) {
+ return (
+ <BackgroundTaskCall
+ args={toolCall.args}
+ output={toolCall.output ?? ''}
+ initialProgress={toolCall.progress ?? 0.1}
+ isSubmitting={isSubmitting}
+ runStepStatus={toolCall.runStepStatus}
+ runStepDurationMs={toolCall.runStepDurationMs}
+ attachments={attachments}
+ hideAttachments={hideAttachments}
+ onExpand={onToolExpand}
+ toolCallId={toolCallId}
+ />
+ );
} else if (toolCall.name === 'skill') {
return (
<SkillCall
diff --git a/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx b/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx
new file mode 100644
index 0000000000..8a4a95d63e
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx
@@ -0,0 +1,234 @@
+import { useMemo, useState, useCallback } from 'react';
+import type { PartMetadata, TAttachment } from 'librechat-data-provider';
+import { backgroundListGuidanceKeys, backgroundTaskNoticeKey } from './guidance';
+import { backgroundTaskOutcome, parseBackgroundTaskOutput } from './background';
+import ProgressText from '~/components/Chat/Messages/Content/ProgressText';
+import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
+import { useLocalize, useLazyCollapseBody } from '~/hooks';
+import { toolPanelSpacingClassName } from '../disclosure';
+import { ToolIcon, OutputRenderer } from '../ToolOutput';
+import BackgroundTaskCard from '../BackgroundTaskCard';
+import useToolCallState from './useToolCallState';
+import { AttachmentGroup } from './Attachment';
+import { useToolCallIntent } from './intent';
+import ToolCallInfo from '../ToolCallInfo';
+import { TOOL_ROW_CLASSES } from '../rows';
+import { cn } from '~/utils';
+
+export default function BackgroundTaskCall({
+ args,
+ output = '',
+ initialProgress = 0.1,
+ isSubmitting,
+ runStepStatus,
+ runStepDurationMs,
+ attachments,
+ hideAttachments = false,
+ onExpand,
+ toolCallId,
+}: {
+ args?: string | Record<string, unknown>;
+ output?: string;
+ initialProgress?: number;
+ isSubmitting: boolean;
+ runStepStatus?: PartMetadata['runStepStatus'];
+ runStepDurationMs?: PartMetadata['runStepDurationMs'];
+ attachments?: TAttachment[];
+ hideAttachments?: boolean;
+ onExpand?: () => void;
+ toolCallId?: string;
+}) {
+ const localize = useLocalize();
+ const [showRaw, setShowRaw] = useState(false);
+ const mcpIconMap = useMCPIconMap();
+ const mcpServerNames = useMCPServerNames();
+ const intent = useToolCallIntent(args);
+ const display = useMemo(() => parseBackgroundTaskOutput(output), [output]);
+ const input = useMemo(() => {
+ if (typeof args === 'string') {
+ return args;
+ }
+ try {
+ return JSON.stringify(args ?? {}) ?? '';
+ } catch {
+ return '';
+ }
+ }, [args]);
+ const hasParams = input.trim() !== '' && input.trim() !== '{}';
+ const outcome = backgroundTaskOutcome(display);
+ const noticeText =
+ display?.kind === 'notice'
+ ? localize(backgroundTaskNoticeKey(display.status, display.message))
+ : undefined;
+ const listGuidance = useMemo(
+ () => (display?.kind === 'list' ? backgroundListGuidanceKeys(display) : []),
+ [display],
+ );
+ const { showCode, toggleCode, expandStyle, expandRef, phase, hasContent } = useToolCallState({
+ initialProgress,
+ isSubmitting,
+ output,
+ hasInput: hasParams || (attachments?.length ?? 0) > 0,
+ onExpand,
+ runStepStatus,
+ extraError: outcome === 'failed',
+ extraCancelled: outcome === 'cancelled',
+ });
+ const { shouldRenderBody, mountBody, handleTransitionEnd } = useLazyCollapseBody(showCode);
+ const handleToggle = useCallback(() => {
+ mountBody();
+ toggleCode();
+ }, [mountBody, toggleCode]);
+
+ let finishedText = intent ?? localize('com_ui_background_tasks_checked');
+ if (phase === 'cancelled') {
+ finishedText =
+ outcome === 'cancelled' && noticeText != null ? noticeText : localize('com_ui_cancelled');
+ } else if (phase === 'failed' && outcome !== 'failed') {
+ finishedText = intent ?? localize('com_ui_background_tasks_checked');
+ } else if (noticeText != null) {
+ finishedText = noticeText;
+ } else if (display?.kind === 'list' && outcome === 'failed') {
+ finishedText = localize('com_ui_background_tasks_incomplete');
+ }
+
+ let announcedText = finishedText;
+ if (phase === 'running') {
+ announcedText = localize('com_ui_background_tasks_checking');
+ } else if (phase === 'failed' && (noticeText == null || outcome !== 'failed')) {
+ announcedText =
+ display?.kind === 'list'
+ ? localize('com_ui_background_tasks_incomplete')
+ : localize('com_ui_failed_subject', { 0: localize('com_ui_background_tasks') });
+ }
+
+ return (
+ <>
+ <span className="sr-only" aria-live="polite" aria-atomic="true">
+ {announcedText}
+ </span>
+ <div
+ className={TOOL_ROW_CLASSES}
+ data-testid="background-task-call"
+ data-tool-call-id={toolCallId}
+ >
+ <ProgressText
+ phase={phase}
+ onClick={handleToggle}
+ inProgressText={intent ?? localize('com_ui_background_tasks_checking')}
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ icon={<ToolIcon type="background_tasks" isAnimating={phase === 'running'} />}
+ hasInput={hasContent}
+ isExpanded={showCode}
+ />
+ </div>
+ <div
+ style={expandStyle}
+ onTransitionEnd={handleTransitionEnd}
+ data-tool-call-output-id={toolCallId}
+ >
+ <div className="overflow-hidden" ref={expandRef}>
+ {hasContent && shouldRenderBody && (
+ <div
+ className={cn(
+ toolPanelSpacingClassName,
+ 'overflow-hidden rounded-lg border border-border-light bg-surface-secondary',
+ )}
+ >
+ {display?.kind === 'task' && (
+ <div className="p-2.5">
+ <BackgroundTaskCard
+ task={display.task}
+ mcpIconMap={mcpIconMap}
+ mcpServerNames={mcpServerNames}
+ />
+ </div>
+ )}
+ {display?.kind === 'list' && (
+ <div className="p-2.5">
+ <div className="mb-2 flex items-center gap-2 text-xs font-medium text-text-secondary">
+ {localize('com_ui_background_tasks')}
+ <span className="rounded-full bg-surface-tertiary px-1.5 tabular-nums">
+ {display.tasks.length}
+ </span>
+ </div>
+ {display.tasks.length > 0 ? (
+ <ul
+ tabIndex={0}
+ aria-label={localize('com_ui_background_tasks')}
+ className="flex max-h-96 flex-col gap-2 overflow-y-auto pr-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy"
+ >
+ {display.tasks.map((task) => (
+ <li key={task.taskId}>
+ <BackgroundTaskCard
+ task={task}
+ mcpIconMap={mcpIconMap}
+ mcpServerNames={mcpServerNames}
+ />
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <p className="text-sm text-text-secondary">
+ {localize('com_ui_background_tasks_empty')}
+ </p>
+ )}
+ {(display.partial || display.warning) && (
+ <p role="alert" className="mt-2 text-xs text-status-warning">
+ {localize('com_ui_background_tasks_incomplete')}
+ </p>
+ )}
+ {listGuidance.map((key) => (
+ <p key={key} className="mt-2 text-xs text-text-secondary">
+ {localize(key)}
+ </p>
+ ))}
+ </div>
+ )}
+ {display?.kind === 'notice' && (
+ <p
+ className={cn(
+ 'p-3 text-sm',
+ outcome === 'failed' || display.status === 'result_persisting'
+ ? 'text-status-warning'
+ : 'text-text-secondary',
+ )}
+ >
+ {noticeText}
+ </p>
+ )}
+ {(display == null || hasParams) && (
+ <div className={cn(display != null && 'border-t border-border-light')}>
+ <ToolCallInfo
+ input={input}
+ output={display == null ? output : undefined}
+ attachments={attachments}
+ />
+ </div>
+ )}
+ {display != null && (
+ <details
+ className="border-t border-border-light px-3 py-2"
+ onToggle={(event) => setShowRaw(event.currentTarget.open)}
+ >
+ <summary className="cursor-pointer rounded text-xs text-text-secondary hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy">
+ {localize('com_ui_background_tasks_raw_details')}
+ </summary>
+ {showRaw && (
+ <div className="mt-2 rounded-md bg-surface-primary p-2.5">
+ <OutputRenderer text={output} copyText={output} />
+ </div>
+ )}
+ </details>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+ {!hideAttachments && attachments && attachments.length > 0 && (
+ <AttachmentGroup attachments={attachments} />
+ )}
+ </>
+ );
+}
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/BackgroundTaskCall.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/BackgroundTaskCall.test.tsx
new file mode 100644
index 0000000000..45078e9cb4
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/BackgroundTaskCall.test.tsx
@@ -0,0 +1,429 @@
+import React from 'react';
+import { RecoilRoot } from 'recoil';
+import { fireEvent, render, screen, within } from '@testing-library/react';
+import BackgroundTaskCall from '../BackgroundTaskCall';
+
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useProgress: (progress: number) => progress,
+ useExpandCollapse: jest.requireActual('~/hooks/Messages/useExpandCollapse').default,
+ useLazyCollapseBody: jest.requireActual('~/hooks/Messages/useLazyCollapseBody').default,
+}));
+
+jest.mock('~/hooks/MCP', () => ({
+ useMCPIconMap: () => new Map(),
+ useMCPServerNames: () => [],
+}));
+
+jest.mock('~/utils', () => ({
+ cn: (...classes: Array<string | false | null | undefined>) => classes.filter(Boolean).join(' '),
+ getToolDisplayLabel: (name: string) =>
+ (({ bash_tool: 'Code', web_search: 'Web Search' }) as Record<string, string>)[name] ?? name,
+}));
+
+jest.mock('../../ProgressText', () => ({
+ __esModule: true,
+ default: ({
+ phase,
+ inProgressText,
+ finishedText,
+ onClick,
+ hasInput,
+ isExpanded,
+ }: {
+ phase: string;
+ inProgressText: string;
+ finishedText: string;
+ onClick: () => void;
+ hasInput: boolean;
+ isExpanded: boolean;
+ }) => (
+ <button
+ type="button"
+ data-testid="task-header"
+ data-phase={phase}
+ aria-expanded={isExpanded}
+ disabled={!hasInput}
+ onClick={onClick}
+ >
+ {phase === 'running' ? inProgressText : finishedText}
+ </button>
+ ),
+}));
+
+jest.mock('../../ToolOutput', () => ({
+ ToolIcon: ({ type }: { type: string }) => <span data-testid="tool-icon">{type}</span>,
+ getToolIconType: (name: string) => name,
+ getMCPServerName: () => '',
+ OutputRenderer: ({ text, copyText }: { text: string; copyText?: string }) => (
+ <pre data-testid="task-output" data-copy-text={copyText}>
+ {text}
+ </pre>
+ ),
+ isError: () => false,
+}));
+
+jest.mock('../../ToolCallInfo', () => ({
+ __esModule: true,
+ default: ({ input, output }: { input: string; output?: string }) => (
+ <div data-testid="tool-call-info" data-input={input} data-output={output} />
+ ),
+}));
+
+jest.mock('../Attachment', () => ({
+ AttachmentGroup: () => <div data-testid="task-attachments" />,
+}));
+
+const completed = {
+ background_task_id: 'bg-1',
+ tool: 'bash_tool',
+ status: 'completed',
+ result: 'stdout:\nchecked at=2026-09-27T00:11:09Z\n{"checks":[]}\n[exit code: 0]',
+};
+
+function renderCall(
+ output: string,
+ props: Partial<React.ComponentProps<typeof BackgroundTaskCall>> = {},
+) {
+ return render(
+ <RecoilRoot>
+ <BackgroundTaskCall
+ args={'{"background_task_id":"bg-1"}'}
+ output={output}
+ isSubmitting={false}
+ initialProgress={1}
+ {...props}
+ />
+ </RecoilRoot>,
+ );
+}
+
+describe('BackgroundTaskCall', () => {
+ it('presents a completed code task as a native result without leaking its JSON envelope', () => {
+ renderCall(JSON.stringify(completed));
+ const header = screen.getByTestId('task-header');
+ expect(header).toHaveTextContent('com_ui_background_tasks_checked');
+ expect(header).toHaveAttribute('aria-expanded', 'false');
+ expect(screen.queryByTestId('task-output')).not.toBeInTheDocument();
+
+ fireEvent.click(header);
+ const card = screen.getByTestId('background-task-card');
+ expect(within(card).getByText('Code')).toBeInTheDocument();
+ expect(within(card).getByText('com_ui_background_tasks_completed')).toBeInTheDocument();
+ expect(within(card).getByTestId('tool-icon')).toHaveTextContent('bash_tool');
+ expect(within(card).getByTestId('task-output')).toHaveTextContent('checked at=2026-09-27');
+ expect(within(card).getByTestId('task-output').textContent).toContain('{\n "checks": []\n}');
+ expect(within(card).getByTestId('task-output')).toHaveAttribute(
+ 'data-copy-text',
+ completed.result,
+ );
+ expect(screen.getByTestId('tool-call-info')).not.toHaveAttribute('data-output');
+ expect(screen.queryByText(/"background_task_id"/)).not.toBeInTheDocument();
+ });
+
+ it('renders an empty list as an empty state and warns when discovery is incomplete', () => {
+ renderCall(JSON.stringify({ tasks: [], outstanding: 0, partial: true, warning: 'Try again.' }));
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'failed');
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getByText('com_ui_background_tasks_empty')).toBeInTheDocument();
+ expect(screen.getByRole('alert')).toHaveTextContent('com_ui_background_tasks_incomplete');
+ expect(screen.queryByText('Try again.')).not.toBeInTheDocument();
+ });
+
+ it('distinguishes a running task from a finished result pending automatic delivery', () => {
+ renderCall(
+ JSON.stringify({
+ tasks: [
+ { background_task_id: 'bg-1', tool: 'web_search', status: 'running' },
+ {
+ background_task_id: 'bg-2',
+ tool: 'bash_tool',
+ status: 'completed',
+ delivery: 'pending',
+ result_available: true,
+ },
+ ],
+ outstanding: 2,
+ }),
+ { args: '{}' },
+ );
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getByRole('list', { name: 'com_ui_background_tasks' })).toHaveAttribute(
+ 'tabindex',
+ '0',
+ );
+ const [running, pending] = screen.getAllByTestId('background-task-card');
+ expect(within(running).getByText('Web Search')).toBeInTheDocument();
+ expect(within(running).getByText('com_ui_background_tasks_running')).toBeInTheDocument();
+ expect(within(pending).getByText('com_ui_background_tasks_result_pending')).toBeInTheDocument();
+ expect(
+ within(pending).getByText('com_ui_background_tasks_result_available'),
+ ).toBeInTheDocument();
+ expect(within(pending).queryByText('com_ui_background_tasks_no_output')).toBeNull();
+ });
+
+ it('shows an error with a failed task outcome and its actual error text', () => {
+ renderCall(
+ JSON.stringify({ ...completed, status: 'error', result: undefined, error: 'Disk full' }),
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'failed');
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getByText('com_ui_failed')).toBeInTheDocument();
+ expect(screen.getByText('Disk full')).toBeInTheDocument();
+ });
+
+ it('shows accepted subagent controls as queued while preserving the control id in raw details', () => {
+ renderCall(
+ JSON.stringify({
+ background_task_id: 'bg-1',
+ tool: 'subagent',
+ subagent_type: 'researcher',
+ status: 'accepted',
+ control_id: 'control-42',
+ }),
+ );
+ fireEvent.click(screen.getByTestId('task-header'));
+ const card = screen.getByTestId('background-task-card');
+ expect(within(card).getByText('com_ui_background_tasks_control_queued')).toBeInTheDocument();
+ expect(within(card).getByText('researcher')).toBeInTheDocument();
+ expect(within(card).queryByText('com_ui_background_tasks_completed')).toBeNull();
+ expect(screen.queryByText(/control-42/)).not.toBeInTheDocument();
+ });
+
+ it('keeps an already-claimed subagent result out of the available-on-request state', () => {
+ renderCall(
+ JSON.stringify({
+ background_task_id: 'bg-1',
+ tool: 'subagent',
+ subagent_type: 'researcher',
+ status: 'claimed',
+ result_available: true,
+ result_claimed: true,
+ }),
+ );
+ fireEvent.click(screen.getByTestId('task-header'));
+ const card = screen.getByTestId('background-task-card');
+ expect(within(card).getByText('com_ui_background_tasks_result_claimed')).toBeInTheDocument();
+ expect(within(card).queryByText('com_ui_background_tasks_result_available')).toBeNull();
+ });
+
+ it('marks an interrupted subagent poll as failed even when the poll run step succeeded', () => {
+ renderCall(
+ JSON.stringify({
+ background_task_id: 'bg-1',
+ tool: 'subagent',
+ status: 'interrupted',
+ error: 'Server restarted before completion.',
+ }),
+ { runStepStatus: 'completed' },
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'failed');
+ fireEvent.click(screen.getByTestId('task-header'));
+ const card = screen.getByTestId('background-task-card');
+ expect(within(card).getByText('com_ui_subagent_thread_status_interrupted')).toBeInTheDocument();
+ expect(within(card).getByText('Server restarted before completion.')).toBeInTheDocument();
+ });
+
+ it.each([
+ ['invalid', 'com_ui_background_tasks_notice_invalid'],
+ ['rejected', 'com_ui_background_tasks_notice_rejected'],
+ ['unavailable', 'com_ui_background_tasks_notice_unavailable'],
+ ['not_found', 'com_ui_background_tasks_notice_not_found'],
+ ['outcome_unknown', 'com_ui_background_tasks_notice_outcome_unknown'],
+ ['result_unavailable', 'com_ui_background_tasks_notice_result_unavailable'],
+ ])(
+ 'announces a %s warning notice as a failed check even if the tool step succeeded',
+ (status, label) => {
+ const hostMessage = 'Host advice in English, for the agent only.';
+ const { container } = renderCall(JSON.stringify({ status, message: hostMessage }), {
+ runStepStatus: 'completed',
+ });
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'failed');
+ expect(container.querySelector('[aria-live="polite"]')).toHaveTextContent(label);
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getAllByText(label).length).toBeGreaterThan(1);
+ expect(screen.queryByText(hostMessage)).not.toBeInTheDocument();
+ },
+ );
+
+ it('localizes guidance without promising that a running task or pending result has finished', () => {
+ const note =
+ 'Still running outside this turn; its result will arrive as a new turn when it finishes.';
+ const message =
+ 'Automatic completion delivery is enabled for this subagent task. Continue independent work if available; otherwise end this turn and the host will resume you when the task finishes. Do not repeatedly poll an unchanged running task. Use check_background_task only for explicit status or control, or as a fallback if automatic delivery is unavailable.';
+ renderCall(
+ JSON.stringify({
+ tasks: [{ background_task_id: 'bg-1', tool: 'subagent', status: 'running', note, message }],
+ message,
+ }),
+ );
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getByText('com_ui_background_tasks_running_elsewhere')).toBeInTheDocument();
+ expect(screen.getAllByText('com_ui_background_tasks_subagent_wakeup_guidance')).toHaveLength(2);
+ expect(screen.queryByText(note)).not.toBeInTheDocument();
+ expect(screen.queryByText(message)).not.toBeInTheDocument();
+ });
+
+ it('shows unknown host prose only inside raw task details, while preserving tool result text', () => {
+ const note = 'Advice from a later server version.';
+ const raw = JSON.stringify({
+ background_task_id: 'bg-1',
+ tool: 'bash_tool',
+ status: 'completed',
+ result: 'Tool-created output remains visible in its own language.',
+ note,
+ });
+ renderCall(raw);
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.getByText('com_ui_background_tasks_more_in_raw_details')).toBeInTheDocument();
+ expect(
+ screen.getByText('Tool-created output remains visible in its own language.'),
+ ).toBeInTheDocument();
+ expect(screen.queryByText(note)).not.toBeInTheDocument();
+ const details = screen.getByText('com_ui_background_tasks_raw_details').closest('details');
+ if (details == null) {
+ throw new Error('Task details disclosure is missing');
+ }
+ details.open = true;
+ fireEvent(details, new Event('toggle', { bubbles: true }));
+ expect(screen.getAllByTestId('task-output')).toHaveLength(2);
+ expect(screen.getAllByTestId('task-output')[1]).toHaveTextContent(note);
+ });
+
+ it('shows control notices as localized text and preserves unfamiliar responses as raw output', () => {
+ const { rerender } = renderCall(
+ JSON.stringify({
+ status: 'delivery_scheduled',
+ background_task_id: 'bg-1',
+ message: 'This result will arrive in a new turn.',
+ }),
+ );
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(
+ screen.getAllByText('com_ui_background_tasks_notice_delivery_scheduled').length,
+ ).toBeGreaterThan(1);
+ expect(screen.queryByText('This result will arrive in a new turn.')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('tool-call-info')).not.toHaveAttribute('data-output');
+
+ const raw = '{"status":"unexpected","result":"preserve this"}';
+ rerender(
+ <RecoilRoot>
+ <BackgroundTaskCall args="{}" output={raw} isSubmitting={false} initialProgress={1} />
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call-info')).toHaveAttribute('data-output', raw);
+ });
+
+ it('reveals the exact control receipt only when raw details are opened', () => {
+ const output = JSON.stringify({
+ status: 'accepted',
+ background_task_id: 'bg-1',
+ control_id: 'control-42',
+ message: 'The control request was queued.',
+ });
+ renderCall(output);
+ fireEvent.click(screen.getByTestId('task-header'));
+ expect(screen.queryByText(/control-42/)).not.toBeInTheDocument();
+
+ const details = screen.getByText('com_ui_background_tasks_raw_details').closest('details');
+ expect(details).not.toBeNull();
+ if (details == null) {
+ throw new Error('Task details disclosure is missing');
+ }
+ details.open = true;
+ fireEvent(details, new Event('toggle', { bubbles: true }));
+ expect(screen.getByTestId('task-output')).toHaveTextContent('control-42');
+ });
+
+ it('announces stable progress across intent deltas, then the settled intent once', () => {
+ const firstArgs = '{"intent":"Checking the backgr';
+ const finalArgs = '{"intent":"Checking the background task","background_task_id":"bg-1"}';
+ const { container, rerender } = renderCall('', {
+ args: firstArgs,
+ isSubmitting: true,
+ initialProgress: 0.1,
+ });
+ const announcement = container.querySelector('[aria-live="polite"]');
+ expect(announcement).toHaveClass('sr-only');
+ expect(announcement).toHaveAttribute('aria-atomic', 'true');
+ expect(announcement).toHaveTextContent('com_ui_background_tasks_checking');
+ rerender(
+ <RecoilRoot>
+ <BackgroundTaskCall args={finalArgs} output="" isSubmitting={true} initialProgress={0.1} />
+ </RecoilRoot>,
+ );
+ expect(announcement).toHaveTextContent('com_ui_background_tasks_checking');
+ rerender(
+ <RecoilRoot>
+ <BackgroundTaskCall
+ args={finalArgs}
+ output={JSON.stringify(completed)}
+ isSubmitting={false}
+ initialProgress={1}
+ runStepStatus="completed"
+ />
+ </RecoilRoot>,
+ );
+ expect(announcement).toHaveTextContent('Checking the background task');
+ });
+
+ it.each([
+ ['delivery_scheduled', 'com_ui_background_tasks_notice_delivery_scheduled'],
+ ['result_persisting', 'com_ui_background_tasks_notice_result_persisting'],
+ ])('announces %s as a pending state rather than a task failure', (status, label) => {
+ const { container } = renderCall(
+ JSON.stringify({ status, message: 'Untranslated backend status message.' }),
+ { runStepStatus: 'completed' },
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'completed');
+ expect(screen.getByTestId('task-header')).toHaveTextContent(label);
+ expect(container.querySelector('[aria-live="polite"]')).toHaveTextContent(label);
+ });
+
+ it.each([
+ ['failed', 'com_ui_failed_subject'],
+ ['cancelled', 'com_ui_cancelled'],
+ ])('announces an explicit %s tool-run status ahead of benign output', (runStepStatus, label) => {
+ const { container } = renderCall(
+ JSON.stringify({ status: 'delivery_scheduled', message: 'The result will arrive later.' }),
+ { runStepStatus: runStepStatus as 'failed' | 'cancelled' },
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', runStepStatus);
+ expect(container.querySelector('[aria-live="polite"]')).toHaveTextContent(label);
+ expect(container.querySelector('[aria-live="polite"]')).not.toHaveTextContent(
+ 'com_ui_background_tasks_notice_delivery_scheduled',
+ );
+ });
+
+ it('announces cancellation rather than a successful check when a result is discarded', () => {
+ const { container } = renderCall(
+ JSON.stringify({ status: 'cancelled', message: 'Discarded the result.' }),
+ {
+ runStepStatus: 'completed',
+ },
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'cancelled');
+ expect(container.querySelector('[aria-live="polite"]')).toHaveTextContent(
+ 'com_ui_background_tasks_result_discarded',
+ );
+ });
+
+ it('keeps the row in progress while a poll streams and updates it after settlement', () => {
+ const { rerender } = renderCall('', { isSubmitting: true, initialProgress: 0.1 });
+ expect(screen.getByTestId('task-header')).toHaveAttribute('data-phase', 'running');
+ fireEvent.click(screen.getByTestId('task-header'));
+ rerender(
+ <RecoilRoot>
+ <BackgroundTaskCall
+ args={'{"background_task_id":"bg-1"}'}
+ output={JSON.stringify(completed)}
+ isSubmitting={false}
+ initialProgress={1}
+ runStepStatus="completed"
+ />
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('task-header')).toHaveAttribute('aria-expanded', 'true');
+ expect(screen.getByTestId('task-output')).toHaveTextContent('checked at=2026-09-27');
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/background.test.ts b/client/src/components/Chat/Messages/Content/Parts/__tests__/background.test.ts
new file mode 100644
index 0000000000..6726754532
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/background.test.ts
@@ -0,0 +1,293 @@
+import {
+ backgroundTaskOutcome,
+ formatBackgroundCodeOutput,
+ parseBackgroundTaskOutput,
+} from '../background';
+
+describe('formatBackgroundCodeOutput', () => {
+ it('indents a JSON log line without changing surrounding stdout and exit code', () => {
+ const raw =
+ 'stdout:\nchecked at=2026-09-27T00:11:09Z\n{"checks":[{"status":"IN_PROGRESS"}]}\n[exit code: 0]';
+ expect(formatBackgroundCodeOutput(raw)).toBe(
+ 'stdout:\nchecked at=2026-09-27T00:11:09Z\n{\n "checks": [\n {\n "status": "IN_PROGRESS"\n }\n ]\n}\n[exit code: 0]',
+ );
+ });
+
+ it('leaves non-JSON lines, single JSON results, and very large outputs untouched', () => {
+ expect(formatBackgroundCodeOutput('stdout:\n[exit code: 0]')).toBe('stdout:\n[exit code: 0]');
+ expect(formatBackgroundCodeOutput('{"ok":true}')).toBe('{"ok":true}');
+ const large = `stdout:\n${'a'.repeat(64_001)}`;
+ expect(formatBackgroundCodeOutput(large)).toBe(large);
+ });
+});
+
+describe('backgroundTaskOutcome', () => {
+ it.each([
+ 'invalid',
+ 'rejected',
+ 'unavailable',
+ 'not_found',
+ 'outcome_unknown',
+ 'result_unavailable',
+ 'error',
+ 'future_control_rejected',
+ ])('flags the %s notice as a failed task check, despite a successful tool run step', (status) => {
+ const display = parseBackgroundTaskOutput(JSON.stringify({ status, message: 'Host advice' }));
+ expect(backgroundTaskOutcome(display)).toBe('failed');
+ });
+
+ it.each(['delivery_scheduled', 'result_persisting'])(
+ 'does not mistake the %s retry state for a failed task',
+ (status) => {
+ const display = parseBackgroundTaskOutput(JSON.stringify({ status, message: 'Host advice' }));
+ expect(backgroundTaskOutcome(display)).toBeUndefined();
+ },
+ );
+
+ it.each(['error', 'interrupted', 'failed', 'not_running', 'control_not_found'])(
+ 'flags a %s task or control receipt as failed',
+ (status) => {
+ const display = parseBackgroundTaskOutput(
+ JSON.stringify({ background_task_id: 't1', tool: 'subagent', status }),
+ );
+ expect(backgroundTaskOutcome(display)).toBe('failed');
+ },
+ );
+
+ it('distinguishes a discarded result from a still-running cancellation request', () => {
+ expect(
+ backgroundTaskOutcome(
+ parseBackgroundTaskOutput(
+ JSON.stringify({ status: 'cancelled', message: 'Result discarded.' }),
+ ),
+ ),
+ ).toBe('cancelled');
+ expect(
+ backgroundTaskOutcome(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ background_task_id: 't1',
+ tool: 'bash_tool',
+ status: 'cancellation_requested',
+ }),
+ ),
+ ),
+ ).toBeUndefined();
+ });
+
+ it('warns about an incomplete list, not an ordinary list of already failed tasks', () => {
+ const incomplete = parseBackgroundTaskOutput(
+ JSON.stringify({ tasks: [], partial: true, warning: 'Some results are missing.' }),
+ );
+ const complete = parseBackgroundTaskOutput(
+ JSON.stringify({
+ tasks: [{ background_task_id: 't1', tool: 'bash_tool', status: 'error' }],
+ partial: false,
+ }),
+ );
+ expect(backgroundTaskOutcome(incomplete)).toBe('failed');
+ expect(backgroundTaskOutcome(complete)).toBeUndefined();
+ });
+});
+
+describe('parseBackgroundTaskOutput', () => {
+ it('parses an ordinary task result with the receipt and its exact output', () => {
+ const result =
+ 'stdout:\nchecked at=2026-09-27T00:11:09Z\n{"checks":[{"status":"IN_PROGRESS"}]}\n[exit code: 0]';
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'completed',
+ result,
+ delivery: 'delivered',
+ started_at: '2026-09-27T00:11:00Z',
+ }),
+ ),
+ ).toEqual({
+ kind: 'task',
+ task: {
+ taskId: 'task-1',
+ toolName: 'bash_tool',
+ status: 'completed',
+ result,
+ delivery: 'delivered',
+ },
+ });
+ });
+
+ it('parses running, failed, cancelled, and pending tasks in a list without inventing results', () => {
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ tasks: [
+ { background_task_id: 't1', tool: 'web_search', status: 'running' },
+ {
+ background_task_id: 't2',
+ tool: 'execute_code',
+ status: 'completed',
+ delivery: 'pending',
+ result_available: true,
+ },
+ {
+ background_task_id: 't3',
+ tool: 'read_file',
+ status: 'error',
+ error: 'Could not read file',
+ delivery: 'failed',
+ },
+ {
+ background_task_id: 't4',
+ tool: 'subagent',
+ status: 'cancelled',
+ subagent_type: 'researcher',
+ },
+ ],
+ outstanding: 2,
+ partial: true,
+ warning: 'Some results were not loaded.',
+ }),
+ ),
+ ).toEqual({
+ kind: 'list',
+ tasks: [
+ { taskId: 't1', toolName: 'web_search', status: 'running' },
+ {
+ taskId: 't2',
+ toolName: 'execute_code',
+ status: 'completed',
+ delivery: 'pending',
+ resultAvailable: true,
+ },
+ {
+ taskId: 't3',
+ toolName: 'read_file',
+ status: 'error',
+ error: 'Could not read file',
+ delivery: 'failed',
+ },
+ {
+ taskId: 't4',
+ toolName: 'subagent',
+ status: 'cancelled',
+ subagentType: 'researcher',
+ },
+ ],
+ partial: true,
+ warning: 'Some results were not loaded.',
+ });
+ });
+
+ it('shows a cancellation request as still stopping rather than cancelled', () => {
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'cancellation_requested',
+ message: 'Cancellation requested; execution continues until settlement.',
+ }),
+ ),
+ ).toMatchObject({ kind: 'task', task: { status: 'stopping' } });
+ });
+
+ it('shows a cancellation_requested flag in a list as stopping, not cancelled', () => {
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ tasks: [
+ {
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'running',
+ cancellation_requested: true,
+ },
+ ],
+ outstanding: 1,
+ }),
+ ),
+ ).toMatchObject({ kind: 'list', tasks: [{ status: 'stopping' }] });
+ });
+
+ it('keeps accepted subagent controls queued rather than labeling them completed', () => {
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ background_task_id: 'subagent-1',
+ subagent_thread_id: 'thread-1',
+ tool: 'subagent',
+ subagent_type: 'researcher',
+ status: 'accepted',
+ control_id: 'control-42',
+ }),
+ ),
+ ).toEqual({
+ kind: 'task',
+ task: {
+ taskId: 'subagent-1',
+ toolName: 'subagent',
+ subagentType: 'researcher',
+ status: 'accepted',
+ },
+ });
+ });
+
+ it.each(['claimed', 'not_running', 'control_not_found'])(
+ 'renders a subagent %s receipt as a task instead of raw JSON',
+ (status) => {
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'subagent',
+ subagent_type: 'researcher',
+ status,
+ result_available: true,
+ result_claimed: true,
+ }),
+ ),
+ ).toEqual({
+ kind: 'task',
+ task: {
+ taskId: 'task-1',
+ toolName: 'subagent',
+ subagentType: 'researcher',
+ status,
+ resultAvailable: true,
+ resultClaimed: true,
+ },
+ });
+ },
+ );
+
+ it('recognizes delivery and invalid-id notices without pretending they are tasks', () => {
+ const message = 'The result is already assigned to an automatic continuation.';
+ expect(
+ parseBackgroundTaskOutput(
+ JSON.stringify({ status: 'delivery_scheduled', background_task_id: 't1', message }),
+ ),
+ ).toEqual({ kind: 'notice', status: 'delivery_scheduled', message });
+ });
+
+ it.each([
+ '',
+ '{"tasks":',
+ JSON.stringify({ tasks: [{ background_task_id: 't1', tool: 'bash_tool', status: 'unknown' }] }),
+ JSON.stringify({
+ tasks: [
+ { background_task_id: 't1', tool: 'bash_tool', status: 'running', delivery: 'unknown' },
+ ],
+ }),
+ JSON.stringify({
+ background_task_id: 't1',
+ tool: 'bash_tool',
+ status: 'completed',
+ result: {},
+ }),
+ JSON.stringify({ status: 'completed', result: 'unrelated tool output' }),
+ JSON.stringify({ tasks: 'corrupt', status: 'invalid', message: 'Retry the request.' }),
+ ])('keeps malformed or unknown tool output on the raw fallback path', (output) => {
+ expect(parseBackgroundTaskOutput(output)).toBeNull();
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/guidance.test.ts b/client/src/components/Chat/Messages/Content/Parts/__tests__/guidance.test.ts
new file mode 100644
index 0000000000..348f86cb79
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/guidance.test.ts
@@ -0,0 +1,177 @@
+import {
+ backgroundListGuidanceKeys,
+ backgroundTaskMessageKey,
+ backgroundTaskNoteKey,
+ backgroundTaskNoticeKey,
+} from '../guidance';
+import { parseBackgroundTaskOutput } from '../background';
+
+describe('background task host guidance', () => {
+ it.each([
+ [
+ 'Generated files were saved and attached to the tool call that dispatched this task.',
+ 'com_ui_background_tasks_files_attached',
+ ],
+ [
+ 'Output and any generated files are being attached to the tool call that dispatched this task.',
+ 'com_ui_background_tasks_files_attaching',
+ ],
+ [
+ 'The tool produced an artifact that is not included inline.',
+ 'com_ui_background_tasks_artifact_not_inline',
+ ],
+ [
+ 'Still running outside this turn; its result will arrive as a new turn when it finishes.',
+ 'com_ui_background_tasks_running_elsewhere',
+ ],
+ [
+ 'Finished, but its result has not been delivered; it will arrive as a new turn unless you poll or cancel it.',
+ 'com_ui_background_tasks_pending_delivery_note',
+ ],
+ [
+ 'Automatic delivery failed; this result will not arrive as a new turn. Poll it to collect the result.',
+ 'com_ui_background_tasks_failed_delivery_note',
+ ],
+ ])('localizes known task note variants: %s', (note, expected) => {
+ expect(backgroundTaskNoteKey(note)).toBe(expected);
+ });
+
+ it('keeps unknown host notes and messages behind raw details', () => {
+ expect(backgroundTaskNoteKey('New server-side note with context.')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ expect(backgroundTaskMessageKey('New server-side control advice.')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ expect(backgroundTaskNoteKey('constructor')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ expect(backgroundTaskMessageKey('__proto__')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ expect(backgroundTaskNoticeKey('constructor', 'Unexpected status.')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ });
+
+ it('localizes known task messages without losing the cancellation and automatic-delivery rules', () => {
+ expect(
+ backgroundTaskMessageKey(
+ 'Cancellation was requested. The task remains active until its executor settles; poll again for a terminal result.',
+ ),
+ ).toBe('com_ui_background_tasks_cancellation_requested');
+ expect(
+ backgroundTaskMessageKey(
+ 'Automatic completion delivery is enabled for this subagent task. Continue independent work if available; otherwise end this turn and the host will resume you when the task finishes. Do not repeatedly poll an unchanged running task. Use check_background_task only for explicit status or control, or as a fallback if automatic delivery is unavailable.',
+ ),
+ ).toBe('com_ui_background_tasks_subagent_wakeup_guidance');
+ });
+
+ it.each([
+ ['invalid', 'Wrong arguments.', 'com_ui_background_tasks_notice_invalid'],
+ ['rejected', 'Capacity reached.', 'com_ui_background_tasks_notice_rejected'],
+ ['not_found', 'No task here.', 'com_ui_background_tasks_notice_not_found'],
+ [
+ 'outcome_unknown',
+ 'Unable to confirm result.',
+ 'com_ui_background_tasks_notice_outcome_unknown',
+ ],
+ [
+ 'result_unavailable',
+ 'Receipt temporarily unavailable.',
+ 'com_ui_background_tasks_notice_result_unavailable',
+ ],
+ [
+ 'result_persisting',
+ 'Receipt is settling.',
+ 'com_ui_background_tasks_notice_result_persisting',
+ ],
+ [
+ 'delivery_scheduled',
+ 'Assigned to another poll.',
+ 'com_ui_background_tasks_notice_delivery_scheduled',
+ ],
+ ['unavailable', 'Process disconnected.', 'com_ui_background_tasks_notice_unavailable'],
+ ['cancelled', 'Result discarded.', 'com_ui_background_tasks_result_discarded'],
+ ])('gives %s a localized, conservative notice', (status, message, expected) => {
+ expect(backgroundTaskNoticeKey(status, message)).toBe(expected);
+ });
+
+ it('distinguishes disabled cancellation, unsupported controls, and a failed discard', () => {
+ expect(
+ backgroundTaskNoticeKey(
+ 'invalid',
+ 'Cancellation is not enabled for ordinary background tools.',
+ ),
+ ).toBe('com_ui_background_tasks_cancel_disabled');
+ expect(
+ backgroundTaskNoticeKey(
+ 'invalid',
+ 'This control action is supported only for subagent tasks.',
+ ),
+ ).toBe('com_ui_background_tasks_notice_subagent_only');
+ expect(
+ backgroundTaskNoticeKey(
+ 'unavailable',
+ 'The pending result could not be discarded right now. It may still arrive as a new turn; retry the cancel shortly.',
+ ),
+ ).toBe('com_ui_background_tasks_notice_discard_unavailable');
+ expect(backgroundTaskNoticeKey('new_status', 'Unexpected server advice.')).toBe(
+ 'com_ui_background_tasks_more_in_raw_details',
+ );
+ });
+
+ it('summarizes pending and failed delivery from task status, not backend English', () => {
+ const display = parseBackgroundTaskOutput(
+ JSON.stringify({
+ tasks: [
+ {
+ background_task_id: 'ordinary-pending',
+ tool: 'bash_tool',
+ status: 'completed',
+ delivery: 'pending',
+ },
+ {
+ background_task_id: 'ordinary-failed',
+ tool: 'read_file',
+ status: 'completed',
+ delivery: 'failed',
+ },
+ {
+ background_task_id: 'subagent-pending',
+ tool: 'subagent',
+ status: 'error',
+ delivery: 'pending',
+ },
+ { background_task_id: 'subagent-running', tool: 'subagent', status: 'running' },
+ ],
+ message:
+ 'Some other text. Automatic completion delivery is enabled for this subagent task.',
+ }),
+ );
+ if (display?.kind !== 'list') {
+ throw new Error('Expected a task list');
+ }
+ expect(backgroundListGuidanceKeys(display)).toEqual([
+ 'com_ui_background_tasks_pending_delivery_guidance',
+ 'com_ui_background_tasks_failed_delivery_guidance',
+ 'com_ui_background_tasks_subagent_pending_guidance',
+ 'com_ui_background_tasks_subagent_wakeup_guidance',
+ ]);
+ });
+
+ it('never promises automatic delivery for a running subagent without host guidance', () => {
+ const display = parseBackgroundTaskOutput(
+ JSON.stringify({
+ tasks: [{ background_task_id: 'subagent', tool: 'subagent', status: 'running' }],
+ message: 'Poll for results manually.',
+ }),
+ );
+ if (display?.kind !== 'list') {
+ throw new Error('Expected a task list');
+ }
+ expect(backgroundListGuidanceKeys(display)).toEqual([
+ 'com_ui_background_tasks_more_in_raw_details',
+ ]);
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/wakeup.test.ts b/client/src/components/Chat/Messages/Content/Parts/__tests__/wakeup.test.ts
index 682a2d62a3..a20ec801c3 100644
--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/wakeup.test.ts
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/wakeup.test.ts
@@ -73,6 +73,33 @@ describe('parseWakeupText', () => {
});
});
+ it('parses a cancelled background tool wake-up without exposing its host envelope', () => {
+ const text = [
+ 'A background tool task has finished. Continue using its durable result below.',
+ JSON.stringify([
+ {
+ background_task_id: 'bg-2',
+ tool_call_id: 'call-2',
+ tool: 'bash_tool',
+ status: 'cancelled',
+ result: 'Cancelled by the user.',
+ },
+ ]),
+ ].join('\n');
+ expect(parseWakeupText(text)).toEqual({
+ kind: 'background_tool',
+ tasks: [
+ {
+ taskId: 'bg-2',
+ toolCallId: 'call-2',
+ toolName: 'bash_tool',
+ status: 'cancelled',
+ result: 'Cancelled by the user.',
+ },
+ ],
+ });
+ });
+
it('parses a plural background tool wake-up', () => {
const text = [
'2 background tool tasks have finished. Continue using their durable results below.',
diff --git a/client/src/components/Chat/Messages/Content/Parts/background.ts b/client/src/components/Chat/Messages/Content/Parts/background.ts
new file mode 100644
index 0000000000..db5589de06
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/background.ts
@@ -0,0 +1,217 @@
+import type { BackgroundTaskDelivery } from 'librechat-data-provider';
+import type { WakeupTaskStatus } from './wakeup';
+
+export function formatBackgroundCodeOutput(output: string): string {
+ if (output.length > 64_000 || !output.includes('\n')) {
+ return output;
+ }
+ const lines = output.split('\n');
+ if (lines.length > 500) {
+ return output;
+ }
+ return lines
+ .map((line) => {
+ const trimmed = line.trim();
+ if (
+ trimmed.length < 2 ||
+ trimmed.length > 8_000 ||
+ !(
+ (trimmed.startsWith('{') && trimmed.endsWith('}')) ||
+ (trimmed.startsWith('[') && trimmed.endsWith(']'))
+ )
+ ) {
+ return line;
+ }
+ try {
+ const value: unknown = JSON.parse(trimmed);
+ if (value == null || typeof value !== 'object') {
+ return line;
+ }
+ const indent = line.slice(0, line.length - line.trimStart().length);
+ return `${indent}${JSON.stringify(value, null, 2).replace(/\n/g, `\n${indent}`)}`;
+ } catch {
+ return line;
+ }
+ })
+ .join('\n');
+}
+
+export type BackgroundTaskStatus =
+ | WakeupTaskStatus
+ | 'running'
+ | 'stopping'
+ | 'accepted'
+ | 'claimed'
+ | 'not_running'
+ | 'control_not_found'
+ | 'dispatched'
+ | 'failed'
+ | 'interrupted';
+
+export type BackgroundTaskView = {
+ taskId: string;
+ toolName: string;
+ status: BackgroundTaskStatus;
+ result?: string;
+ error?: string;
+ note?: string;
+ message?: string;
+ subagentType?: string;
+ resultAvailable?: boolean;
+ resultClaimed?: boolean;
+ delivery?: BackgroundTaskDelivery;
+};
+
+export type BackgroundTaskDisplay =
+ | { kind: 'task'; task: BackgroundTaskView }
+ | {
+ kind: 'list';
+ tasks: BackgroundTaskView[];
+ partial: boolean;
+ warning?: string;
+ message?: string;
+ }
+ | { kind: 'notice'; message: string; status: string };
+
+const PENDING_NOTICES = new Set(['delivery_scheduled', 'result_persisting']);
+
+/** The poll step succeeding is not proof that its underlying task or control succeeded. */
+export function backgroundTaskOutcome(
+ display: BackgroundTaskDisplay | null,
+): 'failed' | 'cancelled' | undefined {
+ if (display == null) {
+ return;
+ }
+ if (display.kind === 'notice') {
+ if (display.status === 'cancelled') {
+ return 'cancelled';
+ }
+ return PENDING_NOTICES.has(display.status) ? undefined : 'failed';
+ }
+ if (display.kind === 'list') {
+ return display.partial || display.warning ? 'failed' : undefined;
+ }
+ const status = display.task.status;
+ if (status === 'cancelled') {
+ return 'cancelled';
+ }
+ return status === 'error' ||
+ status === 'failed' ||
+ status === 'interrupted' ||
+ status === 'not_running' ||
+ status === 'control_not_found'
+ ? 'failed'
+ : undefined;
+}
+
+const isRecord = (value: unknown): value is Record<string, unknown> =>
+ value != null && typeof value === 'object' && !Array.isArray(value);
+
+const optionalString = (value: unknown): value is string | undefined =>
+ value === undefined || typeof value === 'string';
+
+const taskStatus = (value: unknown): BackgroundTaskStatus | null => {
+ if (value === 'cancellation_requested') {
+ return 'stopping';
+ }
+ if (
+ value === 'running' ||
+ value === 'accepted' ||
+ value === 'claimed' ||
+ value === 'not_running' ||
+ value === 'control_not_found' ||
+ value === 'completed' ||
+ value === 'error' ||
+ value === 'cancelled' ||
+ value === 'dispatched' ||
+ value === 'failed' ||
+ value === 'interrupted'
+ ) {
+ return value;
+ }
+ return null;
+};
+
+const deliveryStatus = (value: unknown): value is BackgroundTaskDelivery | undefined =>
+ value === undefined || value === 'pending' || value === 'failed' || value === 'delivered';
+
+function parseTask(value: unknown): BackgroundTaskView | null {
+ if (!isRecord(value)) {
+ return null;
+ }
+ const status = taskStatus(value.status);
+ if (
+ typeof value.background_task_id !== 'string' ||
+ value.background_task_id === '' ||
+ typeof value.tool !== 'string' ||
+ value.tool === '' ||
+ status == null ||
+ !optionalString(value.result) ||
+ !optionalString(value.error) ||
+ !optionalString(value.note) ||
+ !optionalString(value.message) ||
+ !optionalString(value.subagent_type) ||
+ (value.result_available != null && typeof value.result_available !== 'boolean') ||
+ (value.result_claimed != null && typeof value.result_claimed !== 'boolean') ||
+ !deliveryStatus(value.delivery)
+ ) {
+ return null;
+ }
+ return {
+ taskId: value.background_task_id,
+ toolName: value.tool,
+ status: status === 'running' && value.cancellation_requested === true ? 'stopping' : status,
+ ...(typeof value.result === 'string' ? { result: value.result } : {}),
+ ...(typeof value.error === 'string' ? { error: value.error } : {}),
+ ...(typeof value.note === 'string' ? { note: value.note } : {}),
+ ...(typeof value.message === 'string' ? { message: value.message } : {}),
+ ...(typeof value.subagent_type === 'string' ? { subagentType: value.subagent_type } : {}),
+ ...(value.result_available === true ? { resultAvailable: true } : {}),
+ ...(value.result_claimed === true ? { resultClaimed: true } : {}),
+ ...(value.delivery != null ? { delivery: value.delivery } : {}),
+ };
+}
+
+/** Only host-shaped results become cards. Unknown or partial output stays visible as raw tool output. */
+export function parseBackgroundTaskOutput(output?: string | null): BackgroundTaskDisplay | null {
+ if (!output || output.length > 2_000_000) {
+ return null;
+ }
+ const text = output.trim();
+ if (!text.startsWith('{') || !text.endsWith('}')) {
+ return null;
+ }
+ let payload: unknown;
+ try {
+ payload = JSON.parse(text) as unknown;
+ } catch {
+ return null;
+ }
+ if (!isRecord(payload)) {
+ return null;
+ }
+ if ('tasks' in payload && !Array.isArray(payload.tasks)) {
+ return null;
+ }
+ if (Array.isArray(payload.tasks)) {
+ const tasks = payload.tasks.map(parseTask);
+ if (tasks.some((task) => task == null)) {
+ return null;
+ }
+ return {
+ kind: 'list',
+ tasks: tasks as BackgroundTaskView[],
+ partial: payload.partial === true,
+ ...(typeof payload.warning === 'string' ? { warning: payload.warning } : {}),
+ ...(typeof payload.message === 'string' ? { message: payload.message } : {}),
+ };
+ }
+ const task = parseTask(payload);
+ if (task != null) {
+ return { kind: 'task', task };
+ }
+ if (typeof payload.status === 'string' && typeof payload.message === 'string') {
+ return { kind: 'notice', status: payload.status, message: payload.message };
+ }
+ return null;
+}
diff --git a/client/src/components/Chat/Messages/Content/Parts/guidance.ts b/client/src/components/Chat/Messages/Content/Parts/guidance.ts
new file mode 100644
index 0000000000..09e3821f58
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/guidance.ts
@@ -0,0 +1,106 @@
+import type { BackgroundTaskDisplay } from './background';
+import type { TranslationKeys } from '~/hooks';
+
+const RAW_DETAILS_KEY: TranslationKeys = 'com_ui_background_tasks_more_in_raw_details';
+
+/** Backend messages are model-facing English; show localized labels, not their raw prose. */
+const NOTE_KEYS: Record<string, TranslationKeys> = {
+ 'Generated files were saved and attached to the tool call that dispatched this task.':
+ 'com_ui_background_tasks_files_attached',
+ 'Output and any generated files are being attached to the tool call that dispatched this task.':
+ 'com_ui_background_tasks_files_attaching',
+ 'The tool produced an artifact that is not included inline.':
+ 'com_ui_background_tasks_artifact_not_inline',
+ 'Still running outside this turn; its result will arrive as a new turn when it finishes.':
+ 'com_ui_background_tasks_running_elsewhere',
+ 'Finished, but its result has not been delivered; it will arrive as a new turn unless you poll or cancel it.':
+ 'com_ui_background_tasks_pending_delivery_note',
+ 'Automatic delivery failed; this result will not arrive as a new turn. Poll it to collect the result.':
+ 'com_ui_background_tasks_failed_delivery_note',
+};
+
+const MESSAGE_KEYS: Record<string, TranslationKeys> = {
+ 'Cancellation was requested. The task remains active until its executor settles; poll again for a terminal result.':
+ 'com_ui_background_tasks_cancellation_requested',
+ 'Automatic completion delivery is enabled for this subagent task. Continue independent work if available; otherwise end this turn and the host will resume you when the task finishes. Do not repeatedly poll an unchanged running task. Use check_background_task only for explicit status or control, or as a fallback if automatic delivery is unavailable.':
+ 'com_ui_background_tasks_subagent_wakeup_guidance',
+};
+
+const NOTICE_KEYS: Record<string, TranslationKeys> = {
+ invalid: 'com_ui_background_tasks_notice_invalid',
+ rejected: 'com_ui_background_tasks_notice_rejected',
+ unavailable: 'com_ui_background_tasks_notice_unavailable',
+ not_found: 'com_ui_background_tasks_notice_not_found',
+ outcome_unknown: 'com_ui_background_tasks_notice_outcome_unknown',
+ result_unavailable: 'com_ui_background_tasks_notice_result_unavailable',
+ result_persisting: 'com_ui_background_tasks_notice_result_persisting',
+ delivery_scheduled: 'com_ui_background_tasks_notice_delivery_scheduled',
+ cancelled: 'com_ui_background_tasks_result_discarded',
+ error: 'com_ui_background_tasks_notice_error',
+};
+
+export const backgroundTaskNoteKey = (note: string): TranslationKeys =>
+ Object.hasOwn(NOTE_KEYS, note) ? NOTE_KEYS[note] : RAW_DETAILS_KEY;
+
+export const backgroundTaskMessageKey = (message: string): TranslationKeys =>
+ Object.hasOwn(MESSAGE_KEYS, message) ? MESSAGE_KEYS[message] : RAW_DETAILS_KEY;
+
+export function backgroundTaskNoticeKey(status: string, message: string): TranslationKeys {
+ if (
+ status === 'invalid' &&
+ message === 'Cancellation is not enabled for ordinary background tools.'
+ ) {
+ return 'com_ui_background_tasks_cancel_disabled';
+ }
+ if (
+ status === 'invalid' &&
+ message === 'This control action is supported only for subagent tasks.'
+ ) {
+ return 'com_ui_background_tasks_notice_subagent_only';
+ }
+ if (
+ status === 'unavailable' &&
+ message.startsWith('The pending result could not be discarded right now.')
+ ) {
+ return 'com_ui_background_tasks_notice_discard_unavailable';
+ }
+ return Object.hasOwn(NOTICE_KEYS, status) ? NOTICE_KEYS[status] : RAW_DETAILS_KEY;
+}
+
+export function backgroundListGuidanceKeys(
+ display: Extract<BackgroundTaskDisplay, { kind: 'list' }>,
+): TranslationKeys[] {
+ if (!display.message) {
+ return [];
+ }
+ let toolPending = false;
+ let toolFailed = false;
+ let subagentPending = false;
+ let subagentRunning = false;
+ for (const task of display.tasks) {
+ if (task.toolName === 'subagent') {
+ subagentPending ||= task.delivery === 'pending' && task.status !== 'running';
+ subagentRunning ||= task.status === 'running';
+ continue;
+ }
+ toolPending ||= task.delivery === 'pending' && task.status !== 'running';
+ toolFailed ||= task.delivery === 'failed';
+ }
+ const keys: TranslationKeys[] = [];
+ if (toolPending) {
+ keys.push('com_ui_background_tasks_pending_delivery_guidance');
+ }
+ if (toolFailed) {
+ keys.push('com_ui_background_tasks_failed_delivery_guidance');
+ }
+ if (subagentPending) {
+ keys.push('com_ui_background_tasks_subagent_pending_guidance');
+ }
+ if (
+ subagentRunning &&
+ display.message.includes('Automatic completion delivery is enabled for this subagent task.')
+ ) {
+ keys.push('com_ui_background_tasks_subagent_wakeup_guidance');
+ }
+ return keys.length > 0 ? keys : [RAW_DETAILS_KEY];
+}
diff --git a/client/src/components/Chat/Messages/Content/Parts/wakeup.ts b/client/src/components/Chat/Messages/Content/Parts/wakeup.ts
index ce46d45990..1b90e90ee6 100644
--- a/client/src/components/Chat/Messages/Content/Parts/wakeup.ts
+++ b/client/src/components/Chat/Messages/Content/Parts/wakeup.ts
@@ -72,7 +72,6 @@ const backgroundWakeupTask = (payload: unknown): WakeupTask | null => {
const status = wakeupStatus(payload.status);
if (
status == null ||
- status === 'cancelled' ||
typeof payload.background_task_id !== 'string' ||
typeof payload.tool_call_id !== 'string' ||
typeof payload.tool !== 'string' ||
diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
index 1b71b8923c..f51375058b 100644
--- a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
@@ -99,9 +99,10 @@ const VISIBLE_LINES = 15;
interface OutputRendererProps {
text: string;
+ copyText?: string;
}
-export default function OutputRenderer({ text }: OutputRendererProps) {
+export default function OutputRenderer({ text, copyText }: OutputRendererProps) {
const localize = useLocalize();
const { text: displayText, rawError, error, isJson } = useMemo(() => extractText(text), [text]);
const [isExpanded, setIsExpanded] = useState(false);
@@ -110,9 +111,9 @@ export default function OutputRenderer({ text }: OutputRendererProps) {
const handleCopy = useCallback(() => {
setIsCopied(true);
- copy(displayText, { format: 'text/plain' });
+ copy(copyText ?? displayText, { format: 'text/plain' });
setTimeout(() => setIsCopied(false), 3000);
- }, [displayText]);
+ }, [copyText, displayText]);
if (!displayText) {
return null;
diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/ToolIcon.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/ToolIcon.tsx
index 61babdc270..665b6335e0 100644
--- a/client/src/components/Chat/Messages/Content/ToolOutput/ToolIcon.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolOutput/ToolIcon.tsx
@@ -12,6 +12,7 @@ import {
Brain,
Zap,
Wrench,
+ ListChecks,
} from 'lucide-react';
import LangIcon from '~/components/Messages/Content/LangIcon';
import CustomIcon from '~/components/ui/CustomIcon';
@@ -32,6 +33,7 @@ export type ToolIconType =
| 'skill'
| 'read_file'
| 'bash_tool'
+ | 'background_tasks'
| 'ask_user_question'
| 'memory'
| 'action'
@@ -48,6 +50,7 @@ const ICON_MAP: Record<ToolIconType, React.ComponentType<{ className?: string }>
skill: ScrollText,
read_file: FileText,
bash_tool: BashIcon,
+ background_tasks: ListChecks,
ask_user_question: MessageCircleQuestion,
memory: Brain,
action: Zap,
@@ -61,6 +64,9 @@ export function getToolIconType(name: string): ToolIconType {
if (name.includes(Constants.mcp_delimiter)) {
return 'mcp';
}
+ if (name === Constants.CHECK_BACKGROUND_TASK) {
+ return 'background_tasks';
+ }
if (name === 'execute_code' || name === Constants.PROGRAMMATIC_TOOL_CALLING) {
return 'execute_code';
}
diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx
index 77ff54aaee..aff34c258f 100644
--- a/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx
@@ -1,5 +1,6 @@
import React from 'react';
-import { render, screen } from '@testing-library/react';
+import copy from 'copy-to-clipboard';
+import { fireEvent, render, screen } from '@testing-library/react';
import OutputRenderer, { isError } from '../OutputRenderer';
jest.mock('copy-to-clipboard', () => jest.fn());
@@ -10,7 +11,9 @@ jest.mock('~/hooks', () => ({
jest.mock('~/components/Messages/Content/CopyButton', () => ({
__esModule: true,
- default: () => <button type="button" data-testid="copy-output" />,
+ default: ({ onClick }: { onClick: () => void }) => (
+ <button type="button" data-testid="copy-output" onClick={onClick} />
+ ),
}));
describe('OutputRenderer', () => {
@@ -22,6 +25,13 @@ describe('OutputRenderer', () => {
expect(copyPositioner?.parentElement).toHaveClass('relative', 'pr-10');
});
+ it('copies original bytes when a code result has been formatted for display', () => {
+ const raw = 'stdout:\n{"ok":true}';
+ render(<OutputRenderer text={'stdout:\n{\n "ok": true\n}'} copyText={raw} />);
+ fireEvent.click(screen.getByTestId('copy-output'));
+ expect(copy).toHaveBeenCalledWith(raw, { format: 'text/plain' });
+ });
+
it('does not treat text between bracketed prefixes as a tool-call error', () => {
expect(isError('Error: [agent] unexpected [search] tool call failed: unavailable')).toBe(false);
});
diff --git a/client/src/components/Chat/Messages/Content/Wakeup.tsx b/client/src/components/Chat/Messages/Content/Wakeup.tsx
index 53c8b48cd7..7ef6cfe474 100644
--- a/client/src/components/Chat/Messages/Content/Wakeup.tsx
+++ b/client/src/components/Chat/Messages/Content/Wakeup.tsx
@@ -16,6 +16,7 @@ import { useLocalize, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
import { useOpenSubagentPanel } from '~/components/Chat/Subagents/surface';
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
import { useShareContext } from '~/Providers/ShareContext';
+import BackgroundTaskCard from './BackgroundTaskCard';
import { cn, getToolDisplayLabel } from '~/utils';
import { useMessageContext } from '~/Providers';
import { StackedToolIcons } from './ToolOutput';
@@ -33,15 +34,12 @@ const threadStatus = (status: WakeupTask['status']) =>
function WakeupTaskCard({
task,
- kind,
conversationId,
}: {
task: WakeupTask;
- kind: WakeupDisplay['kind'];
conversationId?: string | null;
}) {
const localize = useLocalize();
- const mcpServerNames = useMCPServerNames();
const { isSharedConvo } = useShareContext();
const { messageId } = useMessageContext();
const { byThreadId } = useParentSubagents();
@@ -78,10 +76,7 @@ function WakeupTaskCard({
}, [child, conversationId, isSharedConvo, messageId, task]);
const status = threadStatus(task.status);
const StatusIcon = subagentStatusIcon(status);
- const title =
- kind === 'subagent'
- ? (task.subagentType ?? '')
- : getToolDisplayLabel(task.toolName ?? '', localize, mcpServerNames);
+ const title = task.subagentType ?? '';
const hasResult = task.result.trim() !== '';
const openActivity = useCallback(() => {
@@ -150,7 +145,7 @@ const Wakeup = memo(function Wakeup({
setIsExpanded((previous) => !previous);
}, [mountBody]);
- const anyFailed = display.tasks.some((task) => task.status === 'error');
+ const anyFailed = display.tasks.some((task) => task.status !== 'completed');
const headerLabel = useMemo(() => {
if (display.kind === 'subagent') {
const status = display.tasks[0]?.status ?? 'completed';
@@ -159,11 +154,13 @@ const Wakeup = memo(function Wakeup({
if (display.tasks.length > 1) {
return localize('com_ui_wakeup_tasks_finished', { 0: String(display.tasks.length) });
}
- return localize(
- display.tasks[0]?.status === 'error'
- ? 'com_ui_wakeup_task_errored'
- : 'com_ui_wakeup_task_finished',
- );
+ if (display.tasks[0]?.status === 'cancelled') {
+ return localize('com_ui_wakeup_task_cancelled');
+ }
+ if (display.tasks[0]?.status === 'error') {
+ return localize('com_ui_wakeup_task_errored');
+ }
+ return localize('com_ui_wakeup_task_finished');
}, [display.kind, display.tasks, localize]);
const nameSummary = useMemo(() => {
@@ -226,17 +223,29 @@ const Wakeup = memo(function Wakeup({
{shouldRenderBody && (
<div className="overflow-hidden" ref={expandRef}>
<div className="pb-1">
- <div className="mt-1 text-xs text-text-secondary">
- {localize('com_ui_wakeup_explainer')}
- </div>
- {display.tasks.map((task) => (
- <WakeupTaskCard
- key={task.taskId}
- task={task}
- kind={display.kind}
- conversationId={conversationId}
- />
- ))}
+ {display.kind === 'subagent' && (
+ <div className="mt-1 text-xs text-text-secondary">
+ {localize('com_ui_wakeup_explainer')}
+ </div>
+ )}
+ {display.tasks.map((task) =>
+ display.kind === 'background_tool' ? (
+ <div key={task.taskId} className="my-2">
+ <BackgroundTaskCard
+ task={{
+ taskId: task.taskId,
+ toolName: task.toolName ?? '',
+ status: task.status,
+ result: task.result,
+ }}
+ mcpIconMap={mcpIconMap}
+ mcpServerNames={mcpServerNames}
+ />
+ </div>
+ ) : (
+ <WakeupTaskCard key={task.taskId} task={task} conversationId={conversationId} />
+ ),
+ )}
</div>
</div>
)}
diff --git a/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx
index bf6c75a6ad..c4488db080 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx
@@ -62,6 +62,13 @@ jest.mock('../ToolCall', () => ({
),
}));
+jest.mock('../Parts/BackgroundTaskCall', () => ({
+ __esModule: true,
+ default: ({ output }: { output: string }) => (
+ <div data-testid="background-task-call" data-output={output} />
+ ),
+}));
+
jest.mock('../Image', () => ({
__esModule: true,
default: ({ alignRight }: { alignRight?: boolean }) => (
@@ -222,6 +229,20 @@ describe('Part tool renderer selection', () => {
expect(screen.queryByTestId('tool-call')).not.toBeInTheDocument();
});
+ it('routes the native background poll tool to its structured task renderer', () => {
+ const output = JSON.stringify({ tasks: [], outstanding: 0 });
+ const part = toolCallPart(Constants.CHECK_BACKGROUND_TASK) as Extract<
+ TMessageContentParts,
+ { type: typeof ContentTypes.TOOL_CALL }
+ >;
+ Object.assign(part[ContentTypes.TOOL_CALL], { output });
+
+ renderPart(part);
+
+ expect(screen.getByTestId('background-task-call')).toHaveAttribute('data-output', output);
+ expect(screen.queryByTestId('tool-call')).not.toBeInTheDocument();
+ });
+
it('renders a cancelled generic background tool as cancelled', () => {
const part = toolCallPart('search_mcp_docs') as Extract<
TMessageContentParts,
diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
index 4013817d09..f7fdad90ba 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
@@ -144,6 +144,7 @@ jest.mock('~/utils', () => ({
create_file: 'Create File',
edit_file: 'Edit File',
ask_user_question: 'Question',
+ check_background_task: 'Background tasks',
};
return friendlyNames[name] ?? name;
},
@@ -857,6 +858,68 @@ describe('ToolCallGroup image hoisting', () => {
).toBeInTheDocument();
});
+ it.each([
+ ['error', '1 failed'],
+ ['cancelled', '1 cancelled'],
+ ['interrupted', '1 failed'],
+ ])('reflects a %s task poll in the collapsed group', (status, suffix) => {
+ renderGroup({
+ ...baseProps,
+ parts: [
+ {
+ part: makePart(
+ 'check-1',
+ JSON.stringify({
+ background_task_id: 'bg-1',
+ tool: 'bash_tool',
+ status,
+ ...(status === 'error' ? { error: 'Disk full' } : {}),
+ }),
+ Constants.CHECK_BACKGROUND_TASK,
+ ),
+ idx: 0,
+ },
+ ],
+ lastContentIdx: 0,
+ });
+
+ expect(screen.getByRole('button', { name: `Background tasks, ${suffix}` })).toBeInTheDocument();
+ });
+
+ it.each(['invalid', 'rejected', 'unavailable', 'outcome_unknown', 'result_unavailable'])(
+ 'shows a failed group for the %s background-task notice even when the poll step succeeds',
+ (status) => {
+ const part = makePart(
+ 'poll-1',
+ JSON.stringify({ status, message: 'Host guidance about the failed check.' }),
+ Constants.CHECK_BACKGROUND_TASK,
+ );
+ Object.assign(part[ContentTypes.TOOL_CALL] ?? {}, { runStepStatus: 'completed' });
+ renderGroup({ ...baseProps, parts: [{ part, idx: 0 }], lastContentIdx: 0 });
+ expect(
+ screen.getByRole('button', { name: 'Background tasks, 1 failed' }),
+ ).toBeInTheDocument();
+ },
+ );
+
+ it('marks an incomplete background-task list as a failed check', () => {
+ renderGroup({
+ ...baseProps,
+ parts: [
+ {
+ part: makePart(
+ 'poll-1',
+ JSON.stringify({ tasks: [], partial: true, warning: 'A replica is unreachable.' }),
+ Constants.CHECK_BACKGROUND_TASK,
+ ),
+ idx: 0,
+ },
+ ],
+ lastContentIdx: 0,
+ });
+ expect(screen.getByRole('button', { name: 'Background tasks, 1 failed' })).toBeInTheDocument();
+ });
+
it('counts background failures per step when provider call IDs repeat', () => {
const executions = [
{ stepId: 'step-success', status: 'completed' },
diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolIcon.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolIcon.test.tsx
index 4befd9df69..2734ccb44e 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/ToolIcon.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolIcon.test.tsx
@@ -26,6 +26,13 @@ describe('getToolIconType - ACTN-01: Action delimiter detection', () => {
expect(getToolIconType('some_plain_tool')).toBe('generic');
});
+ it('gives the native background-task tool its own icon while preserving MCP identity', () => {
+ expect(getToolIconType(Constants.CHECK_BACKGROUND_TASK)).toBe('background_tasks');
+ expect(
+ getToolIconType(`${Constants.CHECK_BACKGROUND_TASK}${Constants.mcp_delimiter}remote`),
+ ).toBe('mcp');
+ });
+
it('returns correct types for existing tool names', () => {
expect(getToolIconType('execute_code')).toBe('execute_code');
expect(getToolIconType(Constants.PROGRAMMATIC_TOOL_CALLING)).toBe('execute_code');
diff --git a/client/src/components/Chat/Messages/Content/__tests__/Wakeup.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/Wakeup.test.tsx
index 5d66cf7e7b..a694b0cdc4 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/Wakeup.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/Wakeup.test.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { RecoilRoot } from 'recoil';
import { useAtomValue } from 'jotai';
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, render, screen, within } from '@testing-library/react';
import type { ParentSubagentSummary } from 'librechat-data-provider';
import { activeSubagentPanel } from '~/components/Chat/Subagents/state';
import { ChatSurfaceHarness } from 'test/harness';
@@ -17,12 +17,20 @@ jest.mock('~/hooks', () => ({
}));
jest.mock('~/hooks/MCP', () => ({
- useMCPIconMap: () => ({}),
- useMCPServerNames: () => ({}),
+ useMCPIconMap: () => new Map(),
+ useMCPServerNames: () => [],
}));
jest.mock('../ToolOutput', () => ({
StackedToolIcons: () => <div data-testid="stacked-tool-icons" />,
+ ToolIcon: ({ type }: { type: string }) => <span data-testid="tool-icon">{type}</span>,
+ getToolIconType: (name: string) => name,
+ getMCPServerName: () => '',
+ OutputRenderer: ({ text, copyText }: { text: string; copyText?: string }) => (
+ <pre data-testid="task-output" data-copy-text={copyText}>
+ {text}
+ </pre>
+ ),
}));
jest.mock('../MarkdownLite', () => ({
@@ -173,10 +181,109 @@ describe('Wakeup', () => {
const header = screen.getByRole('button', { name: 'com_ui_wakeup_tasks_finished:2' });
fireEvent.click(header);
expect(screen.getByTestId('stacked-tool-icons')).toBeInTheDocument();
- expect(screen.getByText('com_ui_subagent_thread_status_completed')).toBeInTheDocument();
- expect(screen.getByText('com_ui_subagent_thread_status_failed')).toBeInTheDocument();
+ expect(screen.getByText('com_ui_background_tasks_completed')).toBeInTheDocument();
+ expect(screen.getByText('com_ui_failed')).toBeInTheDocument();
+ expect(screen.getAllByTestId('background-task-card')).toHaveLength(2);
+ expect(screen.getByText('com_ui_error')).toHaveClass('text-status-error');
+ expect(screen.queryByTestId('markdown')).not.toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'com_ui_wakeup_view_activity' }),
).not.toBeInTheDocument();
});
+
+ it('shows a cancelled background result as a warning with its task details', () => {
+ render(
+ <ChatSurfaceHarness>
+ <RecoilRoot>
+ <Wakeup
+ display={{
+ kind: 'background_tool',
+ tasks: [
+ {
+ taskId: 'bg-cancelled',
+ status: 'cancelled',
+ result: 'The task was stopped.',
+ toolCallId: 'call-cancelled',
+ toolName: 'bash_tool',
+ },
+ ],
+ }}
+ />
+ </RecoilRoot>
+ </ChatSurfaceHarness>,
+ );
+ const header = screen.getByRole('button', { name: 'com_ui_wakeup_task_cancelled' });
+ expect(header.querySelector('[role="status"]')).toHaveClass('text-text-warning');
+ fireEvent.click(header);
+ expect(screen.getByTestId('background-task-card')).toHaveTextContent('com_ui_cancelled');
+ expect(screen.getByTestId('task-output')).toHaveTextContent('The task was stopped.');
+ });
+
+ it('shows the originating MCP tool and its server separately', () => {
+ render(
+ <ChatSurfaceHarness>
+ <RecoilRoot>
+ <Wakeup
+ display={{
+ kind: 'background_tool',
+ tasks: [
+ {
+ taskId: 'bg-mcp',
+ status: 'completed',
+ result: 'Found 3 documents.',
+ toolCallId: 'call-mcp',
+ toolName: 'search_repository_mcp_Docs',
+ },
+ ],
+ }}
+ />
+ </RecoilRoot>
+ </ChatSurfaceHarness>,
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'com_ui_wakeup_task_finished' }));
+ const card = screen.getByTestId('background-task-card');
+ expect(within(card).getByText('search_repository')).toBeInTheDocument();
+ expect(within(card).getByText('Docs')).toBeInTheDocument();
+ expect(within(card).getByTestId('task-output')).toHaveTextContent('Found 3 documents.');
+ });
+
+ it('renders the code completion as tool output rather than prose or host-internal JSON', () => {
+ const output = 'stdout:\nchecked at=2026-09-27T00:11:09Z\n{"checks":[]}\n[exit code: 0]';
+ render(
+ <ChatSurfaceHarness>
+ <RecoilRoot>
+ <Wakeup
+ display={{
+ kind: 'background_tool',
+ tasks: [
+ {
+ taskId: 'bg-1',
+ status: 'completed',
+ result: output,
+ toolCallId: 'call-1',
+ toolName: 'bash_tool',
+ },
+ ],
+ }}
+ />
+ </RecoilRoot>
+ </ChatSurfaceHarness>,
+ );
+
+ const header = screen.getByRole('button', { name: 'com_ui_wakeup_task_finished' });
+ expect(header.parentElement).not.toHaveClass('w-[36rem]');
+ fireEvent.click(header);
+ expect(header.parentElement).toHaveClass('w-[36rem]');
+
+ const card = screen.getByTestId('background-task-card');
+ expect(card).toHaveTextContent('com_ui_tool_name_code');
+ expect(card).toHaveTextContent('com_ui_background_tasks_completed');
+ expect(screen.getByTestId('tool-icon')).toHaveTextContent('bash_tool');
+ expect(screen.getByText('com_ui_output')).toBeInTheDocument();
+ expect(screen.getByTestId('task-output')).toHaveTextContent('"checks": []');
+ expect(screen.getByTestId('task-output').textContent).toContain('{\n "checks": []\n}');
+ expect(screen.getByTestId('task-output')).toHaveAttribute('data-copy-text', output);
+ expect(screen.queryByText('com_ui_wakeup_explainer')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('markdown')).not.toBeInTheDocument();
+ });
});
diff --git a/client/src/components/Chat/Messages/Content/outcome.ts b/client/src/components/Chat/Messages/Content/outcome.ts
index bd855feae6..7b039c0c3f 100644
--- a/client/src/components/Chat/Messages/Content/outcome.ts
+++ b/client/src/components/Chat/Messages/Content/outcome.ts
@@ -1,4 +1,4 @@
-import { Tools, ContentTypes, ToolCallTypes } from 'librechat-data-provider';
+import { Tools, Constants, ContentTypes, ToolCallTypes } from 'librechat-data-provider';
import type {
Agents,
TAttachment,
@@ -6,6 +6,7 @@ import type {
FunctionToolCall,
TMessageContentParts,
} from 'librechat-data-provider';
+import { backgroundTaskOutcome, parseBackgroundTaskOutput } from './Parts/background';
import { parseBackgroundHandle, splitBackgroundAttachments } from './Parts/handle';
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
import { isMemoryFailureOutput } from './Parts/MemoryCall';
@@ -133,9 +134,13 @@ export function getToolMeta(
const { backgroundStatus, fileAttachments } = splitBackgroundAttachments(ownAttachments, tc.id);
const backgroundSettled = backgroundStatus != null || (fileAttachments?.length ?? 0) > 0;
const backgroundFailed = backgroundHandle != null && backgroundStatus === 'error';
+ const polled =
+ name === Constants.CHECK_BACKGROUND_TASK ? parseBackgroundTaskOutput(tc.output) : null;
+ const polledOutcome = backgroundTaskOutcome(polled);
const backgroundCancelled =
tc.backgroundTask?.cancelled === true ||
- (backgroundHandle != null && backgroundStatus === 'cancelled');
+ (backgroundHandle != null && backgroundStatus === 'cancelled') ||
+ polledOutcome === 'cancelled';
return {
name,
iconName,
@@ -145,7 +150,7 @@ export function getToolMeta(
...resolveOutcome(
backgroundCancelled ? 'cancelled' : runStepStatus,
completed,
- failedOutput || backgroundFailed,
+ failedOutput || backgroundFailed || polledOutcome === 'failed',
),
};
}
diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json
index a8cc3a24e3..5e8dbc38aa 100644
--- a/client/src/locales/en/translation.json
+++ b/client/src/locales/en/translation.json
@@ -1,12 +1,22 @@
{
"com_ui_background_tasks": "Background tasks",
"com_ui_background_tasks_cancel_disabled": "Stopping background tools is not enabled on this server",
+ "com_ui_background_tasks_checked": "Checked background tasks",
+ "com_ui_background_tasks_checking": "Checking background tasks",
"com_ui_background_tasks_completed": "Completed",
+ "com_ui_background_tasks_control_not_found": "Control not found",
+ "com_ui_background_tasks_control_queued": "Control queued",
+ "com_ui_background_tasks_empty": "No background tasks yet",
"com_ui_background_tasks_failed_label": "Background tasks, {{0}} results not delivered",
"com_ui_background_tasks_finished": "Finished",
"com_ui_background_tasks_incomplete": "Some background results may not be shown. Check again later.",
"com_ui_background_tasks_label": "Background tasks, {{0}} running",
+ "com_ui_background_tasks_no_output": "No output returned",
+ "com_ui_background_tasks_not_running": "No longer running",
"com_ui_background_tasks_pending_label": "Background tasks, {{0}} results pending",
+ "com_ui_background_tasks_raw_details": "Raw task details",
+ "com_ui_background_tasks_result_available": "Result available on request",
+ "com_ui_background_tasks_result_claimed": "Result claimed",
"com_ui_background_tasks_result_pending": "Result pending",
"com_ui_background_tasks_result_undelivered": "Result not delivered",
"com_ui_background_tasks_running": "Running",
@@ -17,6 +27,30 @@
"com_ui_background_tasks_load_failed": "Could not load all tasks. The list may be incomplete. Try again.",
"com_ui_background_tasks_stopping": "Stopping…",
"com_ui_background_tasks_subagent": "Subagent",
+ "com_ui_background_tasks_artifact_not_inline": "This task produced an artifact that is not shown here.",
+ "com_ui_background_tasks_cancellation_requested": "Cancellation requested. The task may still be running; check again for its final status.",
+ "com_ui_background_tasks_failed_delivery_guidance": "Automatic delivery failed. Poll each affected task to collect its result; it will not arrive as a new turn.",
+ "com_ui_background_tasks_failed_delivery_note": "Automatic delivery failed. Poll this task to collect its result; it will not arrive as a new turn.",
+ "com_ui_background_tasks_files_attached": "Generated files are attached to the original tool call.",
+ "com_ui_background_tasks_files_attaching": "Output and generated files are being attached to the original tool call.",
+ "com_ui_background_tasks_more_in_raw_details": "More information in raw task details.",
+ "com_ui_background_tasks_notice_delivery_scheduled": "Result assigned to another poll or automatic delivery. It may still arrive as a new turn.",
+ "com_ui_background_tasks_notice_discard_unavailable": "Could not discard the pending result. It may still arrive as a new turn; try again shortly.",
+ "com_ui_background_tasks_notice_error": "The background-task check failed. See raw task details.",
+ "com_ui_background_tasks_notice_invalid": "Invalid background-task request. Check the task ID or control arguments.",
+ "com_ui_background_tasks_notice_not_found": "No background task with that ID was found in this conversation.",
+ "com_ui_background_tasks_notice_outcome_unknown": "The task's outcome is unknown. Inspect the target system before repeating an action.",
+ "com_ui_background_tasks_notice_rejected": "The request was rejected. Check raw details before trying again.",
+ "com_ui_background_tasks_notice_result_persisting": "The result is being saved or recovered. Check again shortly; do not rerun the task.",
+ "com_ui_background_tasks_notice_result_unavailable": "The result is temporarily unavailable. Check again later; do not automatically repeat a mutating action.",
+ "com_ui_background_tasks_notice_subagent_only": "This control action is available only for subagent tasks.",
+ "com_ui_background_tasks_notice_unavailable": "Task or control temporarily unavailable. Check again; do not assume the task stopped or its result will not arrive.",
+ "com_ui_background_tasks_pending_delivery_guidance": "Finished results are pending delivery. Poll to collect now or wait for the agent to resume; do not treat them as delivered yet.",
+ "com_ui_background_tasks_pending_delivery_note": "Result pending delivery. It may still arrive as a new turn; poll to collect it sooner.",
+ "com_ui_background_tasks_result_discarded": "Finished result discarded. It will not arrive as a new turn.",
+ "com_ui_background_tasks_running_elsewhere": "Still running outside this turn. Its result may arrive as a new turn.",
+ "com_ui_background_tasks_subagent_pending_guidance": "Finished subagent results are pending delivery. Poll to collect now or wait for the agent to resume.",
+ "com_ui_background_tasks_subagent_wakeup_guidance": "This subagent will automatically resume the agent when it finishes; there is no need to poll it repeatedly.",
"com_ui_repository_instructions": "Repository instructions",
"com_ui_repository_instructions_prefer": "Prefer repository conventions",
"com_ui_repository_instructions_defer": "Prefer agent conventions",
@@ -2894,10 +2928,11 @@
"com_ui_versions": "Versions",
"com_ui_via_server": "in {{0}}",
"com_ui_view_memory": "View Memory",
- "com_ui_wakeup_explainer": "This durable result woke the agent to continue the conversation.",
+ "com_ui_wakeup_explainer": "The agent continued with this result.",
"com_ui_wakeup_subagent_cancelled": "Subagent task cancelled",
"com_ui_wakeup_subagent_completed": "Subagent task completed",
"com_ui_wakeup_subagent_errored": "Subagent task failed",
+ "com_ui_wakeup_task_cancelled": "Background task cancelled",
"com_ui_wakeup_task_errored": "Background task failed",
"com_ui_wakeup_task_finished": "Background task finished",
"com_ui_wakeup_tasks_finished": "{{0}} background tasks finished",
diff --git a/client/src/utils/__tests__/toolLabels.test.ts b/client/src/utils/__tests__/toolLabels.test.ts
index e0d1f9ee44..0b96db8024 100644
--- a/client/src/utils/__tests__/toolLabels.test.ts
+++ b/client/src/utils/__tests__/toolLabels.test.ts
@@ -74,6 +74,18 @@ describe('getToolDisplayLabel', () => {
);
});
+ it('uses the background task label for the native poll tool, not an MCP tool with that name', () => {
+ expect(getToolDisplayLabel(Constants.CHECK_BACKGROUND_TASK, identityLocalize)).toBe(
+ 'com_ui_background_tasks',
+ );
+ expect(
+ getToolDisplayLabel(
+ `${Constants.CHECK_BACKGROUND_TASK}${Constants.mcp_delimiter}remote`,
+ identityLocalize,
+ ),
+ ).toBe('remote');
+ });
+
it.each(['set_memory', 'delete_memory'])('returns a friendly memory label for %s', (toolName) => {
expect(getToolDisplayLabel(toolName, identityLocalize)).toBe(TOOL_FRIENDLY_NAME_KEYS[toolName]);
});
diff --git a/client/src/utils/toolLabels.ts b/client/src/utils/toolLabels.ts
index d0dbe41c2a..190df413bf 100644
--- a/client/src/utils/toolLabels.ts
+++ b/client/src/utils/toolLabels.ts
@@ -14,6 +14,7 @@ export const TOOL_FRIENDLY_NAME_KEYS: Record<string, TranslationKeys> = {
run_tools_with_code: 'com_ui_tool_name_code',
run_tools_with_bash: 'com_ui_tool_name_code',
bash_tool: 'com_ui_tool_name_code',
+ [Constants.CHECK_BACKGROUND_TASK]: 'com_ui_background_tasks',
web_search: 'com_ui_tool_name_web_search',
image_gen_oai: 'com_ui_tool_name_image_gen',
image_edit_oai: 'com_ui_tool_name_image_edit',