{"record":{"id":"bef92c22a3aa56ec","repo":"affaan-m/ECC","slug":"rollback-failed-errors-join","errorCode":null,"errorMessage":"rollback failed: ${errors.join('; ')}","messagePattern":"rollback failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/tmux-worktree-orchestrator.js","lineNumber":478,"sourceCode":"    } catch (error) {\n      errors.push(error.message);\n    }\n\n    if (branchExistsImpl(plan.repoRoot, workerPlan.branchName)) {\n      try {\n        runCommandImpl('git', ['branch', '-D', workerPlan.branchName], { cwd: plan.repoRoot });\n      } catch (error) {\n        errors.push(error.message);\n      }\n    }\n  }\n\n  if (createdState.removeCoordinationDir && fs.existsSync(plan.coordinationDir)) {\n    fs.rmSync(plan.coordinationDir, { force: true, recursive: true });\n  }\n\n  if (errors.length > 0) {\n    throw new Error(`rollback failed: ${errors.join('; ')}`);\n  }\n}\n\nfunction executePlan(plan, runtime = {}) {\n  const spawnSyncImpl = runtime.spawnSync || spawnSync;\n  const runCommandImpl = runtime.runCommand || runCommand;\n  const materializePlanImpl = runtime.materializePlan || materializePlan;\n  const overlaySeedPathsImpl = runtime.overlaySeedPaths || overlaySeedPaths;\n  const cleanupExistingImpl = runtime.cleanupExisting || cleanupExisting;\n  const rollbackCreatedResourcesImpl = runtime.rollbackCreatedResources || rollbackCreatedResources;\n  const createdState = {\n    workerPlans: [],\n    sessionCreated: false,\n    removeCoordinationDir: !fs.existsSync(plan.coordinationDir)\n  };\n\n  runCommandImpl('git', ['rev-parse', '--is-inside-work-tree'], { cwd: plan.repoRoot });\n  runCommandImpl('tmux', ['-V']);","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/tmux-worktree-orchestrator.js#L460-L496","documentation":"rollbackCreatedResources attempts to undo partial orchestration setup (removing created worktrees, branches, coordination dirs), collecting each cleanup failure into an errors array. If any rollback step failed, it throws once with all errors joined so the user sees the complete cleanup failure picture.","triggerScenarios":"Calling rollbackCreatedResources after a failed executePlan when the spawned cleanup commands (e.g. 'git worktree remove', 'git branch -D', fs.rmSync) themselves fail — e.g. worktree is locked, dirty, or already gone; branch is checked out elsewhere.","commonSituations":"A first failure left the worktree with uncommitted changes so 'git worktree remove' refuses; the branch is checked out in another worktree; filesystem permission issues prevent removing the coordination dir; concurrent orchestrator runs racing on the same resources.","solutions":["Inspect the joined errors in the message to see which cleanup steps failed.","Manually remove the leftover worktrees: 'git worktree list' then 'git worktree remove --force <path>'.","Delete leftover branches: 'git branch -D orchestrator-<session>-<worker>'.","Remove the coordination directory manually if fs removal failed due to permissions (fix perms or rm -rf)."],"exampleFix":"// after a failed rollback\ngit worktree list\ngit worktree remove --force ../myrepo-my-session-worker1\ngit branch -D orchestrator-my-session-worker1","handlingStrategy":"try-catch","validationCode":"// before orchestrating, ensure no partial state exists\nconst stale = spawnSync('git', ['worktree', 'list'], { encoding: 'utf8' }).stdout;\nif (stale.includes(sessionName)) {\n  spawnSync('git', ['worktree', 'prune']);\n}","typeGuard":null,"tryCatchPattern":"try {\n  executePlan(plan);\n} catch (err) {\n  if (String(err.message).startsWith('rollback failed:')) {\n    console.error('Automatic cleanup failed:', err.message);\n    console.error('Clean up manually: git worktree remove --force <path>; git branch -D <branch>');\n    return;\n  }\n  throw err;\n}","preventionTips":["Keep worktrees clean (no uncommitted changes) so removal succeeds","Avoid running the same session concurrently from two terminals","After any crash, run 'git worktree list' and prune leftovers before retrying","Read each joined error in the message — it enumerates every failed cleanup step"],"tags":["cleanup","rollback","git","filesystem"],"backgroundTag":"unsupported-operation","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}