{"record":{"id":"6a94a41e3457d983","repo":"coleam00/Archon","slug":"merge-check-failed-err-message","errorCode":null,"errorMessage":"merge check failed: ${err.message}","messagePattern":"merge check failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/cleanup-service.ts","lineNumber":864,"sourceCode":"        remoteMainRef,\n        prStateCache,\n        includeClosed,\n        remote\n      );\n      safe = decision.safe;\n      openPr = decision.openPr;\n    } catch (error) {\n      const err = error as Error;\n      // Log before skipping — silent skips make transient git/network failures\n      // impossible to debug from the cleanup report alone.\n      getLog().warn(\n        { err, branchName: env.branch_name, repoPath: mainRepoPath },\n        'cleanup.merge_check_failed'\n      );\n      result.skipped.push({\n        branchName: env.branch_name,\n        reason: `merge check failed: ${err.message}`,\n      });\n      continue;\n    }\n    if (!safe) {\n      if (openPr) {\n        result.skipped.push({\n          branchName: env.branch_name,\n          reason: 'PR is open (active review)',\n        });\n      }\n      continue;\n    }\n\n    // Check for uncommitted changes or a live owning run\n    const blocker = await getRemovalBlocker(env);\n    if (blocker) {\n      result.skipped.push({ branchName: env.branch_name, reason: blocker.display });\n      continue;\n    }","sourceCodeStart":846,"sourceCodeEnd":882,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/services/cleanup-service.ts#L846-L882","documentation":"cleanupMergedWorktrees evaluates each isolation environment with isSafeToRemove (merge state, PR state, remote refs). If that safety check itself throws — an unexpected error rather than a 'not safe' verdict — the environment is skipped, never removed, and the branch is recorded in result.skipped with this reason, plus a 'cleanup.merge_check_failed' warn log so the skip is debuggable from the cleanup report.","triggerScenarios":"isSafeToRemove throwing while running git commands (merge-base / rev-parse against remoteMainRef) or querying PR state for env.branch_name: missing repo at mainRepoPath, missing/misconfigured remote, network failure fetching remote refs, corrupt git state, or a PR-API failure not absorbed by the prStateCache.","commonSituations":"No network so remote refs cannot be resolved; remote renamed or deleted; repo moved so mainRepoPath is invalid; GitHub API rate limit or auth failure while checking PR state; unexpected branch_name patterns in the environments table.","solutions":["Read the 'cleanup.merge_check_failed' warn log for the underlying err — the skipped reason string only carries the message.","Fix the git/remote issue (git fetch, restore remote, verify mainRepoPath) and re-run cleanup.","If offline, re-run cleanup when connectivity is restored; skipped environments are intentionally preserved.","Confirm the codebase's git remote and remoteMainRef configuration match the actual repository setup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// per environment, before relying on cleanup results\nconst report = await cleanupMergedWorktrees(codebaseId, mainRepoPath);\nconst blocked = report.skipped.filter(s => s.reason.startsWith('merge check failed:'));\nif (blocked.length > 0) {\n  console.warn('git/network issues during cleanup; rerun after fixing:', blocked.map(b => b.branchName));\n}","typeGuard":"function isMergeCheckSkip(s: { reason: string }): boolean {\n  return s.reason.startsWith('merge check failed: ');\n}","tryCatchPattern":"try {\n  const decision = await isSafeToRemove(repoPath, branchName, remoteMainRef, prStateCache, includeClosed, remote);\n  safe = decision.safe;\n} catch (error) {\n  const err = error as Error;\n  getLog().warn({ err, branchName, repoPath }, 'cleanup.merge_check_failed');\n  result.skipped.push({ branchName, reason: `merge check failed: ${err.message}` });\n  continue; // never remove when safety cannot be proven\n}","preventionTips":["Ensure the main repo has a valid remote and run `git fetch` periodically.","Verify mainRepoPath exists and is the correct checkout before cleanup runs.","Monitor cleanup.merge_check_failed warnings for recurring git/API issues.","Re-run cleanup after transient network failures instead of assuming environments were removed."],"tags":["git","cleanup","worktree","network"],"backgroundTag":"git-remote-unresolved","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}