stablyai/orca · error · Error

Destination file appeared before download completed

Error message

Destination file appeared before download completed

What it means

Thrown by assertDestinationStillUnclaimed during download promotion. If the destination did not exist when the download started, but now exists when the temp file is about to be renamed, another process created it in the window. The code refuses to overwrite, treating the race as a potential conflict or security concern.

Source

Thrown at src/main/ipc/filesystem.ts:264

    return { existed: true }
  } catch (error) {
    if (isENOENT(error)) {
      return { existed: false }
    }
    throw error
  }
}

async function assertDestinationStillUnclaimed(destinationPath: string): Promise<void> {
  try {
    await stat(destinationPath)
  } catch (error) {
    if (isENOENT(error)) {
      return
    }
    throw error
  }
  throw new Error('Destination file appeared before download completed')
}

async function promoteDownloadedFile(
  tempPath: string,
  destinationPath: string,
  destinationExisted: boolean
): Promise<void> {
  if (!destinationExisted) {
    await assertDestinationStillUnclaimed(destinationPath)
    await rename(tempPath, destinationPath)
    return
  }

  const backupPath = createSiblingTransferPath(destinationPath, 'backup')
  let backupCreated = false
  try {
    await rename(destinationPath, backupPath)
    backupCreated = true

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Retry the download to a different filename.
  2. Ensure no concurrent downloads or sync agents target the same directory.
  3. If the conflict was from a failed prior download, remove the stale file and retry.

Example fix

// before: download to /downloads/file.bin while a sync agent also writes there
// after: pause sync or use a unique filename
//   download to /downloads/file (1).bin
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await ipcRenderer.invoke('fs:downloadFile', { filePath, connectionId })
} catch (error) {
  if (error instanceof Error && error.message === 'Destination file appeared before download completed') {
    showUserWarning('Another process created the destination file. Retry with a different name.')
    return
  }
  throw error
}

Prevention

When it happens

Trigger: Between inspectDownloadDestination (which recorded existed=false) and promoteDownloadedFile (which calls assertDestinationStillUnclaimed), another process or concurrent download creates a file at the exact destination path. The final stat succeeds, indicating the destination is no longer free.

Common situations: Two concurrent downloads targeting the same path. A background sync (Dropbox, iCloud, rsync) creates the file during the download. A user or script creates the file manually while the download is in progress.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/3990115a306c765b. Report an issue: GitHub.