Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(memory): keep Explorer's retry on the out-of-credits prompt

M3gA-Mind28a231b6ecf5
diff --git a/app/src/components/memory/MemoryErrorAlert.test.tsx b/app/src/components/memory/MemoryErrorAlert.test.tsx
index 02f4816e0a..899bac4082 100644
--- a/app/src/components/memory/MemoryErrorAlert.test.tsx
+++ b/app/src/components/memory/MemoryErrorAlert.test.tsx
@@ -1,7 +1,7 @@
import { act, fireEvent, screen } from '@testing-library/react';
import { useState } from 'react';
import { Route, Routes } from 'react-router-dom';
-import { describe, expect, it } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
import { I18nProvider, useT } from '../../lib/i18n/I18nContext';
import { memoryErrorMessage } from '../../services/api/memoryApi';
@@ -10,21 +10,14 @@ import { renderWithProviders } from '../../test/test-utils';
import MemoryErrorAlert from './MemoryErrorAlert';
/** Renders the alert for `err` the way the memory views do: via memoryErrorMessage. */
-function Harness({ err, retry }: { err: unknown; retry?: boolean }) {
+function Harness({ err, retry }: { err: unknown; retry?: () => void }) {
const { t } = useT();
- const message = memoryErrorMessage(err, t);
return (
- <MemoryErrorAlert message={message} data-testid="alert">
- {retry ? (
- <>
- <span>{message}</span> <button type="button">Retry</button>
- </>
- ) : undefined}
- </MemoryErrorAlert>
+ <MemoryErrorAlert message={memoryErrorMessage(err, t)} data-testid="alert" onRetry={retry} />
);
}
-function renderAt(err: unknown, retry = false) {
+function renderAt(err: unknown, retry?: () => void) {
renderWithProviders(
<Routes>
<Route path="/" element={<Harness err={err} retry={retry} />} />
@@ -72,15 +65,24 @@ describe('MemoryErrorAlert', () => {
expect(screen.queryByTestId('memory-top-up')).not.toBeInTheDocument();
});
- it('renders the caller content (e.g. a retry) for other errors only', () => {
- renderAt(coded('ENGINE'), true);
- expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument();
+ it('offers Retry beside the error for other errors', () => {
+ const retry = vi.fn();
+ renderAt(coded('ENGINE'), retry);
+ fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
+ expect(retry).toHaveBeenCalledTimes(1);
});
- it('drops the retry for out of credits: a retry cannot succeed until a top-up', () => {
- renderAt(coded('INSUFFICIENT_CREDITS'), true);
- expect(screen.queryByRole('button', { name: 'Retry' })).not.toBeInTheDocument();
+ it('keeps Retry beside Top up when out of credits, for after a top-up', () => {
+ const retry = vi.fn();
+ renderAt(coded('INSUFFICIENT_CREDITS'), retry);
expect(screen.getByTestId('memory-top-up')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Try again' }));
+ expect(retry).toHaveBeenCalledTimes(1);
+ });
+
+ it('shows no Retry when the view offers none', () => {
+ renderAt(coded('INSUFFICIENT_CREDITS'));
+ expect(screen.queryByRole('button', { name: 'Try again' })).not.toBeInTheDocument();
});
// Accepted edge of matching on the message: views keep the text they made
diff --git a/app/src/components/memory/MemoryErrorAlert.tsx b/app/src/components/memory/MemoryErrorAlert.tsx
index 1a952f3839..fef0ec9b1a 100644
--- a/app/src/components/memory/MemoryErrorAlert.tsx
+++ b/app/src/components/memory/MemoryErrorAlert.tsx
@@ -4,7 +4,6 @@
* that nothing stored was lost and links to billing. Every other failure keeps
* the destructive alert.
*/
-import type { ReactNode } from 'react';
import { useNavigate } from 'react-router-dom';
import { useT } from '../../lib/i18n/I18nContext';
@@ -17,6 +16,8 @@ const BILLING_ROUTE = '/settings/account';
interface MemoryCreditsPromptProps {
/** The out-of-credits explanation. */
message: string;
+ /** Retries the failed action (e.g. after a top-up), shown beside Top up. */
+ onRetry?: () => void;
className?: string;
'data-testid'?: string;
}
@@ -24,6 +25,7 @@ interface MemoryCreditsPromptProps {
/** "Out of credits: top up", with a button to billing. */
export function MemoryCreditsPrompt({
message,
+ onRetry,
className,
'data-testid': testId,
}: MemoryCreditsPromptProps) {
@@ -42,6 +44,7 @@ export function MemoryCreditsPrompt({
onClick={() => navigate(BILLING_ROUTE)}>
{t('memory.outOfCredits.action')}
</Button>
+ {onRetry && <RetryButton onRetry={onRetry} />}
</AlertDescription>
</Alert>
);
@@ -52,8 +55,17 @@ interface MemoryErrorAlertProps {
message: string;
className?: string;
'data-testid'?: string;
- /** Replaces the message inside the error alert (e.g. message + retry). */
- children?: ReactNode;
+ /** Retries the failed action; shown in both the prompt and the error alert. */
+ onRetry?: () => void;
+}
+
+function RetryButton({ onRetry }: { onRetry: () => void }) {
+ const { t } = useT();
+ return (
+ <Button type="button" variant="tertiary" size="xs" onClick={onRetry}>
+ {t('common.retry')}
+ </Button>
+ );
}
/** The credits prompt for an exhausted balance, else the error alert. */
@@ -61,15 +73,30 @@ export default function MemoryErrorAlert({
message,
className,
'data-testid': testId,
- children,
+ onRetry,
}: MemoryErrorAlertProps) {
const { t } = useT();
if (isOutOfCreditsMessage(message, t)) {
- return <MemoryCreditsPrompt message={message} className={className} data-testid={testId} />;
+ return (
+ <MemoryCreditsPrompt
+ message={message}
+ onRetry={onRetry}
+ className={className}
+ data-testid={testId}
+ />
+ );
}
return (
<Alert variant="destructive" className={className} data-testid={testId}>
- <AlertDescription>{children ?? message}</AlertDescription>
+ <AlertDescription>
+ {message}
+ {onRetry && (
+ <>
+ {' '}
+ <RetryButton onRetry={onRetry} />
+ </>
+ )}
+ </AlertDescription>
</Alert>
);
}
diff --git a/app/src/components/memory/MemoryExplorerTab.tsx b/app/src/components/memory/MemoryExplorerTab.tsx
index 4b7dfcf757..03830da33f 100644
--- a/app/src/components/memory/MemoryExplorerTab.tsx
+++ b/app/src/components/memory/MemoryExplorerTab.tsx
@@ -160,19 +160,14 @@ export default function MemoryExplorerTab() {
</nav>
{error !== null && (
- <MemoryErrorAlert message={error} data-testid="memory-explorer-error">
- <span>{error}</span>{' '}
- <Button
- type="button"
- variant="tertiary"
- size="xs"
- onClick={() => {
- setError(null);
- setReloadKey(k => k + 1);
- }}>
- {t('common.retry')}
- </Button>
- </MemoryErrorAlert>
+ <MemoryErrorAlert
+ message={error}
+ data-testid="memory-explorer-error"
+ onRetry={() => {
+ setError(null);
+ setReloadKey(k => k + 1);
+ }}
+ />
)}
<Card