Skip to content

Commit 3065258

Browse files
committed
Remove internal retry logic from process_file and implement a caller-driven retry strategy for intelligent updates
- you should never retry, instead show model selection (the behavior we currently have after all retries fail) - you should never retry, instead show model selection (the behavior we currently have after all retries fail) - "Applying changes to daemon.ts: Request failed with status code 429." -> "Request failed with status code 429."
1 parent a68cec5 commit 3065258

9 files changed

Lines changed: 82 additions & 168 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/handlers/active-editor-intelligent-update-handler.ts‎

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ import {
88
import { sanitize_file_name, create_safe_path } from '@/utils/path-sanitizer'
99
import { Logger } from '@shared/utils/logger'
1010
import { OriginalFileState } from '@/commands/apply-chat-response-command/types/original-file-state'
11-
import { ToolConfig } from '@/services/model-providers-manager'
11+
import {
12+
ToolConfig,
13+
ModelProvidersManager
14+
} from '@/services/model-providers-manager'
1215
import { PanelProvider } from '@/views/panel/backend/panel-provider'
1316
import { dictionary } from '@shared/constants/dictionary'
14-
import { process_file } from '@/utils/intelligent-update-utils'
17+
import {
18+
process_file,
19+
get_intelligent_update_config
20+
} from '@/utils/intelligent-update-utils'
1521

1622
export const handle_active_editor_intelligent_update = async (params: {
1723
endpoint_url: string
@@ -144,26 +150,6 @@ export const handle_active_editor_intelligent_update = async (params: {
144150
progress
145151
})
146152
}
147-
},
148-
on_retry_attempt: () => {
149-
if (params.panel_provider) {
150-
params.panel_provider.send_message({
151-
command: 'SHOW_PROGRESS',
152-
title: 'Thinking...',
153-
show_elapsed_time: true,
154-
cancellable: true
155-
})
156-
}
157-
},
158-
on_retry: () => {
159-
if (params.panel_provider) {
160-
params.panel_provider.send_message({
161-
command: 'SHOW_PROGRESS',
162-
title: 'Retrying...',
163-
show_elapsed_time: true,
164-
cancellable: true
165-
})
166-
}
167153
}
168154
})
169155

@@ -198,10 +184,30 @@ export const handle_active_editor_intelligent_update = async (params: {
198184
data: error
199185
})
200186

201-
if (!axios.isCancel(error) && error.message != 'Operation cancelled') {
187+
if (
188+
!axios.isCancel(error) &&
189+
error.message != 'Operation cancelled' &&
190+
error.message != 'User cancelled the operation'
191+
) {
202192
vscode.window.showErrorMessage(
203193
dictionary.error_message.ERROR_APPLYING_CHANGES(error.message)
204194
)
195+
196+
const api_providers_manager = new ModelProvidersManager(params.context)
197+
const config_result = await get_intelligent_update_config(
198+
api_providers_manager,
199+
true,
200+
params.context
201+
)
202+
203+
if (config_result) {
204+
return await handle_active_editor_intelligent_update({
205+
...params,
206+
endpoint_url: config_result.provider.base_url,
207+
api_key: config_result.provider.api_key,
208+
config: config_result.config
209+
})
210+
}
205211
}
206212
return null
207213
} finally {

‎apps/editor/src/utils/intelligent-update-utils.ts‎

Lines changed: 42 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ export const process_file = async (params: {
223223
cancel_token?: CancelToken
224224
on_chunk?: (tokens_per_second: number, total_tokens: number) => void
225225
on_thinking_chunk?: (text: string) => void
226-
on_retry?: (attempt: number, error: any) => void
227-
on_retry_attempt?: () => void
228226
}): Promise<string> => {
229227
Logger.info({
230228
function_name: 'process_file',
@@ -253,86 +251,55 @@ export const process_file = async (params: {
253251
reasoning_effort: params.reasoning_effort
254252
})
255253

256-
const MAX_ATTEMPTS = 3
257-
let attempt = 0
258-
while (attempt < MAX_ATTEMPTS) {
259-
attempt++
260-
try {
261-
const result = await make_api_request({
262-
endpoint_url: params.endpoint_url,
263-
api_key: params.api_key,
264-
body,
265-
cancellation_token: params.cancel_token,
266-
on_chunk: params.on_chunk,
267-
on_thinking_chunk: params.on_thinking_chunk,
268-
rethrow_error: true
269-
})
270-
271-
const refactored_content = result?.response
272-
if (!refactored_content) {
273-
Logger.error({
274-
function_name: 'process_file',
275-
message: 'API request returned empty response',
276-
data: { file_path: params.file_path, attempt }
277-
})
278-
throw new Error('API request returned empty response')
279-
}
254+
try {
255+
const result = await make_api_request({
256+
endpoint_url: params.endpoint_url,
257+
api_key: params.api_key,
258+
body,
259+
cancellation_token: params.cancel_token,
260+
on_chunk: params.on_chunk,
261+
on_thinking_chunk: params.on_thinking_chunk,
262+
rethrow_error: true
263+
})
280264

281-
const cleaned_content = cleanup_api_response({
282-
content: refactored_content
283-
})
284-
Logger.info({
265+
const refactored_content = result?.response
266+
if (!refactored_content) {
267+
Logger.error({
285268
function_name: 'process_file',
286-
message: 'API response received and cleaned',
287-
data: {
288-
file_path: params.file_path,
289-
response_length: cleaned_content?.length
290-
}
269+
message: 'API request returned empty response',
270+
data: { file_path: params.file_path }
291271
})
292-
return cleaned_content
293-
} catch (error: any) {
294-
if (axios.isCancel(error)) {
295-
Logger.info({
296-
function_name: 'process_file',
297-
message: 'Request cancelled',
298-
data: params.file_path
299-
})
300-
throw error
301-
}
272+
throw new Error('API request returned empty response')
273+
}
302274

303-
const is_retryable_error =
304-
(axios.isAxiosError(error) &&
305-
(error.response?.status == 429 ||
306-
(error.response?.status && error.response.status >= 500))) ||
307-
error.name == 'StreamAbortError'
308-
309-
if (!is_retryable_error) {
310-
Logger.error({
311-
function_name: 'process_file',
312-
message: `Refactoring error (attempt ${attempt}) - not retrying`,
313-
data: { error, file_path: params.file_path }
314-
})
315-
throw error
275+
const cleaned_content = cleanup_api_response({
276+
content: refactored_content
277+
})
278+
Logger.info({
279+
function_name: 'process_file',
280+
message: 'API response received and cleaned',
281+
data: {
282+
file_path: params.file_path,
283+
response_length: cleaned_content?.length
316284
}
317-
318-
Logger.error({
285+
})
286+
return cleaned_content
287+
} catch (error: any) {
288+
if (axios.isCancel(error)) {
289+
Logger.info({
319290
function_name: 'process_file',
320-
message: `Refactoring error (attempt ${attempt})`,
321-
data: { error, file_path: params.file_path }
291+
message: 'Request cancelled',
292+
data: params.file_path
322293
})
323-
console.error(
324-
`Refactoring error for ${params.file_path} (attempt ${attempt}):`,
325-
error
326-
)
327-
328-
if (attempt >= MAX_ATTEMPTS) {
329-
throw error
330-
}
331-
332-
params.on_retry?.(attempt, error)
333-
await new Promise((resolve) => setTimeout(resolve, 3000))
334-
params.on_retry_attempt?.()
294+
throw error
335295
}
296+
297+
Logger.error({
298+
function_name: 'process_file',
299+
message: `Refactoring error`,
300+
data: { error, file_path: params.file_path }
301+
})
302+
console.error(`Refactoring error for ${params.file_path}:`, error)
303+
throw error
336304
}
337-
throw new Error('Processing file failed after maximum attempts')
338305
}

‎apps/editor/src/views/panel/backend/message-handlers/handle-fix-all-failed-files.ts‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,6 @@ export const handle_fix_all_failed_files = async (params: {
184184
})
185185
}
186186

187-
const on_retry_attempt = () => {
188-
params.panel_provider.send_message({
189-
command: 'UPDATE_FILE_PROGRESS',
190-
file_path,
191-
workspace_name,
192-
is_applying: true,
193-
apply_status: 'thinking'
194-
})
195-
}
196-
197-
const on_retry = () => {
198-
params.panel_provider.send_message({
199-
command: 'UPDATE_FILE_PROGRESS',
200-
file_path,
201-
workspace_name,
202-
is_applying: true,
203-
apply_status: 'retrying'
204-
})
205-
}
206-
207187
try {
208188
const updated_content = await process_file({
209189
endpoint_url: endpoint_url,
@@ -217,9 +197,7 @@ export const handle_fix_all_failed_files = async (params: {
217197
instruction: instructions,
218198
cancel_token: cancel_token_source.token,
219199
on_chunk,
220-
on_thinking_chunk,
221-
on_retry_attempt,
222-
on_retry
200+
on_thinking_chunk
223201
})
224202

225203
if (updated_content) {

‎apps/editor/src/views/panel/backend/message-handlers/handle-intelligent-update-file-in-preview.ts‎

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,6 @@ export const handle_intelligent_update_file_in_preview = async (
172172
})
173173
}
174174

175-
const on_retry_attempt = () => {
176-
panel_provider.send_message({
177-
command: 'UPDATE_FILE_PROGRESS',
178-
file_path,
179-
workspace_name,
180-
is_applying: true,
181-
apply_status: 'thinking'
182-
})
183-
}
184-
185-
const on_retry = () => {
186-
panel_provider.send_message({
187-
command: 'UPDATE_FILE_PROGRESS',
188-
file_path,
189-
workspace_name,
190-
is_applying: true,
191-
apply_status: 'retrying'
192-
})
193-
}
194-
195175
const content_promise = process_file({
196176
endpoint_url: endpoint_url,
197177
api_key: api_provider.api_key,
@@ -204,9 +184,7 @@ export const handle_intelligent_update_file_in_preview = async (
204184
instruction: instructions,
205185
cancel_token: cancel_token_source.token,
206186
on_chunk,
207-
on_thinking_chunk,
208-
on_retry_attempt,
209-
on_retry
187+
on_thinking_chunk
210188
})
211189

212190
try {
@@ -255,20 +233,13 @@ export const handle_intelligent_update_file_in_preview = async (
255233
message: 'Error during process_file',
256234
data: { error, file_path }
257235
})
258-
vscode.window.showErrorMessage(
259-
dictionary.error_message.INTELLIGENT_UPDATE_FAILED_FOR_FILE(
260-
file_name,
261-
error.message
262-
)
263-
)
236+
vscode.window.showErrorMessage(error.message)
264237

265-
if (axios.isAxiosError(error)) {
266-
await handle_intelligent_update_file_in_preview(panel_provider, {
267-
...message,
268-
force_model_selection: true
269-
})
270-
return
271-
}
238+
await handle_intelligent_update_file_in_preview(panel_provider, {
239+
...message,
240+
force_model_selection: true
241+
})
242+
return
272243
}
273244
} finally {
274245
const index =

‎apps/editor/src/views/panel/types/messages.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ export type Checkpoint = {
6969
is_starred?: boolean
7070
}
7171

72-
export type FileProgressStatus =
73-
| 'waiting'
74-
| 'thinking'
75-
| 'receiving'
76-
| 'retrying'
72+
export type FileProgressStatus = 'waiting' | 'thinking' | 'receiving'
7773

7874
// === FROM FRONTEND TO BACKEND ===
7975
export interface GetInstructionsMessage extends BaseMessage {
@@ -484,7 +480,7 @@ export interface UpdateFileProgressMessage extends BaseMessage {
484480
file_path: string
485481
workspace_name?: string
486482
is_applying: boolean
487-
apply_status?: 'waiting' | 'thinking' | 'receiving' | 'done' | 'retrying'
483+
apply_status?: 'waiting' | 'thinking' | 'receiving' | 'done'
488484
apply_progress?: number
489485
apply_tokens_per_second?: number
490486
}

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ export const dictionary = {
321321
`Could not find original state for file: ${file_name}.`,
322322
UPDATE_INSTRUCTIONS_FOR_FILE_NOT_FOUND: (file_name: string) =>
323323
`Could not find update instructions for file: ${file_name}.`,
324-
INTELLIGENT_UPDATE_FAILED_FOR_FILE: (file_name: string, message: string) =>
325-
`Applying changes to ${file_name}: ${message}.`,
326324
FAILED_TO_FETCH_OPEN_ROUTER_MODELS:
327325
'Failed to fetch Open Router models. Please check your connection.',
328326
FAILED_TO_GET_CHANGES_FROM_BRANCH: (branch_name: string) =>

‎packages/shared/src/types/file-in-preview.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type FileInPreview = {
1212
apply_failed?: boolean
1313
ai_content?: string
1414
is_applying?: boolean
15-
apply_status?: 'waiting' | 'thinking' | 'receiving' | 'done' | 'retrying'
15+
apply_status?: 'waiting' | 'thinking' | 'receiving' | 'done'
1616
apply_progress?: number
1717
apply_tokens_per_second?: number
1818
applied_with_intelligent_update?: boolean

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export const ResponsePreview: FC<Props> = (props) => {
157157
const get_status_text = (file: FileInPreview) => {
158158
if (file.apply_status == 'waiting') return 'Waiting for server...'
159159
if (file.apply_status == 'thinking') return 'Thinking...'
160-
if (file.apply_status == 'retrying') return 'Retrying...'
161160
if (file.apply_status == 'receiving') return 'Receiving...'
162161
if (file.apply_status == 'done') return 'Done'
163162
return ''

‎packages/ui/src/components/editor/panel/ResponsePreview/components/FileItem/FileItem.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const get_file_message = (file: FileInPreview): FileMessage | null => {
3030
let text = 'Applying...'
3131
if (file.apply_status == 'waiting') text = 'Waiting for server...'
3232
else if (file.apply_status == 'thinking') text = 'Thinking...'
33-
else if (file.apply_status == 'retrying') text = 'Retrying...'
3433
else if (file.apply_status == 'receiving') text = 'Receiving...'
3534
else if (file.apply_status == 'done') text = 'Done'
3635

0 commit comments

Comments
 (0)