Yeachan-Heo/oh-my-codex · error

answers[${entry.index}].question_id is unknown for this ques

Error message

answers[${entry.index}].question_id is unknown for this question: ${entry.question_id}

What it means

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.

Source

Thrown at src/question/state.ts:354

  }
}

function questionForAnswer(record: QuestionRecord, entry: QuestionAnswerEntry): NormalizedQuestionItem {
  const question = (record.questions ?? []).find((item) => item.id === entry.question_id);
  if (question) return question;
  if (entry.question_id === 'q-1') {
    return {
      id: 'q-1',
      ...(record.header ? { header: record.header } : {}),
      question: record.question,
      options: record.options,
      allow_other: record.allow_other,
      other_label: record.other_label,
      multi_select: record.multi_select,
      type: getNormalizedQuestionType(record),
    };
  }
  throw new Error(`answers[${entry.index}].question_id is unknown for this question: ${entry.question_id}`);
}

function validateAnswerAgainstQuestion(question: NormalizedQuestionItem, entry: QuestionAnswerEntry): void {
  const { answer } = entry;
  const selectedValues = validateStringArray(answer.selected_values, `answers[${entry.index}].answer.selected_values`);
  const selectedLabels = validateStringArray(answer.selected_labels, `answers[${entry.index}].answer.selected_labels`);
  assertNoDuplicateValues(selectedValues, `answers[${entry.index}].answer.selected_values`);

  const optionValues = new Set(question.options.map((option) => option.value));
  const multi = isMultiAnswerableQuestion(question);
  const hasOtherText = typeof answer.other_text === 'string' && answer.other_text.trim().length > 0;
  const otherText = hasOtherText ? answer.other_text!.trim() : undefined;
  const outOfSchemaValues = selectedValues.filter((value) => !optionValues.has(value));

  if (answer.kind === 'other') {
    if (!question.allow_other) throw new Error(`answers[${entry.index}].answer.kind=other is not allowed for this question`);
    if (multi) throw new Error(`answers[${entry.index}].answer.kind=other is only valid for single-answerable questions`);
    if (!otherText) throw new Error(`answers[${entry.index}].answer.other_text must be a non-empty string`);

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Re-fetch the record and use its current question ids when building answers
  2. Confirm you are submitting to the same recordPath the questions came from
  3. Check for exact id match (whitespace/case) between entry.question_id and record question ids

Example fix

// before
entry.question_id = savedForm.questionId; // from an older record version
// after
const record = await readQuestionRecord(recordPath);
entry.question_id = record!.questions![0]!.id; // current id
Defensive patterns

Strategy: validation

Validate before calling

const validIds = new Set([...(record.questions ?? []).map((q) => q.id), record.id].filter(Boolean));
if (!answers.every((a) => validIds.has(a.question_id))) throw new Error('answer references unknown question');

Type guard

function isKnownQuestionId(record: QuestionRecord, id: string): boolean {
  return (record.questions ?? []).some((q) => q.id === id) || id === record.id;
}

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/8a25cc6b06858bef. Report an issue: GitHub.