{"record":{"id":"259dc2dc900f3454","repo":"stablyai/orca","slug":"cannot-safely-offer-force-delete-for-preserved-bra","errorCode":null,"errorMessage":"Cannot safely offer force-delete for preserved branch \"${result.preservedBranch.branchName}\" without its saved commit.","messagePattern":"Cannot safely offer force-delete for preserved branch \"(.+?)\" without its saved commit\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktrees.ts","lineNumber":545,"sourceCode":"  hostId: ExecutionHostId\n  branchName: string\n  head: string\n  pushTarget?: GitPushTarget\n}\n\nconst preservedBranchCleanupByScope = new Map<string, PreservedBranchCleanupTarget>()\n\nfunction rememberPreservedBranchCleanupTarget(\n  worktreeId: string,\n  hostId: ExecutionHostId,\n  result: RemoveWorktreeResult | undefined,\n  fallbackHead: string | undefined,\n  pushTarget: GitPushTarget | undefined\n): void {\n  if (result?.preservedBranch) {\n    const head = result.preservedBranch.head ?? fallbackHead\n    if (!head) {\n      throw new Error(\n        `Cannot safely offer force-delete for preserved branch \"${result.preservedBranch.branchName}\" without its saved commit.`\n      )\n    }\n    preservedBranchCleanupByScope.set(preservedBranchCleanupScopeKey({ worktreeId, hostId }), {\n      worktreeId,\n      hostId,\n      branchName: result.preservedBranch.branchName,\n      head,\n      ...(pushTarget ? { pushTarget } : {})\n    })\n    return\n  }\n  preservedBranchCleanupByScope.delete(preservedBranchCleanupScopeKey({ worktreeId, hostId }))\n}\n\nfunction preserveBranchHeadFallback(\n  result: RemoveWorktreeResult | undefined,\n  fallbackHead: string | undefined","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktrees.ts#L527-L563","documentation":"Thrown by rememberPreservedBranchCleanupTarget when a RemoveWorktreeResult reports a preservedBranch but neither result.preservedBranch.head nor the fallbackHead (the registered worktree's HEAD) is available. Without a concrete commit SHA, Orca refuses to register a force-delete target because it cannot prove which commit to delete. This is a defensive invariant inside the remove flow, not a user-input error.","triggerScenarios":"A worktrees:remove whose Git result preserved a branch (preserveBranchOnDelete) but the worktree list entry carried no resolvable head, and the registeredWorktree.head passed as fallback was also undefined.","commonSituations":"Git reported a detached/unborn HEAD for the worktree, a remote SSH provider returned a worktree entry without head metadata, or an older provider implementation omitted the head field. Usually points to an unexpected Git/provider state rather than a config mistake.","solutions":["Ensure the Git worktree list reports a HEAD for that worktree (check `git worktree list --porcelain` on the host).","If using an SSH provider, confirm the provider version returns head in its worktree listings.","Treat this as an internal defect: capture the remove args and the worktree list at the time of failure and report it, since the caller cannot supply the missing commit safely."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In the remove flow, guard the remember call so a missing head does not abort cleanup.\ntry {\n  rememberPreservedBranchCleanupTarget(worktreeId, hostId, removalResult, fallbackHead, pushTarget)\n} catch (e) {\n  // Log and skip registering a force-delete target; the branch can still be deleted manually later.\n  console.warn('[worktrees] cannot register preserved-branch cleanup (no head)', e)\n}","preventionTips":["Treat a missing head as a provider/Git defect to investigate, not a user error.","Ensure SSH providers return head in worktree listings.","Capture the worktree list at failure time to diagnose why HEAD was unresolved."],"tags":["worktree-remove","preserved-branch","internal-invariant","ssh"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}