Skip to content

Commit d4ede00

Browse files
zebbernCopilot
andcommitted
fix: remove auto-fix from preview error handler, always show alert dialog
Preview errors now always display the ChatAlert dialog instead of auto-triggering fix attempts. Removes dead #isAutoFixableError method, callback registration functions, and unused imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2eaf578 commit d4ede00

2 files changed

Lines changed: 5 additions & 98 deletions

File tree

app/components/chat/Chat.client.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import {
4242
} from '~/utils/terminalErrorDetector';
4343
import {
4444
resetPreviewErrorHandler,
45-
registerPreviewAutoFixCallback,
46-
unregisterPreviewAutoFixCallback,
4745
} from '~/utils/previewErrorHandler';
4846
import { createAutoFixHandler, handleFixSuccess, isAutoFixActive } from '~/lib/services/autoFixService';
4947
import { hasExceededMaxRetries, recordFixAttempt, resetAutoFix } from '~/lib/stores/autofix';
@@ -941,15 +939,13 @@ export const ChatImpl = memo(
941939
});
942940
};
943941

944-
// Register the callback for both terminal and preview errors
942+
// Register the callback for terminal errors only (preview errors show alert to user)
945943
const handler = createAutoFixHandler(autoFixSendMessage);
946944
registerAutoFixCallback(handler);
947-
registerPreviewAutoFixCallback(handler);
948945

949946
// Cleanup on unmount
950947
return () => {
951948
unregisterAutoFixCallback();
952-
unregisterPreviewAutoFixCallback();
953949

954950
// Reset auto-fix state so it doesn't stay stuck if component unmounts mid-fix
955951
if (isAutoFixActive()) {

app/utils/previewErrorHandler.ts

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,9 @@ import {
2222
classifyErrorSeverity,
2323
SEVERITY_CONFIG,
2424
} from '~/utils/errors/errorConfig';
25-
import {
26-
autoFixStore,
27-
startAutoFix,
28-
shouldContinueFix,
29-
hasExceededMaxRetries,
30-
type ErrorSource,
31-
} from '~/lib/stores/autofix';
32-
import type { AutoFixCallback } from './terminalErrorDetector';
3325

3426
const logger = createScopedLogger('PreviewErrorHandler');
3527

36-
// Global auto-fix callback - shared with terminal error detector
37-
let globalPreviewAutoFixCallback: AutoFixCallback | null = null;
38-
39-
/**
40-
* Register a callback to handle auto-fix requests from preview errors
41-
*/
42-
export function registerPreviewAutoFixCallback(callback: AutoFixCallback): void {
43-
globalPreviewAutoFixCallback = callback;
44-
logger.debug('Preview auto-fix callback registered');
45-
}
46-
47-
/**
48-
* Unregister the preview auto-fix callback
49-
*/
50-
export function unregisterPreviewAutoFixCallback(): void {
51-
globalPreviewAutoFixCallback = null;
52-
logger.debug('Preview auto-fix callback unregistered');
53-
}
54-
5528
/**
5629
* Simple hash function for error deduplication
5730
*/
@@ -195,43 +168,11 @@ class PreviewErrorHandler {
195168
const content = contentParts.join('\n');
196169

197170
/*
198-
* Check if we should trigger auto-fix instead of showing alert
199-
* Auto-fixable errors are typically code issues (SyntaxError, TypeError, ReferenceError, etc.)
171+
* Preview errors are NOT auto-fixed — always show the alert and let the user
172+
* decide whether to ask Devonz for help. Auto-fix from previews was too aggressive,
173+
* triggering on transient build errors (e.g., missing files while AI is still writing)
174+
* and wasting tokens on unnecessary LLM calls.
200175
*/
201-
const isAutoFixable = this.#isAutoFixableError(errorMessage);
202-
const canAutoFix = isAutoFixable && shouldContinueFix() && globalPreviewAutoFixCallback;
203-
204-
if (canAutoFix) {
205-
// Trigger auto-fix instead of showing alert
206-
const started = startAutoFix({
207-
source: 'preview' as ErrorSource,
208-
type: severity,
209-
message: description,
210-
content,
211-
});
212-
213-
if (started && globalPreviewAutoFixCallback) {
214-
logger.info(`Auto-fix triggered for preview error: ${title}`);
215-
216-
// Add delay before triggering fix
217-
const autoFixState = autoFixStore.get();
218-
setTimeout(() => {
219-
globalPreviewAutoFixCallback?.({
220-
source: 'preview' as ErrorSource,
221-
type: severity,
222-
message: description,
223-
content,
224-
});
225-
}, autoFixState.settings.delayBetweenAttempts);
226-
227-
return; // Don't show alert, auto-fix is handling it
228-
}
229-
}
230-
231-
// If auto-fix didn't trigger, show max retries warning if applicable
232-
if (isAutoFixable && hasExceededMaxRetries()) {
233-
logger.warn('Max auto-fix retries exceeded for preview error, showing alert to user');
234-
}
235176

236177
/* Lazy import to avoid circular dependency */
237178
const { workbenchStore } = await import('~/lib/stores/workbench');
@@ -248,36 +189,6 @@ class PreviewErrorHandler {
248189
}
249190

250191
/**
251-
* Check if an error is auto-fixable (code issues that the LLM can fix)
252-
*/
253-
#isAutoFixableError(errorMessage: string): boolean {
254-
const autoFixablePatterns = [
255-
/SyntaxError/i,
256-
/TypeError/i,
257-
/ReferenceError/i,
258-
/RangeError/i,
259-
/Cannot find module/i,
260-
/Module not found/i,
261-
/does not provide an export/i,
262-
/Failed to resolve import/i,
263-
/Unexpected token/i,
264-
/is not defined/i,
265-
/is not a function/i,
266-
/Cannot read propert/i,
267-
/Element type is invalid/i,
268-
/Objects are not valid as a React child/i,
269-
/Maximum update depth exceeded/i,
270-
/Invalid hook call/i,
271-
/must be used within/i,
272-
/Invariant Violation/i,
273-
/ChunkLoadError/i,
274-
/Failed to fetch dynamically imported module/i,
275-
/Cannot use import statement outside a module/i,
276-
];
277-
278-
return autoFixablePatterns.some((pattern) => pattern.test(errorMessage));
279-
}
280-
281192
/**
282193
* Reset the handler state
283194
* Call this when user clicks "Ask Devonz" so the same error can be caught again

0 commit comments

Comments
 (0)