{"record":{"id":"f8f8e2da46e48773","repo":"Yeachan-Heo/oh-my-codex","slug":"selected-value-is-not-in-the-option-schema-valu","errorCode":null,"errorMessage":"selected value is not in the option schema: ${value}","messagePattern":"selected value is not in the option schema: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/question/state.ts","lineNumber":321,"sourceCode":"function assertNoDuplicateValues(values: string[], path: string): void {\n  const seen = new Set<string>();\n  for (const value of values) {\n    if (seen.has(value)) throw new Error(`${path} must not contain duplicate values: ${value}`);\n    seen.add(value);\n  }\n}\n\nfunction expectedSelectedLabelsForValues(\n  question: NormalizedQuestionItem,\n  selectedValues: string[],\n  otherText: string | undefined,\n): string[] {\n  const optionLabelsByValue = new Map(question.options.map((option) => [option.value, option.label]));\n  return selectedValues.map((value) => {\n    const optionLabel = optionLabelsByValue.get(value);\n    if (optionLabel) return optionLabel;\n    if (question.allow_other && otherText && value === otherText) return question.other_label;\n    throw new Error(`selected value is not in the option schema: ${value}`);\n  });\n}\n\nfunction assertSelectedLabelsMatch(\n  selectedLabels: string[],\n  expectedLabels: string[],\n  path: string,\n): void {\n  if (selectedLabels.length !== expectedLabels.length) {\n    throw new Error(`${path} cardinality must match selected values`);\n  }\n  const mismatchIndex = selectedLabels.findIndex((label, index) => label !== expectedLabels[index]);\n  if (mismatchIndex !== -1) {\n    throw new Error(`${path}[${mismatchIndex}] must match the selected value label`);\n  }\n}\n\nfunction questionForAnswer(record: QuestionRecord, entry: QuestionAnswerEntry): NormalizedQuestionItem {","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/question/state.ts#L303-L339","documentation":"When deriving expected labels for submitted selected_values, each value must either match an option's value in the question schema or (when allow_other is set) equal the trimmed other_text. Any other value throws — the submitted value simply does not exist in the option schema.","triggerScenarios":"Submitting a value not present in question.options[].value and not equal to other_text when allow_other is true; e.g. sending a label instead of a value, or free text without allow_other.","commonSituations":"Confusing option label with option value (submitting 'Yes please' when value is 'yes'); stale client holding an old question schema after options changed server-side; sending other text on a question with allow_other disabled.","solutions":["Submit option.value (not label) exactly as defined in the question schema","If sending free text, verify question.allow_other is true and pass the same string as other_text, selected_values[0], and value","Refresh the question schema before submit if options may have changed"],"exampleFix":"// before\nanswer.selected_values = ['Yes please']; // label, not value\n// after\nanswer.selected_values = [question.options.find((o) => o.label === 'Yes please')!.value]; // 'yes'","handlingStrategy":"validation","validationCode":"const known = new Set(question.options.map((o) => o.value));\nconst ok = answer.selected_values.every((v) => known.has(v) || (question.allow_other && v === answer.other_text?.trim()));\nif (!ok) throw new Error('value not in option schema');","typeGuard":"function valueAllowed(q: NormalizedQuestionItem, v: string, otherText?: string): boolean {\n  return q.options.some((o) => o.value === v) || (!!q.allow_other && v === otherText?.trim());\n}","tryCatchPattern":"try { await submit(p, answers); } catch (e) { if (/selected value is not in the option schema/.test((e as Error).message)) { await refreshQuestionAndRemap(); return; } throw e; }","preventionTips":["Always submit option.value, never the label","Re-validate against a freshly fetched question schema before submit"],"tags":["validation","option-schema","answers"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}