{"record":{"id":"1e2dd1f2397fe5e8","repo":"Yeachan-Heo/oh-my-codex","slug":"scale-down-cleanup-debt-worktree-symlink-worker","errorCode":null,"errorMessage":"scale_down_cleanup_debt_worktree_symlink:${worker.name}","messagePattern":"scale_down_cleanup_debt_worktree_symlink:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/team/scaling.ts","lineNumber":1609,"sourceCode":"\n    const expectedWorktreePath = join(repoRoot, '.omx', 'team', teamName, 'worktrees', worker.name);\n    if (!isAbsolute(worker.worktree_path) || worker.worktree_path !== resolve(worker.worktree_path)\n      || resolve(worker.worktree_path) !== expectedWorktreePath\n      || (worker.worktree_repo_root !== undefined && (\n        !isAbsolute(worker.worktree_repo_root)\n        || worker.worktree_repo_root !== resolve(worker.worktree_repo_root)\n        || resolve(worker.worktree_repo_root) !== repoRoot\n      ))\n      || (worker.worktree_detached !== undefined && typeof worker.worktree_detached !== 'boolean')\n      || (worker.worktree_created !== undefined && typeof worker.worktree_created !== 'boolean')\n      || (worker.worktree_created === true && (\n        typeof worker.worktree_repo_root !== 'string' || typeof worker.worktree_detached !== 'boolean'\n      ))) {\n      throw new Error(`scale_down_cleanup_debt_invalid_worktree_target:${worker.name}`);\n    }\n    await assertExistingPathParentContained(expectedWorktreePath, repoRoot);\n    if (existsSync(expectedWorktreePath) && await realpath(expectedWorktreePath) !== expectedWorktreePath) {\n      throw new Error(`scale_down_cleanup_debt_worktree_symlink:${worker.name}`);\n    }\n  }\n}\n\nasync function cleanupScaleDownResources(\n  teamName: string,\n  teamStateRoot: string,\n  workers: readonly ScaleDownCleanupDebtResource[],\n): Promise<void> {\n  for (const worker of workers) {\n    // An absent exact worktree means a prior cleanup completed before crashing.\n    // Do not replay a restoration or git removal against a replacement path.\n    if (worker.worktree_path && existsSync(worker.worktree_path)) {\n      await removeWorkerWorktreeRootAgentsFile(\n        teamName,\n        worker.name,\n        worker.team_state_root ?? teamStateRoot,\n        worker.worktree_path,","sourceCodeStart":1591,"sourceCodeEnd":1627,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/team/scaling.ts#L1591-L1627","documentation":"The expected worktree path for a worker exists but realpath() differs from the path itself, i.e. the worktree is (or contains) a symlink. Scale-down cleanup refuses to operate through symlinks. Message embeds worker name.","triggerScenarios":"validateScaleDownCleanupResources finds existsSync(expectedWorktreePath) true and realpath(...) !== path, meaning a symlink was planted at the expected worktree location.","commonSituations":"Users symlinking worktrees to another disk for space; malicious or accidental symlink placing cleanup targets outside the repo; backup tools replacing directories with links.","solutions":["Replace the symlink with a real directory (or remove it and let the tool recreate the worktree)","Avoid symlinking .omx/team/*/worktrees entries; configure worktree storage location properly instead","Re-run scale-down after removing the link"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { existsSync, realpathSync, statSync } from 'node:fs';\nfunction worktreeIsRealDir(p: string): boolean {\n  return !existsSync(p) || (statSync(p).isDirectory() && realpathSync(p) === p);\n}","typeGuard":null,"tryCatchPattern":"catch (e) {\n  const m = /scale_down_cleanup_debt_worktree_symlink:(.+)$/.exec(String((e as Error).message));\n  if (m) { await replaceSymlinkWithDir(team, m[1]); return retryScaleDown(); }\n  throw e;\n}","preventionTips":["Never replace worktree directories with symlinks","Configure storage location properly instead of linking around it"],"tags":["team","scale-down","worktree","symlink","security"],"backgroundTag":"path-traversal-detected","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}