Skip to content

Self-improving AI Employees for everyone

fix(home): offer Start again to an employee whose run failed

trohitgf6a67275d33d
diff --git a/client/src/features/home/__tests__/employeeView.test.tsx b/client/src/features/home/__tests__/employeeView.test.tsx
index 2e8100e8..19dd7291 100644
--- a/client/src/features/home/__tests__/employeeView.test.tsx
+++ b/client/src/features/home/__tests__/employeeView.test.tsx
@@ -170,10 +170,14 @@ describe('EmployeeView', () => {
});
});
- it('keeps the stopped notice without offering Open in Dev mode when no normal action is available', () => {
- renderPage(summary({ status: 'attention', talk: TALK_ON }, { state: 'failed', can_resume: false }));
+ it('offers Start again above the message box after a failure', () => {
+ actions.startEmployee.mockReturnValue(new Promise(() => {}));
+ renderPage(summary({ status: 'attention', talk: TALK_ON }, { state: 'failed', can_resume: false, revision: 7 }));
expect(screen.queryByRole('button', { name: 'Open in Dev mode' })).not.toBeInTheDocument();
expect(screen.getByText('Maya isn’t running, so they can’t read messages right now.')).toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Start again' }));
+ expect(actions.startEmployee).toHaveBeenCalledWith('w1', 7);
expect(enterDev).not.toHaveBeenCalled();
});
diff --git a/client/src/features/home/__tests__/presentation.test.ts b/client/src/features/home/__tests__/presentation.test.ts
index f01be1a7..371f35b7 100644
--- a/client/src/features/home/__tests__/presentation.test.ts
+++ b/client/src/features/home/__tests__/presentation.test.ts
@@ -33,7 +33,8 @@ describe('presentEmployee', () => {
['working', { state: 'running' }, 'Working', 'working', 'pause'],
['paused', { state: 'paused' }, 'Paused', 'paused', 'resume'],
['attention', { state: 'paused' }, 'Needs attention', 'attention', 'resume'],
- ['attention', { state: 'failed', can_resume: false }, 'Needs attention', 'attention', 'open_workflow'],
+ ['attention', { state: 'failed', can_resume: false }, 'Needs attention', 'attention', 'start'],
+ ['attention', { state: 'pausing', can_resume: false }, 'Needs attention', 'attention', 'open_workflow'],
['ready', { state: 'never_started' }, 'Ready', 'ready', 'start'],
])('%s (%o) shows %s and offers %s', (status, control, label, tone, action) => {
const view = presentEmployee(employee({ status }, control));
@@ -42,6 +43,18 @@ describe('presentEmployee', () => {
expect(view.pulse).toBe(status === 'working');
});
+ // start_employee resets a failed employee before starting it again.
+ it('offers Start again after a failure', () => {
+ const view = presentEmployee(employee({ status: 'attention' }, { state: 'failed', can_resume: false }));
+ expect(view.primary).toEqual({ kind: 'start', again: true });
+ expect(primaryActionLabel(view.primary)).toBe('Start again');
+ });
+
+ it('asks for what a failed employee is missing before starting it again', () => {
+ const view = presentEmployee(employee({ status: 'attention', missing_apps: [whatsapp] }, { state: 'failed', can_resume: false }));
+ expect(view.primary.kind).toBe('connect_app');
+ });
+
it('asks to connect the first missing app before anything else', () => {
const view = presentEmployee(employee({ status: 'ready', missing_apps: [whatsapp], needs_ai: true }));
expect(view.primary).toEqual({ kind: 'connect_app', app: expect.objectContaining({ name: 'WhatsApp' }) });
diff --git a/client/src/features/home/data/presentation.ts b/client/src/features/home/data/presentation.ts
index 1ffecacc..3b33ef41 100644
--- a/client/src/features/home/data/presentation.ts
+++ b/client/src/features/home/data/presentation.ts
@@ -11,7 +11,7 @@
* | working | Working | Pause |
* | ready | Ready | Connect {App} / Connect AI / Start |
* | paused | Paused | Resume |
- * | attention | Needs attention | Resume when possible, else Open in Dev mode |
+ * | attention | Needs attention | Resume when possible; after a failure Start again (the server resets first); else Open in Dev mode |
* | pending_approvals > 0 | Needs you (overrides pill) | (the drafts are the action) |
* | browser_request | Needs you (overrides pill) | (Help in browser opens the Workspace) |
*
@@ -34,7 +34,8 @@ export type StatusTone = 'working' | 'ready' | 'paused' | 'attention' | 'waiting
export type PrimaryAction =
| { kind: 'pause' }
| { kind: 'resume' }
- | { kind: 'start' }
+ /** `again`: the last run failed; `start_employee` resets it first. */
+ | { kind: 'start'; again?: boolean }
| { kind: 'connect_app'; app: AppRef }
| { kind: 'connect_ai' }
| { kind: 'open_workflow' };
@@ -62,6 +63,13 @@ const BUSY: Record<WorkflowControlPendingMutation['action'], string> = {
reset: 'Resetting…',
};
+/** What starting needs first: an app to connect, or an AI model. */
+function startBlocker(employee: EmployeeSummary): PrimaryAction | null {
+ if (employee.missing_apps.length > 0) return { kind: 'connect_app', app: employee.missing_apps[0] };
+ if (employee.needs_ai) return { kind: 'connect_ai' };
+ return null;
+}
+
function primaryAction(employee: EmployeeSummary): PrimaryAction {
const { control } = employee;
switch (employee.status) {
@@ -70,12 +78,14 @@ function primaryAction(employee: EmployeeSummary): PrimaryAction {
case 'paused':
return control.can_resume ? { kind: 'resume' } : { kind: 'open_workflow' };
case 'attention':
- return control.can_resume ? { kind: 'resume' } : { kind: 'open_workflow' };
+ if (control.can_resume) return { kind: 'resume' };
+ // A failed run has neither can_start nor can_resume, but
+ // start_employee resets a failed employee and starts it again.
+ if (control.state === 'failed') return startBlocker(employee) ?? { kind: 'start', again: true };
+ return { kind: 'open_workflow' };
case 'ready':
default:
- if (employee.missing_apps.length > 0) return { kind: 'connect_app', app: employee.missing_apps[0] };
- if (employee.needs_ai) return { kind: 'connect_ai' };
- return control.can_start ? { kind: 'start' } : { kind: 'open_workflow' };
+ return startBlocker(employee) ?? (control.can_start ? { kind: 'start' } : { kind: 'open_workflow' });
}
}
@@ -109,7 +119,7 @@ export function primaryActionLabel(action: PrimaryAction): string {
case 'resume':
return 'Resume';
case 'start':
- return 'Start';
+ return action.again ? 'Start again' : 'Start';
case 'connect_app':
return `Connect ${action.app.name}`;
case 'connect_ai':