{"record":{"id":"988a709475ab759e","repo":"affaan-m/ECC","slug":"tmux-session-already-exists-plan-sessionname","errorCode":null,"errorMessage":"tmux session already exists: ${plan.sessionName}","messagePattern":"tmux session already exists: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/tmux-worktree-orchestrator.js","lineNumber":506,"sourceCode":"  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']);\n\n  if (plan.replaceExisting) {\n    cleanupExistingImpl(plan);\n  } else {\n    const hasSession = spawnSyncImpl('tmux', ['has-session', '-t', plan.sessionName], {\n      encoding: 'utf8',\n      stdio: ['ignore', 'pipe', 'pipe']\n    });\n    if (hasSession.status === 0) {\n      throw new Error(`tmux session already exists: ${plan.sessionName}`);\n    }\n  }\n\n  try {\n    materializePlanImpl(plan);\n\n    for (const workerPlan of plan.workerPlans) {\n      runCommandImpl('git', workerPlan.gitArgs, { cwd: plan.repoRoot });\n      createdState.workerPlans.push(workerPlan);\n      overlaySeedPathsImpl({\n        repoRoot: plan.repoRoot,\n        seedPaths: workerPlan.seedPaths,\n        worktreePath: workerPlan.worktreePath\n      });\n    }\n\n    runCommandImpl(\n      'tmux',","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/tmux-worktree-orchestrator.js#L488-L524","documentation":"executePlan refuses to start when a tmux session with plan.sessionName already exists (checked via 'tmux has-session -t'). This prevents attaching duplicate panes/workers into an existing session or silently reusing stale state from a previous run.","triggerScenarios":"Calling executePlan twice with the same sessionName; a previous run crashed after creating the tmux session but before cleanup; skipExistingSession/precheck flag disabled so the has-session check runs and returns status 0.","commonSituations":"Re-running the orchestrator after an aborted run without cleanup; two team members launching the same session name concurrently; session left over from an interactive tmux experiment with the same name.","solutions":["Kill the existing session: run 'tmux kill-session -t <sessionName>' and re-run the orchestrator.","Use a different sessionName in the plan if the old session must be preserved.","Attach to the existing session ('tmux attach -t <sessionName>') if it is actually the run you want.","Check for and clean up leftover sessions after crashed runs: 'tmux ls'."],"exampleFix":"// before (fails)\nnode orchestrator.js --session my-session\n// after\ntmux kill-session -t my-session\nnode orchestrator.js --session my-session","handlingStrategy":"validation","validationCode":"const { status } = spawnSync('tmux', ['has-session', '-t', sessionName], { stdio: 'ignore' });\nif (status === 0) {\n  console.error(`session '${sessionName}' exists — kill it first: tmux kill-session -t ${sessionName}`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  executePlan(plan);\n} catch (err) {\n  if (String(err.message).startsWith('tmux session already exists')) {\n    spawnSync('tmux', ['kill-session', '-t', plan.sessionName], { stdio: 'inherit' });\n    executePlan(plan); // retry once after cleanup\n    return;\n  }\n  throw err;\n}","preventionTips":["Run 'tmux ls' before starting and kill stale sessions from crashed runs","Use unique session names per user/task to avoid team collisions","Wrap orchestration in a script that kills the session in a trap/finally block","Only reuse a session name intentionally after confirming the old run is dead"],"tags":["tmux","session","conflict"],"backgroundTag":"address-already-in-use","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"}