{"record":{"id":"715256d67eb67da0","repo":"Yeachan-Heo/oh-my-codex","slug":"priorscaledowncleanup-error","errorCode":null,"errorMessage":"priorScaleDownCleanup.error","messagePattern":"priorScaleDownCleanup\\.error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/team/runtime.ts","lineNumber":4914,"sourceCode":"    } catch (error) {\n      if (!(error instanceof Error) || !error.message.startsWith('restored_hud_cleanup_debt_unresolved:')) {\n        throw error;\n      }\n      // The config identity is not the debt identity. Remove it durably before\n      // replaying the pinned obligation: a later detached-session teardown must\n      // not treat a live, same-PID/owner non-HUD pane as the restored HUD.\n      config = await mutateShutdownConfig(config, cwd, (current) => {\n        current.hud_pane_id = null;\n        current.hud_pane_pid = undefined;\n      });\n\n      reconcileRestoredHudCleanupDebtSync(cwd, restoredHudDebtRoot);\n    }\n  } else {\n    reconcileRestoredHudCleanupDebtSync(cwd, restoredHudDebtRoot);\n  }\n  const priorScaleDownCleanup = await reconcileScaleDownCleanupDebt(sanitized, cwd, config);\n  if (!priorScaleDownCleanup.ok) throw new Error(priorScaleDownCleanup.error);\n  await reconcileGonePaneDescendantCleanupDebt(sanitized, cwd, config);\n  const manifest = await readTeamManifestV2(sanitized, cwd);\n  const leaderSessionId = typeof manifest?.leader?.session_id === 'string'\n    ? manifest.leader.session_id.trim()\n    : '';\n  const governance = resolveGovernancePolicy(\n    manifest?.governance,\n    manifest?.policy as Partial<TeamGovernance> | undefined,\n  );\n\n  const classification = await withTeamTaskMembershipBarrier(sanitized, cwd, async () => {\n    const current = await classifyShutdown({\n      teamName: sanitized,\n      cwd,\n      config: config!,\n      governance,\n      confirmIssues,\n    });","sourceCodeStart":4896,"sourceCodeEnd":4932,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/team/runtime.ts#L4896-L4932","documentation":"Thrown when reconcileScaleDownCleanupDebt fails during shutdown (returns ok:false); its error string is rethrown verbatim. This step cleans up leftover panes/debt from earlier scale-down operations before the team is torn down.","triggerScenarios":"Running team shutdown while the scale-down cleanup reconciliation encounters an error — e.g. unreadable debt records, tmux failures, or inconsistent pane references recorded from previous scale-downs.","commonSituations":"Leftover scale-down state referencing panes that no longer exist; tmux server restarted so recorded pane IDs are invalid; partially-written cleanup-debt records after a crash.","solutions":["Inspect the reconciler's error message to identify the failing debt record and clean it up manually","Ensure the tmux server/session is reachable, then retry shutdown","As a last resort, clear stale scale-down debt records for the team and retry shutdown"],"exampleFix":"// before\nawait shutdownTeam(team, cwd);\n\n// after\nconst res = await reconcileScaleDownCleanupDebt(team, cwd, config);\nif (!res.ok) await clearScaleDownDebtRecords(team, cwd); // manual cleanup\nawait shutdownTeam(team, cwd);","handlingStrategy":"retry","validationCode":"const res = await reconcileScaleDownCleanupDebt(teamName, cwd, config);\nif (!res.ok) throw new Error(res.error);","typeGuard":null,"tryCatchPattern":"try { await shutdownTeam(t, cwd); } catch (e) { if (/scale.?down/i.test((e as Error).message)) { await clearScaleDownDebtRecords(t, cwd); await shutdownTeam(t, cwd); } else throw e; }","preventionTips":["Keep tmux reachable during shutdown","Clean up scale-down debt promptly after scaling operations","Log and clear malformed debt records early"],"tags":["shutdown","scale-down","cleanup"],"backgroundTag":"cleanup-reconciliation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}