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
16 changes: 11 additions & 5 deletions app/components/BackupStatusIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ export function BackupStatusIndicator() {
if (toastState.current.type === 'idle') {
const now = Date.now();
if (toastState.current.lastCompleted + TOAST_COOLDOWN < now) {
const toastId = crypto.randomUUID();
toast.loading('Saving...', {
id: toastId,
});
toastState.current = { type: 'loading', toastId };
// Only show "Saving..." toast if "chat-save-failure" toast is not currently showing
const activeToasts = toast.getHistory();
const chatSaveFailureToastActive = activeToasts.some((t) => t.id === 'chat-save-failure');

if (!chatSaveFailureToastActive) {
const toastId = crypto.randomUUID();
toast.loading('Saving...', {
id: toastId,
});
toastState.current = { type: 'loading', toastId };
}
}
}
}
Expand Down
22 changes: 19 additions & 3 deletions app/lib/stores/startup/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { subchatIndexStore, waitForSubchatIndexChanged } from '~/lib/stores/subc
import { api } from '@convex/_generated/api';
import { workbenchStore } from '~/lib/stores/workbench.client';
import { chatSyncState, type BackupSyncState, type InitialBackupSyncState } from './chatSyncState';
import { toast } from 'sonner';

const logger = createScopedLogger('history');

Expand Down Expand Up @@ -249,18 +250,33 @@ async function chatSyncWorker(args: {
if (error !== null || (response !== undefined && !response.ok)) {
const errorText = response !== undefined ? await response.text() : (error?.message ?? 'Unknown error');
logger.error('Complete message info not initialized');
const newFailureCount = currentState.numFailures + 1;
chatSyncState.set({
...currentState,
numFailures: currentState.numFailures + 1,
numFailures: newFailureCount,
});
const sleepTime = backoffTime(currentState.numFailures);

// Show toast notification after 3 consecutive failures
if (newFailureCount >= 3) {
toast.error('Your chat is having trouble saving and progress may be lost. Download your code to save it.', {
id: 'chat-save-failure',
duration: Number.POSITIVE_INFINITY,
});
}

const sleepTime = backoffTime(newFailureCount);
logger.error(
`Failed to save chat (num failures: ${currentState.numFailures}), sleeping for ${sleepTime.toFixed(2)}ms`,
`Failed to save chat (num failures: ${newFailureCount}), sleeping for ${sleepTime.toFixed(2)}ms`,
errorText,
);
await new Promise((resolve) => setTimeout(resolve, sleepTime));
continue;
}
// Dismiss the save failure toast on successful save
if (currentState.numFailures >= 3) {
toast.dismiss('chat-save-failure');
}

const updates: Partial<BackupSyncState> = {
lastSync: now,
numFailures: 0,
Expand Down