Yeachan-Heo/oh-my-codex · error
${path}[${mismatchIndex}] must match the selected value labe
Error message
${path}[${mismatchIndex}] must match the selected value label What it means
assertSelectedLabelsMatch compares each selected_labels[i] against the label the schema expects for selected_values[i]. On the first index where they differ it throws with that index, pinpointing the misaligned label.
Source
Thrown at src/question/state.ts:335
return selectedValues.map((value) => {
const optionLabel = optionLabelsByValue.get(value);
if (optionLabel) return optionLabel;
if (question.allow_other && otherText && value === otherText) return question.other_label;
throw new Error(`selected value is not in the option schema: ${value}`);
});
}
function assertSelectedLabelsMatch(
selectedLabels: string[],
expectedLabels: string[],
path: string,
): void {
if (selectedLabels.length !== expectedLabels.length) {
throw new Error(`${path} cardinality must match selected values`);
}
const mismatchIndex = selectedLabels.findIndex((label, index) => label !== expectedLabels[index]);
if (mismatchIndex !== -1) {
throw new Error(`${path}[${mismatchIndex}] must match the selected value label`);
}
}
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),
};
}View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Derive labels from the current question schema at submit time rather than caching them
- When appending/removing a selection, update both arrays together (derive labels from values)
Example fix
// before answer.selected_labels = cachedLabels; // stale/order mismatch // after answer.selected_labels = answer.selected_values.map((v) => question.options.find((o) => o.value === v)!.label);
Defensive patterns
Strategy: validation
Validate before calling
const expected = answer.selected_values.map((v) => question.options.find((o) => o.value === v)?.label ?? question.other_label); if (expected.some((l, i) => l !== answer.selected_labels[i])) answer.selected_labels = expected;
Type guard
function labelsMatchSchema(q: NormalizedQuestionItem, values: string[], labels: string[]): boolean {
return values.every((v, i) => labels[i] === (q.options.find((o) => o.value === v)?.label ?? q.other_label));
} Try / catch
try { await submit(p, answers); } catch (e) { const m = /answers\[\d+\]\.answer\.selected_labels\[(\d+)\] must match/.exec((e as Error).message); if (m) { fixLabelAt(+m[1]); return submit(p, answers); } throw e; } Prevention
- Compute labels at submit time from the live schema, not cached render state
- Keep values and labels updated as one atomic pair
When it happens
Trigger: selected_labels[i] does not equal question option label (or other_label for other answers) for the value at the same index; e.g. reordered values without reordering labels, or outdated label text after schema localization changes.
Common situations: Reordering one array but not the other; stale cached labels after the question's labels were updated; localization mismatch between client and server label text.
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
- ${path} cardinality must match selected values
- ${path} must be a non-empty string array
- selected value is not in the option schema: ${value}
- answers[${entry.index}].question_id is unknown for this ques
- answers[${entry.index}].answer.kind=other is not allowed for
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/bd42871cfa49f7eb.
Report an issue: GitHub.