{"record":{"id":"cc7bfb59935b2948","repo":"stablyai/orca","slug":"a-worktree-cannot-be-attached-to-itself","errorCode":null,"errorMessage":"A worktree cannot be attached to itself.","messagePattern":"A worktree cannot be attached to itself\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktree-remote.ts","lineNumber":198,"sourceCode":"}\n\nfunction getSetupRunnerCommandPlatformForLaunch(\n  setup: CreateWorktreeResult['setup'],\n  fallbackPlatform: 'windows' | 'posix'\n): 'windows' | 'posix' {\n  return getSetupRunnerCommandPlatformForPath(setup?.runnerScriptPath ?? '', fallbackPlatform)\n}\n\nfunction validateWorkspaceLineageParentBeforeCreate(\n  store: Store,\n  parentWorkspace: CreateWorktreeArgs['parentWorkspace'],\n  childWorkspaceKey: ReturnType<typeof worktreeWorkspaceKey>\n): void {\n  if (!parentWorkspace) {\n    return\n  }\n  if (parentWorkspace === childWorkspaceKey) {\n    throw new Error('A worktree cannot be attached to itself.')\n  }\n  const parentScope = parseWorkspaceKey(parentWorkspace)\n  if (!parentScope) {\n    throw new Error(`Invalid parent workspace: ${parentWorkspace}`)\n  }\n  if (parentScope.type === 'folder' && !store.getFolderWorkspace(parentScope.folderWorkspaceId)) {\n    throw new Error(`Parent folder workspace not found: ${parentWorkspace}`)\n  }\n  if (parentScope.type === 'worktree' && !store.getWorktreeMeta(parentScope.worktreeId)) {\n    throw new Error(`Parent worktree workspace not found: ${parentWorkspace}`)\n  }\n}\n\nfunction recordWorkspaceLineageForCreatedWorktree(\n  store: Store,\n  args: CreateWorktreeArgs,\n  worktree: Worktree,\n  createdAt: number","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktree-remote.ts#L180-L216","documentation":"Thrown by validateWorkspaceLineageParentBeforeCreate when the supplied parentWorkspace key equals the childWorkspaceKey being created. A worktree cannot be its own parent in the workspace lineage graph — that would create a self-referential cycle. The check is a strict equality on the composite workspace keys and fires before any broader parent-existence validation.","triggerScenarios":"createWorktree is called with parentWorkspace set to the same worktreeWorkspaceKey value computed for the new child. The lineage validation detects parentWorkspace === childWorkspaceKey and throws.","commonSituations":"A UI bug passes the currently-selected workspace's key as the parent of a worktree being created inside that same workspace. A programmatic caller computes both keys from the same source without distinguishing them. State desync after a workspace rename leaves parent and child keys identical.","solutions":["Pass a distinct parent workspace key (or omit parentWorkspace to create a top-level worktree).","Fix the caller so the parent key is sourced from a different workspace than the child.","Add an upstream equality check in the UI to disable self-attachment before submission."],"exampleFix":"// before\ncreateWorktree({ ..., parentWorkspace: childKey })\n// after\ncreateWorktree({ ..., parentWorkspace: distinctParentKey })\n// or top-level:\ncreateWorktree({ ..., parentWorkspace: undefined })","handlingStrategy":"validation","validationCode":"function isSelfAttachment(parentWorkspace: string | undefined, childKey: string): boolean {\n  return !!parentWorkspace && parentWorkspace === childKey\n}\nif (isSelfAttachment(args.parentWorkspace, childKey)) {\n  throw new Error('Cannot attach a worktree to itself')\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createWorktree(args)\n} catch (e) {\n  if (/A worktree cannot be attached to itself/.test((e as Error).message)) {\n    showFieldError('parent', 'Select a different parent or none.')\n    return\n  } else throw e\n}","preventionTips":["Disable self-selection in the parent-picker UI.","Source parent and child keys from distinct workspace objects.","Clear the parent reference when the user starts creating inside the current workspace."],"tags":["worktree","validation","lineage","workspace","cycle-detection"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}