Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ import { AgentActivityLine, AgentExecutionLog } from './agent-execution-log';
// Drives the mocked `useBackendQuery` return: the run's sandbox op, or `null`
// for a run that never ran an agent node.
const { state } = vi.hoisted(() => ({
state: { data: undefined as unknown },
state: {
data: undefined as unknown,
isError: false,
isFetching: false,
errorUpdateCount: 0,
refetch: vi.fn(),
},
}));

vi.mock('@/app/hooks/use-backend-query', () => ({
useBackendQuery: () => ({ data: state.data }),
useBackendQuery: () => ({
data: state.data,
isError: state.isError,
isFetching: state.isFetching,
errorUpdateCount: state.errorUpdateCount,
refetch: state.refetch,
}),
}));

const runId = 'run-1' as string;
Expand Down Expand Up @@ -158,4 +170,61 @@ describe('AgentExecutionLog', () => {
);
expect(container).toBeEmptyDOMElement();
});

it('keeps the transcript section visible and retries when the op read fails', async () => {
state.data = undefined;
state.isError = true;
state.errorUpdateCount = 1;
const { user } = render(
<AgentExecutionLog organizationId="org-1" runId={runId} />,
);

expect(screen.getByRole('alert')).toHaveTextContent(
'Could not load the agent log.',
);
const retry = screen.getByRole('button', { name: 'Try again' });
await user.click(retry);
expect(state.refetch).toHaveBeenCalledOnce();
expect(retry).toHaveFocus();
});

it('keeps the section and focused retry mounted while a retry resets the query', async () => {
state.data = undefined;
state.isError = true;
state.errorUpdateCount = 1;
state.refetch.mockImplementation(() => {
state.isError = false;
state.isFetching = true;
});
const { user, rerender } = render(
<AgentExecutionLog organizationId="org-1" runId={runId} />,
);

const retry = screen.getByRole('button', { name: 'Try again' });
await user.click(retry);
rerender(<AgentExecutionLog organizationId="org-1" runId={runId} />);

expect(
screen.getByRole('heading', { name: 'Agent log' }),
).toBeInTheDocument();
expect(screen.getByRole('alert')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Try again' })).toHaveFocus();
expect(retry).toHaveAttribute('aria-disabled', 'true');
expect(retry).toHaveAttribute('aria-busy', 'true');
expect(retry).not.toBeDisabled();
});

it('keeps cached transcript content visible when a refresh fails', () => {
state.data = op([{ type: 'text', text: 'cached thought' }]);
state.isError = true;
state.errorUpdateCount = 1;
const { container } = render(
<AgentExecutionLog organizationId="org-1" runId={runId} />,
);

expect(container).toHaveTextContent('cached thought');
expect(screen.getByRole('alert')).toHaveTextContent(
'Could not load the agent log.',
);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { Alert } from '@tale/ui/alert';
import { Button } from '@tale/ui/button';
import { cn } from '@tale/ui/cn';
import { CollapsibleDetails } from '@tale/ui/collapsible-details';
Expand All @@ -11,12 +12,14 @@ import {
CheckCircle2,
Loader2,
MessageSquare,
RotateCcw,
Wrench,
} from 'lucide-react';
import { useEffect, useRef, useState } from 'react';

import { useAutoScroll } from '@/app/hooks/use-auto-scroll';
import { useBackendQuery } from '@/app/hooks/use-backend-query';
import { readStateOf } from '@/app/lib/backend/read-state';
import {
mergeTimelineEntries,
strippedText,
Expand Down Expand Up @@ -407,24 +410,68 @@ export function ExecutionLogView({
export function AgentExecutionLog({
organizationId,
runId,
nodeId,
waitingForRoom = false,
className,
}: {
organizationId: string;
runId: string;
nodeId?: string;
/** The run is parked on the turn's start, waiting for sandbox room. */
waitingForRoom?: boolean;
className?: string;
}) {
const { t } = useT('automations');
const opQuery = useBackendQuery(
'sandbox/session_queries_public:getAgentNodeSandboxOp',
{ organizationId, runId },
{ organizationId, runId, ...(nodeId !== undefined ? { nodeId } : {}) },
);
const read = readStateOf(opQuery);
const failure = (read.unavailable || read.stale) && (
<Alert
variant="destructive"
title={t('runs.agentLog.readFailed')}
description={t('runs.agentLog.readFailedDescription')}
>
<Button
variant="secondary"
size="sm"
className="mt-3 w-fit gap-1.5"
aria-disabled={read.retrying}
aria-busy={read.retrying}
onClick={() => void opQuery.refetch()}
>
<RotateCcw className="size-3.5" aria-hidden />
{t('runs.agentLog.retry')}
</Button>
</Alert>
);
if (read.unavailable) {
return (
<Stack as="section" gap={2} className={cn('min-h-0 flex-1', className)}>
<Text as="h3" variant="label">
{t('runs.agentLog.title')}
</Text>
{failure}
</Stack>
);
}
if (!read.stale) {
return (
<ExecutionLogView
op={opQuery.data ?? null}
waitingForRoom={waitingForRoom}
className={className}
/>
);
}
return (
<ExecutionLogView
op={opQuery.data ?? null}
waitingForRoom={waitingForRoom}
className={className}
/>
<Stack gap={2} className={cn('min-h-0 flex-1', className)}>
<ExecutionLogView
op={opQuery.data ?? null}
waitingForRoom={waitingForRoom}
/>
{failure}
</Stack>
);
}
3 changes: 3 additions & 0 deletions services/platform/messages/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ automations:
title: Agenten-Log
starting: Der Agent startet in der Sandbox…
empty: Der Agent hat für diesen Lauf kein Log erzeugt.
readFailed: Das Agenten-Log konnte nicht geladen werden.
readFailedDescription: Das Transkript ist vorübergehend nicht verfügbar. Versuche es erneut, um es zu laden.
retry: Erneut versuchen
servedBy: 'Diese Runde lief auf {model}.'
visionModel: 'Bilder in diesem Lauf hat {model} gelesen.'
approval:
Expand Down
3 changes: 3 additions & 0 deletions services/platform/messages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ automations:
title: Agent log
starting: The agent is starting up in the sandbox…
empty: The agent produced no log for this run.
readFailed: Could not load the agent log.
readFailedDescription: The transcript is temporarily unavailable. Try again to reload it.
retry: Try again
servedBy: 'This turn ran on {model}.'
visionModel: 'Images in this run were read by {model}.'
approval:
Expand Down
3 changes: 3 additions & 0 deletions services/platform/messages/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,9 @@ automations:
title: Journal de l'agent
starting: "L'agent démarre dans le bac à sable…"
empty: "L'agent n'a produit aucun journal pour cette exécution."
readFailed: Impossible de charger le journal de l'agent.
readFailedDescription: Le journal est temporairement indisponible. Réessaie pour le recharger.
retry: Réessayer
servedBy: 'Ce tour a tourné sur {model}.'
visionModel: 'Les images de cette exécution ont été lues par {model}.'
approval:
Expand Down