{"record":{"id":"aa4027f457bb9e95","repo":"can1357/oh-my-pi","slug":"objective-is-required-when-op-create","errorCode":null,"errorMessage":"objective is required when op=create","messagePattern":"objective is required when op=create","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/goals/runtime.ts","lineNumber":386,"sourceCode":"\n\t#createGoalState(objective: string, tokenBudget: number | undefined): GoalModeState {\n\t\tconst now = this.#now();\n\t\tconst goal: Goal = {\n\t\t\tid: String(Snowflake.next()),\n\t\t\tobjective,\n\t\t\tstatus: \"active\",\n\t\t\ttokenBudget,\n\t\t\ttokensUsed: 0,\n\t\t\ttimeUsedSeconds: 0,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\treturn { enabled: true, mode: \"active\", goal };\n\t}\n\n\tasync createGoal(input: { objective: string; tokenBudget?: number }): Promise<GoalModeState> {\n\t\tconst objective = input.objective.trim();\n\t\tif (!objective) throw new Error(\"objective is required when op=create\");\n\t\tvalidateTokenBudget(input.tokenBudget);\n\t\treturn await this.#withAccounting(async () => {\n\t\t\tconst existing = this.#host.getState();\n\t\t\tif (existing?.goal && existing.goal.status !== \"dropped\" && existing.goal.status !== \"complete\") {\n\t\t\t\tthrow new Error(\"cannot create a new goal because this session already has a goal\");\n\t\t\t}\n\t\t\tconst state = this.#createGoalState(objective, input.tokenBudget);\n\t\t\tthis.#budgetReportedFor = undefined;\n\t\t\tthis.#markActiveAccounting(state.goal);\n\t\t\tawait this.#commitState(state, { persist: \"goal\" });\n\t\t\treturn state;\n\t\t});\n\t}\n\n\tasync replaceGoal(input: { objective: string; tokenBudget?: number }): Promise<GoalModeState> {\n\t\tconst objective = input.objective.trim();\n\t\tif (!objective) throw new Error(\"objective is required when op=replace\");\n\t\tvalidateTokenBudget(input.tokenBudget);","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/goals/runtime.ts#L368-L404","documentation":"createGoal requires a non-empty objective string. The runtime trims the input and throws when the result is empty, since a goal with no objective is meaningless to track or report on.","triggerScenarios":"Calling createGoal with objective set to '' or a whitespace-only string ('   '), or with an undefined/null coerced into an empty string by upstream code.","commonSituations":"Tool-call arguments where the LLM supplied an empty objective; UI forms submitted without filling the goal field; config files with objective: \"\" placeholders.","solutions":["Provide a meaningful objective string before calling createGoal","Trim and check the objective in the caller and show a validation message instead","Reject empty objective at the tool/schema boundary so the runtime is never called with one"],"exampleFix":"// before\nawait runtime.createGoal({ objective: userGoal.trim() });\n// after\nconst objective = userGoal.trim();\nif (!objective) throw new Error('Goal objective must not be empty');\nawait runtime.createGoal({ objective });","handlingStrategy":"validation","validationCode":"if (typeof objective !== 'string' || objective.trim().length === 0) {\n  throw new Error('objective must be a non-empty string');\n}","typeGuard":"function hasObjective(input: { objective: string }): boolean {\n  return typeof input.objective === 'string' && input.objective.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runtime.createGoal({ objective });\n} catch (err) {\n  if (err instanceof Error && err.message === 'objective is required when op=create') {\n    return { ok: false, reason: 'empty-objective' };\n  }\n  throw err;\n}","preventionTips":["Trim and length-check user/LLM-supplied objectives before calling","Enforce min-length on the objective in your tool schema or form validation","Never build objective strings by joining possibly-empty arrays without a guard"],"tags":["validation","arguments","goals"],"backgroundTag":"missing-required-parameter","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}