{"record":{"id":"0b15bc64ff266863","repo":"paperclipai/paperclip","slug":"git-worktree-branch-mismatch","errorCode":"git_worktree_branch_mismatch","errorMessage":"Issue ${issue.identifier ?? issue.id} expected git worktree branch \"${expectedManagedBranchName}\" at \"${effectiveCwd}\", but ${inspection.reason ?? \"the checked-out branch could not be verified\"}.","messagePattern":"Issue (.+?) expected git worktree branch \"(.+?)\" at \"(.+?)\", but (.+?)\\.","errorType":"validation","errorClass":"WorkspaceValidationFailure","httpStatus":null,"severity":"error","filePath":"server/src/services/heartbeat.ts","lineNumber":2302,"sourceCode":"      scrubGitCredentialText(\n        `Failed to prepare managed checkout for \"${input.repoUrl}\" at \"${cwd}\": ${reason}${authNote ? ` ${authNote}` : \"\"}`,\n      ),\n    );\n  }\n\n  try {\n    await fs.rename(cloneTmpDir, cwd);\n  } catch (renameError) {\n    await fs\n      .rm(cloneTmpDir, { recursive: true, force: true })\n      .catch(() => undefined);\n    // The target appearing between the emptiness check and the rename means another\n    // materialization won the race; adopt its checkout instead of failing the run.\n    if (await hasAdoptableGitDir()) {\n      return { cwd, warning: null };\n    }\n    const reason =\n      renameError instanceof Error ? renameError.message : String(renameError);\n    throw new Error(\n      `Failed to move managed checkout into place at \"${cwd}\": ${reason}`,\n    );\n  }\n  return { cwd, warning: null };\n}\n\n/**\n * Resolve one project workspace row to a usable cwd. The anchor path and each additional\n * referenced project share this step: use the configured cwd when present, otherwise clone or\n * create the managed checkout directory for the project. It throws only when the managed\n * checkout cannot be prepared (for example, a clone failure).\n */\nasync function resolveConfiguredOrManagedProjectCwd(input: {\n  companyId: string;\n  projectId: string;\n  cwd: string | null;\n  repoUrl: string | null;","sourceCodeStart":2284,"sourceCodeEnd":2320,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/heartbeat.ts#L2284-L2320","documentation":"Error \"Issue ${issue.identifier ?? issue.id} expected git worktree branch \"${expectedManagedBranchName}\" at \"${effectiveCwd}\", but ${inspection.reason ?? \"the checked-out branch could not be verified\"}.\" thrown in paperclipai/paperclip.","triggerScenarios":"Thrown at server/src/services/heartbeat.ts:2134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restore the expected managed branch in the worktree, or record a sanctioned branch transition, then retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}