{"record":{"id":"0250ee02e7e1d934","repo":"Yeachan-Heo/oh-my-codex","slug":"scale-down-cleanup-debt-invalid-worktree-target","errorCode":null,"errorMessage":"scale_down_cleanup_debt_invalid_worktree_target:${worker.name}","messagePattern":"scale_down_cleanup_debt_invalid_worktree_target:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/team/scaling.ts","lineNumber":1605,"sourceCode":"        throw new Error(`scale_down_cleanup_debt_invalid_worktree_metadata:${worker.name}`);\n      }\n      continue;\n    }\n\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(","sourceCodeStart":1587,"sourceCodeEnd":1623,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/team/scaling.ts#L1587-L1623","documentation":"A worker's worktree target metadata has invalid types or an invalid combination: worktree_path must be an absolute normalized path matching the expected location, and repo_root/branch must be strings, detached/created booleans; worktree_created=true requires repo_root string and detached boolean. Message embeds worker name.","triggerScenarios":"validateScaleDownCleanupResources finds worktree_path defined but wrong type/shape, not matching join(repoRoot,'.omx','team',teamName,'worktrees',worker.name), or the created/repo_root/detached combination is inconsistent.","commonSituations":"Repo moved so the recorded absolute worktree_path no longer matches the expected location; hand-edited or corrupted team config; version upgrade changing worktree layout conventions.","solutions":["Compare the recorded worktree_path against <repoRoot>/.omx/team/<team>/worktrees/<worker> and correct the config or move the repo back","Fix type inconsistencies (branch as non-string, detached as non-boolean) in the worker record","Delete the stale worker record and re-add the worker via scaleUp to regenerate valid metadata"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { isAbsolute, join, resolve } from 'node:path';\nfunction validWorktreeTarget(w: WorkerInfo, repoRoot: string, teamName: string): boolean {\n  const expected = join(repoRoot, '.omx', 'team', teamName, 'worktrees', w.name);\n  return w.worktree_path === expected && isAbsolute(w.worktree_path) && w.worktree_path === resolve(w.worktree_path);\n}","typeGuard":null,"tryCatchPattern":"catch (e) {\n  const m = /scale_down_cleanup_debt_invalid_worktree_target:(.+)$/.exec(String((e as Error).message));\n  if (m) { await repairWorktreeRecord(team, m[1]); return retryScaleDown(); }\n  throw e;\n}","preventionTips":["Do not move the repository without regenerating team config","Keep team config under version control to detect drift"],"tags":["team","scale-down","worktree","config","validation"],"backgroundTag":"config-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}