{"record":{"id":"21e09fe0d7a4b869","repo":"Yeachan-Heo/oh-my-codex","slug":"question-invalid-answer","errorCode":"question_invalid_answer","errorMessage":"answers[${entry.index}].answer selected value is not in the option schema: ${selectedValue}","messagePattern":"answers\\[(.+?)\\]\\.answer selected value is not in the option schema: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/question/state.ts","lineNumber":391,"sourceCode":"    if (selectedValues.length !== 1 || selectedValues[0] !== otherText || answer.value !== otherText) {\n      throw new Error(`answers[${entry.index}].answer other value must match selected_values[0] and other_text`);\n    }\n    assertSelectedLabelsMatch(\n      selectedLabels,\n      [question.other_label],\n      `answers[${entry.index}].answer.selected_labels`,\n    );\n    return;\n  }\n\n  if (answer.kind === 'option') {\n    if (multi) throw new Error(`answers[${entry.index}].answer.kind=option is only valid for single-answerable questions`);\n    if (selectedValues.length !== 1 || selectedLabels.length !== 1) {\n      throw new Error(`answers[${entry.index}].answer must select exactly one option`);\n    }\n    const selectedValue = selectedValues[0]!;\n    if (!optionValues.has(selectedValue)) {\n      throw new Error(`answers[${entry.index}].answer selected value is not in the option schema: ${selectedValue}`);\n    }\n    if (answer.value !== selectedValue) {\n      throw new Error(`answers[${entry.index}].answer.value must match selected_values[0]`);\n    }\n    assertSelectedLabelsMatch(\n      selectedLabels,\n      expectedSelectedLabelsForValues(question, selectedValues, undefined),\n      `answers[${entry.index}].answer.selected_labels`,\n    );\n    return;\n  }\n\n  if (!multi) throw new Error(`answers[${entry.index}].answer.kind=multi is only valid for multi-answerable questions`);\n  if (!Array.isArray(answer.value)) throw new Error(`answers[${entry.index}].answer.value must be an array for multi answers`);\n  if (answer.value.length !== selectedValues.length || answer.value.some((value, index) => value !== selectedValues[index])) {\n    throw new Error(`answers[${entry.index}].answer.value must match selected_values`);\n  }\n  if (outOfSchemaValues.length > 0) {","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/question/state.ts#L373-L409","documentation":"For option-kind answers the single selected value must be one of the question's option values. This is the single-select counterpart of the schema membership check and carries code question_invalid_answer.","triggerScenarios":"kind 'option' where selected_values[0] is not in optionValues — e.g. a label, a sentinel, or a value from an outdated schema.","commonSituations":"Submitting labels instead of values; stale client schema after options changed; hand-crafted payloads in scripts/tests with guessed values.","solutions":["Map UI choice to question.options[].value before submit","Refresh the question schema if options may have changed since render"],"exampleFix":"// before\nanswer.selected_values = [selectedLabel];\n// after\nanswer.selected_values = [question.options.find((o) => o.label === selectedLabel)!.value];","handlingStrategy":"validation","validationCode":"const known = new Set(question.options.map((o) => o.value));\nif (answer.kind === 'option' && !known.has(answer.selected_values[0]!)) throw new Error('value not in schema — remap from fresh schema');","typeGuard":"function valueInSchema(q: NormalizedQuestionItem, v: string): boolean { return q.options.some((o) => o.value === v); }","tryCatchPattern":"try { await submit(p, answers); } catch (e) { if ((e as Error & { code?: string }).code === 'question_invalid_answer' && /not in the option schema/.test((e as Error).message)) { await remapValuesFromFreshSchema(); return submit(p, answers); } throw e; }","preventionTips":["Map UI labels to schema values at submit time","Refresh the question schema before submitting long-lived forms"],"tags":["validation","option-schema","question-invalid-answer"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}