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 @@ -21,6 +21,9 @@ import {

const mocks = vi.hoisted(() => ({
run: null as unknown,
runError: false,
runFetching: false,
refetchRun: vi.fn(),
pendingAsk: null as unknown,
reviewer: undefined as TaskReviewerState | undefined,
reviewerError: false,
Expand All @@ -46,8 +49,11 @@ vi.mock('@/app/hooks/use-backend-query', () => ({
return { data: mocks.pendingAsk };
}
return {
data:
query === 'automations/queries:getLiveRunForTask' ? mocks.run : null,
data: mocks.run,
isError: mocks.runError,
isFetching: mocks.runFetching,
error: mocks.runError ? new Error('503') : null,
refetch: mocks.refetchRun,
};
},
}));
Expand Down Expand Up @@ -179,6 +185,9 @@ function capturedReview(
describe('TaskSubjectPanel', () => {
beforeEach(() => {
mocks.run = null;
mocks.runError = false;
mocks.runFetching = false;
mocks.refetchRun.mockReset();
mocks.pendingAsk = null;
mocks.reviewer = {
reviewer: { kind: 'inherit' },
Expand All @@ -199,6 +208,71 @@ describe('TaskSubjectPanel', () => {
vi.mocked(toast).mockClear();
});

it('retains ownership through failure and retry, then restores Start after an empty successful read', async () => {
mocks.run = undefined;
mocks.runError = true;
const view = renderPanel(ownedBy(), true);
expect(
screen.getByRole('region', { name: 'Document verification desk' }),
).toBeVisible();
expect(
screen.getByText(
'Verifies one batch of incoming documents for completeness and consistency.',
),
).toBeVisible();
expect(screen.getByRole('alert')).toHaveTextContent(
"Couldn't load the workflow state.",
);
expect(
screen.queryByRole('button', { name: 'Start' }),
).not.toBeInTheDocument();
await view.user.click(screen.getByRole('button', { name: 'Try again' }));
expect(mocks.refetchRun).toHaveBeenCalledTimes(1);
expect(mocks.start).not.toHaveBeenCalled();
expect(mocks.cancel).not.toHaveBeenCalled();
expect(mocks.updateStatus).not.toHaveBeenCalled();
mocks.runError = false;
mocks.runFetching = true;
view.rerender(panel(ownedBy(), true));
expect(screen.getByRole('alert')).toBeVisible();
expect(screen.getByRole('button', { name: 'Try again' })).toBeDisabled();
expect(screen.getByRole('button', { name: 'Try again' })).toHaveAttribute(
'aria-busy',
'true',
);
mocks.runError = true;
mocks.runFetching = false;
view.rerender(panel(ownedBy(), true));
expect(screen.getByRole('alert')).toBeVisible();
expect(screen.getByRole('button', { name: 'Try again' })).toBeEnabled();
mocks.runError = false;
mocks.run = null;
view.rerender(panel(ownedBy(), true));
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Start' })).toBeEnabled();
});

it('does not derive workflow actions from stale data after a failed read', () => {
mocks.runError = true;
renderPanel(ownedBy(), true);
expect(screen.getByRole('alert')).toBeVisible();
expect(
screen.queryByRole('button', { name: 'Start' }),
).not.toBeInTheDocument();
});

it('keeps initial loading quiet and clears failed-read memory for another task', () => {
mocks.run = undefined;
const view = renderPanel(ownedBy(), true);
expect(screen.queryByRole('region')).not.toBeInTheDocument();
mocks.runError = true;
view.rerender(panel(ownedBy(), true));
expect(screen.getByRole('alert')).toBeVisible();
mocks.runError = false;
view.rerender(panel(ownedBy(), true, 'backlog', undefined, 'task_2'));
expect(screen.queryByRole('region')).not.toBeInTheDocument();
});

it('shows the captured agent review without human verdict actions on an automation-owned task', () => {
mocks.reviewer = capturedReview({ kind: 'agent', agentId: 'reviewer' });
const resolved = resolveTaskSubjectContract(
Expand Down
105 changes: 73 additions & 32 deletions services/platform/app/features/tasks/components/task-subject-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ function TaskSubjectPanelBody({
projectId: task.projectId,
taskId: task._id,
});
// A retry without cached data can return to pending. Keep the explanation
// mounted until a successful read, rather than losing the recovery surface.
const [runReadFailed, setRunReadFailed] = useState(false);
const runReadError = runQuery.isError || runReadFailed;
if (runQuery.isError && !runReadFailed) setRunReadFailed(true);
if (!runQuery.isError && runQuery.data !== undefined && runReadFailed) {
setRunReadFailed(false);
}
const run = runQuery.data ?? null;
// The live run's parked question, if its agent asked one — the panel's
// whole story flips to "answer this" while it is pending.
Expand Down Expand Up @@ -184,7 +192,11 @@ function TaskSubjectPanelBody({
hasFiles,
});
const canReview =
canEdit && state?.kind === 'review' && reviewReady && !agentReview;
canEdit &&
!runReadError &&
state?.kind === 'review' &&
reviewReady &&
!agentReview;
const reviewIdentity = reviewConfirmationIdentity(
task._id,
pendingReview ?? null,
Expand All @@ -198,6 +210,65 @@ function TaskSubjectPanelBody({
setApproveOpen(false);
setChangesOpen(false);
}
const ownershipContext = (
<>
<Row gap={2} align="center">
<Workflow
className="text-muted-foreground size-4 shrink-0"
aria-hidden
/>
<Text
as="h3"
id={headingId}
variant="label"
className="min-w-0 flex-1 truncate"
>
{displayName}
</Text>
{!runReadError && state?.kind === 'running' && (
<Button
variant="ghost"
size="sm"
onClick={() => setDetailsOpen(true)}
>
{t('run.details')}
</Button>
)}
</Row>

{/* The automation's OWN words on what it does — clamped, because a pack
may declare a paragraph and this is orientation, not documentation. */}
{displayDescription !== undefined && (
<Text as="p" variant="caption" className="line-clamp-2 text-pretty">
{displayDescription}
</Text>
)}
</>
);
if (runReadError) {
return (
<section
aria-labelledby={headingId}
className="border-border bg-card flex flex-col gap-2 rounded-lg border p-3"
>
{ownershipContext}
<Text as="p" role="alert" className="text-pretty">
{t('subject.runLoadError')}
</Text>
<Row gap={2} wrap>
<Button
variant="secondary"
size="sm"
aria-busy={runQuery.isFetching}
disabled={runQuery.isFetching}
onClick={() => void runQuery.refetch()}
>
{tCommon('actions.tryAgain')}
</Button>
</Row>
</section>
);
}
// Facts still loading — render nothing rather than a state that flips.
if (state === null || state.kind === 'idle') return null;
// A folder-input contract on a task with NO bound folder has no upload
Expand Down Expand Up @@ -375,37 +446,7 @@ function TaskSubjectPanelBody({
: 'border-primary/40 bg-primary/[0.03]',
)}
>
<Row gap={2} align="center">
<Workflow
className="text-muted-foreground size-4 shrink-0"
aria-hidden
/>
<Text
as="h3"
id={headingId}
variant="label"
className="min-w-0 flex-1 truncate"
>
{displayName}
</Text>
{state.kind === 'running' && (
<Button
variant="ghost"
size="sm"
onClick={() => setDetailsOpen(true)}
>
{t('run.details')}
</Button>
)}
</Row>

{/* The automation's OWN words on what it does — clamped, because a pack
may declare a paragraph and this is orientation, not documentation. */}
{displayDescription !== undefined && (
<Text as="p" variant="caption" className="line-clamp-2 text-pretty">
{displayDescription}
</Text>
)}
{ownershipContext}

<Skeletonize
loading={
Expand Down
1 change: 1 addition & 0 deletions services/platform/messages/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7424,6 +7424,7 @@ tasks:
detailsTitleLive: '{name} — Fortschritt'
openFull: Vollständigen Lauf öffnen
subject:
runLoadError: "Der Workflow-Status konnte nicht geladen werden. Versuch es erneut, um die verfügbaren Aktionen zu sehen."
ready: 'Bereit zum Start — {name} übernimmt ab hier.'
start: Starten
startAgain: Erneut starten
Expand Down
1 change: 1 addition & 0 deletions services/platform/messages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7577,6 +7577,7 @@ tasks:
detailsTitleLive: '{name} — progress'
openFull: Open the full run
subject:
runLoadError: "Couldn't load the workflow state. Try again to see the available actions."
ready: 'Ready to start — {name} takes it from here.'
start: Start
startAgain: Start again
Expand Down
1 change: 1 addition & 0 deletions services/platform/messages/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7528,6 +7528,7 @@ tasks:
detailsTitleLive: '{name} — avancement'
openFull: "Ouvrir l'exécution complète"
subject:
runLoadError: "Impossible de charger l’état du workflow. Réessaie pour voir les actions disponibles."
ready: 'Prête à démarrer — {name} prend la suite.'
start: Démarrer
startAgain: Relancer
Expand Down
6 changes: 6 additions & 0 deletions services/platform/tests/manual/reference/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ staged, and keep regeneration on its original-prompt path:
`app/features/chat/components/chat-surface.test.tsx` covers the component
boundary; persisted cards after reload remain manual in `CHAT-F8`.

Automation-owned tasks retain their workflow name and description after a failed
live-run read, show an accessible error with retry, keep that surface during
retry, and restore workflow actions only after a successful read. Successful
empty reads retain the normal no-live-run state. These cases are owned by
`app/features/tasks/components/task-subject-panel.test.tsx` (#3849).

Task attachment uploads overlap while their drain, read and replace steps are
serialized, and replacements read the latest saved list rather than an
upload-start snapshot.
Expand Down