{"record":{"id":"8a25cc6b06858bef","repo":"Yeachan-Heo/oh-my-codex","slug":"answers-entry-index-question-id-is-unknown-for","errorCode":null,"errorMessage":"answers[${entry.index}].question_id is unknown for this question: ${entry.question_id}","messagePattern":"answers\\[(.+?)\\]\\.question_id is unknown for this question: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/question/state.ts","lineNumber":354,"sourceCode":"  }\n}\n\nfunction questionForAnswer(record: QuestionRecord, entry: QuestionAnswerEntry): NormalizedQuestionItem {\n  const question = (record.questions ?? []).find((item) => item.id === entry.question_id);\n  if (question) return question;\n  if (entry.question_id === 'q-1') {\n    return {\n      id: 'q-1',\n      ...(record.header ? { header: record.header } : {}),\n      question: record.question,\n      options: record.options,\n      allow_other: record.allow_other,\n      other_label: record.other_label,\n      multi_select: record.multi_select,\n      type: getNormalizedQuestionType(record),\n    };\n  }\n  throw new Error(`answers[${entry.index}].question_id is unknown for this question: ${entry.question_id}`);\n}\n\nfunction validateAnswerAgainstQuestion(question: NormalizedQuestionItem, entry: QuestionAnswerEntry): void {\n  const { answer } = entry;\n  const selectedValues = validateStringArray(answer.selected_values, `answers[${entry.index}].answer.selected_values`);\n  const selectedLabels = validateStringArray(answer.selected_labels, `answers[${entry.index}].answer.selected_labels`);\n  assertNoDuplicateValues(selectedValues, `answers[${entry.index}].answer.selected_values`);\n\n  const optionValues = new Set(question.options.map((option) => option.value));\n  const multi = isMultiAnswerableQuestion(question);\n  const hasOtherText = typeof answer.other_text === 'string' && answer.other_text.trim().length > 0;\n  const otherText = hasOtherText ? answer.other_text!.trim() : undefined;\n  const outOfSchemaValues = selectedValues.filter((value) => !optionValues.has(value));\n\n  if (answer.kind === 'other') {\n    if (!question.allow_other) throw new Error(`answers[${entry.index}].answer.kind=other is not allowed for this question`);\n    if (multi) throw new Error(`answers[${entry.index}].answer.kind=other is only valid for single-answerable questions`);\n    if (!otherText) throw new Error(`answers[${entry.index}].answer.other_text must be a non-empty string`);","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/question/state.ts#L336-L372","documentation":"Each submitted answer entry must reference a question that exists in the record (by id), or the record's single-question fallback fields. questionForAnswer throws when entry.question_id matches none, meaning the answer is for a question the record never contained.","triggerScenarios":"Submitting answers with a question_id not present in record.questions and not matching the record-level question id/allow_other/etc. fallback; e.g. a stale client submitting against a regenerated record with new ids.","commonSituations":"Question schema regenerated (new ids) while a form was open; copy-pasted question_id typos; submitting answers from one record against another record's path; single-question records where the entry id differs from the record id.","solutions":["Re-fetch the record and use its current question ids when building answers","Confirm you are submitting to the same recordPath the questions came from","Check for exact id match (whitespace/case) between entry.question_id and record question ids"],"exampleFix":"// before\nentry.question_id = savedForm.questionId; // from an older record version\n// after\nconst record = await readQuestionRecord(recordPath);\nentry.question_id = record!.questions![0]!.id; // current id","handlingStrategy":"validation","validationCode":"const validIds = new Set([...(record.questions ?? []).map((q) => q.id), record.id].filter(Boolean));\nif (!answers.every((a) => validIds.has(a.question_id))) throw new Error('answer references unknown question');","typeGuard":"function isKnownQuestionId(record: QuestionRecord, id: string): boolean {\n  return (record.questions ?? []).some((q) => q.id === id) || id === record.id;\n}","tryCatchPattern":"try { await submit(p, answers); } catch (e) { if (/question_id is unknown/.test((e as Error).message)) { await refetchRecordAndRemapIds(p, answers); return submit(p, answers); } throw e; }","preventionTips":["Bind forms to the record instance they will be submitted against","Refetch the record if it may have been regenerated"],"tags":["validation","question-id","answers"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}