diff --git a/services/platform/app/features/tasks/components/task-subject-panel.test.tsx b/services/platform/app/features/tasks/components/task-subject-panel.test.tsx index 169032a522..1f651de0bf 100644 --- a/services/platform/app/features/tasks/components/task-subject-panel.test.tsx +++ b/services/platform/app/features/tasks/components/task-subject-panel.test.tsx @@ -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, @@ -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, }; }, })); @@ -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' }, @@ -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( diff --git a/services/platform/app/features/tasks/components/task-subject-panel.tsx b/services/platform/app/features/tasks/components/task-subject-panel.tsx index 725bf3dc4b..d9e81ef3a2 100644 --- a/services/platform/app/features/tasks/components/task-subject-panel.tsx +++ b/services/platform/app/features/tasks/components/task-subject-panel.tsx @@ -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. @@ -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, @@ -198,6 +210,65 @@ function TaskSubjectPanelBody({ setApproveOpen(false); setChangesOpen(false); } + const ownershipContext = ( + <> + + + + {displayName} + + {!runReadError && state?.kind === 'running' && ( + + )} + + + {/* 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 && ( + + {displayDescription} + + )} + + ); + if (runReadError) { + return ( +
+ {ownershipContext} + + {t('subject.runLoadError')} + + + + +
+ ); + } // 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 @@ -375,37 +446,7 @@ function TaskSubjectPanelBody({ : 'border-primary/40 bg-primary/[0.03]', )} > - - - - {displayName} - - {state.kind === 'running' && ( - - )} - - - {/* 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 && ( - - {displayDescription} - - )} + {ownershipContext}