File tree Expand file tree Collapse file tree
apps/desktop/src/main/desktop-executor
packages/desktop-bridge/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 */
311313export 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
You can’t perform that action at this time.
0 commit comments