{"record":{"id":"baeacb3feec963c0","repo":"Yeachan-Heo/oh-my-codex","slug":"cannot-add-a-goal-to-an-already-completed-aggregat","errorCode":null,"errorMessage":"Cannot add a goal to an already completed aggregate ultragoal plan; start a new plan for post-terminal work.","messagePattern":"Cannot add a goal to an already completed aggregate ultragoal plan; start a new plan for post-terminal work\\.","errorType":"exception","errorClass":"UltragoalError","httpStatus":null,"severity":"error","filePath":"src/ultragoal/artifacts.ts","lineNumber":1177,"sourceCode":"    title,\n    objective,\n    status: 'pending',\n    attempt: 0,\n    createdAt: now,\n    updatedAt: now,\n    evidence: options.evidence,\n    resolvesReviewBlockedGoalId: options.resolvesReviewBlockedGoalId,\n  };\n  plan.goals.push(goal);\n  plan.updatedAt = now;\n  return goal;\n}\n\nexport async function addUltragoalGoal(cwd: string, options: AddUltragoalGoalOptions): Promise<{ plan: UltragoalPlan; goal: UltragoalItem }> {\n  return withUltragoalMutationLock(cwd, async () => {\n  const plan = await readUltragoalPlanUnderLock(cwd);\n  if (plan.aggregateCompletion?.status === 'complete') {\n    throw new UltragoalError('Cannot add a goal to an already completed aggregate ultragoal plan; start a new plan for post-terminal work.');\n  }\n  const now = iso(options.now);\n  const goal = appendGoalToPlan(plan, options);\n  await writePlan(cwd, plan);\n  await appendLedger(cwd, {\n    ts: now,\n    event: 'goal_added',\n    goalId: goal.id,\n    status: goal.status,\n    evidence: options.evidence,\n    message: goal.title,\n  });\n  return { plan, goal };\n  });\n}\n\n\nfunction proposalTargetIds(proposal: UltragoalSteeringProposal): string[] {","sourceCodeStart":1159,"sourceCodeEnd":1195,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/ultragoal/artifacts.ts#L1159-L1195","documentation":"addUltragoalGoal rejects additions to a plan whose aggregateCompletion.status is 'complete'. Once the aggregate ultragoal is terminal, the plan is considered closed and post-terminal work must go into a new plan.","triggerScenarios":"Calling addUltragoalGoal on a plan that was previously finalized with aggregate completion marked complete — e.g. continuing to append goals after a release/milestone was closed out.","commonSituations":"Reopening work after a milestone was marked complete; automation that appends goals on a schedule hitting an already-finalized repo; two teams sharing a repo where one finalized the plan.","solutions":["Create a fresh plan for the new work: `omx ultragoal create-goals --force` (or in a new plan location) instead of appending","If the completion was premature/mistaken, edit or re-run the finalize flow to reopen the plan before adding goals","Add a pre-check in automation: read the plan and skip add when aggregateCompletion.status === 'complete'"],"exampleFix":"// before\nawait addUltragoalGoal(cwd, { objective: 'post-launch tweak' }); // throws 1174\n\n// after\nconst plan = await readUltragoalPlan(cwd);\nif (plan.aggregateCompletion?.status === 'complete') {\n  await createUltragoalPlan(cwd, { brief: 'post-launch', force: true });\n} else {\n  await addUltragoalGoal(cwd, { objective: 'post-launch tweak' });\n}","handlingStrategy":"type-guard","validationCode":"const plan = await readUltragoalPlan(cwd);\nconst completed = plan.aggregateCompletion?.status === 'complete';\nif (!completed) await addUltragoalGoal(cwd, opts);","typeGuard":"function isPlanOpen(plan: UltragoalPlan): boolean { return plan.aggregateCompletion?.status !== 'complete'; }","tryCatchPattern":"try { await addUltragoalGoal(cwd, opts); } catch (e) { if (e instanceof UltragoalError && e.message.includes('already completed')) { await createUltragoalPlan(cwd, { brief: 'post-terminal', force: true }); } else throw e; }","preventionTips":["Check aggregateCompletion.status before appending goals","Treat 'complete' as terminal: plan new work in a new plan","Guard scheduled/automated adders with the open-plan check"],"tags":["ultragoal","terminal-state","add-goal","lifecycle"],"backgroundTag":"operation-on-finalized-resource","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}