{"record":{"id":"677ef6e6b75b4b29","repo":"stablyai/orca","slug":"could-not-generate-a-unique-name-for-originalna-677ef6","errorCode":null,"errorMessage":"Could not generate a unique name for '${originalName}' after ${counter} attempts","messagePattern":"Could not generate a unique name for '(.+?)' after (.+?) attempts","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/filesystem-mutations.ts","lineNumber":794,"sourceCode":"  const stem = hasMeaningfulExt ? originalName.slice(0, dotIndex) : originalName\n  const ext = hasMeaningfulExt ? originalName.slice(dotIndex) : ''\n\n  let candidate = `${stem} copy${ext}`\n  if (!(await nameExists(destDir, candidate)) && !reservedNames.has(candidate)) {\n    return candidate\n  }\n\n  let counter = 2\n  while (counter < 10000) {\n    candidate = `${stem} copy ${counter}${ext}`\n    if (!(await nameExists(destDir, candidate)) && !reservedNames.has(candidate)) {\n      return candidate\n    }\n    counter += 1\n  }\n\n  // Extremely unlikely fallback\n  throw new Error(\n    `Could not generate a unique name for '${originalName}' after ${counter} attempts`\n  )\n}\n\nasync function nameExists(dir: string, name: string): Promise<boolean> {\n  try {\n    await lstat(join(dir, name))\n    return true\n  } catch (error) {\n    if (isENOENT(error)) {\n      return false\n    }\n    throw error\n  }\n}\n","sourceCodeStart":776,"sourceCodeEnd":810,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/filesystem-mutations.ts#L776-L810","documentation":"Thrown by deconflictName when it cannot find a unique name after trying 9998 candidates (counter 2 through 9999). The function appends ' copy', ' copy 2', ..., ' copy 9999' and checks both filesystem existence and an in-batch reserved set. This is an extremely unlikely fallback meant to guarantee termination.","triggerScenarios":"The destination directory already contains 9999+ files with names matching the pattern 'stem copy N.ext' for the same stem, or the reservedNames set (tracking in-batch deconfliction) covers all 9998 candidates. The loop exits at counter = 10000 without finding a free name.","commonSituations":"Importing into a directory with thousands of similarly-named files from repeated copy operations. A bug or loop in the caller that generates an enormous reservedNames set. Importing a very large batch where many source files have identical names.","solutions":["Clear or reduce the number of similarly-named files in the destination directory.","Choose a different destination directory with fewer name collisions.","If importing a batch, ensure source files have distinct names or import in smaller batches."],"exampleFix":"// before: import into /dest which has 9999+ \"report copy N.csv\" files\n// after: clean up or use a fresh directory\n//   rm /dest/'report copy '*.csv\n//   or: import into /dest/fresh-batch/","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await importLocalSource(sourcePath, destDir)\n} catch (error) {\n  if (error instanceof Error && error.message.includes('Could not generate a unique name')) {\n    showUserError('Too many name collisions in the destination. Use a different folder or clean up existing copies.')\n    return\n  }\n  throw error\n}","preventionTips":["Choose a destination directory with fewer similarly-named files.","Avoid repeatedly importing the same file into the same directory thousands of times.","Clean up old 'copy N' files before bulk-importing large batches."],"tags":["deconfliction","filesystem","local-import","naming","ipc"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}