Skip to content

Commit 087a309

Browse files
committed
fix(desktop): an import the rate limit never let start stays safe to ask for again
When Sim's rate limit outlasts every retry, it refused the entry outright, so the result lists exactly what landed instead of being outcome unknown. An import where nothing landed is no longer marked do-not-retry.
1 parent 5860fd7 commit 087a309

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

‎apps/desktop/src/main/desktop-executor/runner.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,19 @@ describe('background imports', () => {
271271
])
272272
})
273273

274+
it('reports an import the rate limit never let start as safe to ask for again', async () => {
275+
const sim = recordingSim(() => new DeviceRequestError(429, 'Too many requests', 1))
276+
const completion = await runner({ imports: { importEntry: sim.importEntry } }).run(
277+
importCall(await reportsFolder()),
278+
new AbortController().signal
279+
)
280+
281+
expect(completion.status).toBe('error')
282+
expect(completion.data).toMatchObject({ partial: false, files: [], folders: [] })
283+
expect(completion.data).not.toHaveProperty('doNotRetry')
284+
expect(completion.data).not.toHaveProperty('outcomeUnknown')
285+
})
286+
274287
it('fails without storing anything when the source cannot be read', async () => {
275288
const sim = recordingSim()
276289
const completion = await runner({ imports: { importEntry: sim.importEntry } }).run(

‎apps/desktop/src/main/desktop-executor/runner.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ export function createDesktopToolRunner(deps: DesktopToolRunnerDeps): DesktopToo
321321
return localFileImportCompletion(
322322
localFileImportFailure(
323323
{ workspaceId: targetWorkspaceId, files, folders },
324-
getErrorMessage(error)
324+
getErrorMessage(error),
325+
// A rate limit that outlasted every retry refused the entry outright: nothing of it landed.
326+
{ outcomeKnown: error instanceof DeviceRequestError && error.status === 429 }
325327
)
326328
)
327329
}

‎packages/desktop-bridge/src/tool-results.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,24 @@ export interface DesktopLocalFileImportResult {
305305
}
306306

307307
/**
308-
* An import that stopped part way. Files it already created stay; whether more landed than it
309-
* reports is unknown, so the model inspects the workspace instead of importing again.
308+
* An import that stopped part way. Files it already created stay. Usually whether more landed than
309+
* it reports is unknown, so the model inspects the workspace instead of importing again. With
310+
* `outcomeKnown` (Sim refused the next entry outright), the list is exact, and an import where
311+
* nothing landed can simply be asked for again.
310312
*/
311313
export function localFileImportFailure(
312314
partial: Pick<DesktopLocalFileImportResult, 'workspaceId' | 'files' | 'folders'>,
313-
error: string
315+
error: string,
316+
options: { outcomeKnown?: boolean } = {}
314317
): DesktopLocalFileImportResult {
318+
const landed = partial.files.length > 0 || partial.folders.length > 0
315319
return {
316320
success: false,
317321
...partial,
318322
error,
319-
partial: partial.files.length > 0 || partial.folders.length > 0,
320-
doNotRetry: true,
321-
outcomeUnknown: true,
323+
partial: landed,
324+
...(landed || !options.outcomeKnown ? { doNotRetry: true as const } : {}),
325+
...(options.outcomeKnown ? {} : { outcomeUnknown: true as const }),
322326
}
323327
}
324328

0 commit comments

Comments
 (0)