paperclipai/paperclip · error · PhotonAnswerValidationError
Photon question index is invalid
Error message
Photon question index is invalid
What it means
PhotonAnswerValidationError thrown from publishPhotonPrompt when the interaction is kind 'ask_user_questions' but the provided questionIndex has no matching question in payload.questions. Publishing a numbered sub-prompt requires a valid question index.
Solutions
- Validate 0 <= questionIndex < interaction.payload.questions.length before calling publishPhotonPrompt
- Iterate with interaction.payload.questions.map/forEach so the index is always in bounds
- Refetch the interaction payload before publishing to avoid stale counts
Example fix
// before for (let i = 0; i <= questions.length; i++) await publishPhotonPrompt(adapter, key, interaction, i); // after for (let i = 0; i < interaction.payload.questions.length; i++) await publishPhotonPrompt(adapter, key, interaction, i);
Defensive patterns
Strategy: validation
Validate before calling
const valid = interaction.kind === 'ask_user_questions' && Number.isInteger(questionIndex) && questionIndex >= 0 && questionIndex < interaction.payload.questions.length;
Type guard
const questionAt = (ia: PhotonInteraction, i: number) => ia.kind === 'ask_user_questions' ? ia.payload.questions[i] ?? null : null;
Try / catch
try { await publishPhotonPrompt(adapter, key, interaction, questionIndex); } catch (e) { if (e instanceof PhotonAnswerValidationError && /question index is invalid/.test(e.message)) return refetchInteraction(); throw e; } Prevention
- Iterate questions with forEach/map so indices stay in bounds
- Refetch the interaction payload before publishing sub-prompts
- Use 0-based indices consistently in publisher code
When it happens
Trigger: Calling publishPhotonPrompt with questionIndex pointing past the end of (or before the start of) interaction.payload.questions for an ask_user_questions interaction.
Common situations: A loop over questions uses a stale count after the payload was trimmed; 1-based vs 0-based indexing bug; the question was removed between listing and publishing its prompt.
Related errors
- That question does not exist
- A full lowercase source SHA is required.
- A reusable lease cannot be replaced and reacquired in the…
- A reusable lease handoff requires an execution workspace…
- A safe, unique --revision is required
AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-09-18).
Data as JSON: /api/errors/9ec2436e5e54b9ef.
Report an issue: GitHub.
Appendix: source
Thrown at server/src/services/photon/interactions.ts:197
existing.promptMessageGuid,
])
await adapter.state.update<PhotonPromptReceipt>(
`prompt-message:${guid}`,
(current) => current ?? existing,
);
if (existing.pollMessageGuid)
await adapter.state.update<PhotonPromptReceipt>(
`poll-message:${existing.pollMessageGuid}`,
(current) => current ?? existing,
);
return existing;
}
const question =
interaction.kind === "ask_user_questions"
? interaction.payload.questions[questionIndex]
: null;
if (interaction.kind === "ask_user_questions" && !question)
throw new PhotonAnswerValidationError("Photon question index is invalid");
const reference = `${binding.reference}.${questionIndex + 1}`;
const title =
projectSafeChatPublicationText(
question?.prompt ??
(interaction as RequestConfirmationInteraction).payload.prompt,
).trim() || "Input needed";
const choices = question
? question.options.map((option) => ({
id: option.id,
label:
projectSafeChatPublicationText(option.label).trim() ||
`Choice ${question.options.indexOf(option) + 1}`,
}))
: [
{
id: "accept",
label: projectSafeChatPublicationText(
(interaction as RequestConfirmationInteraction).payloadView on GitHub (pinned to 3f1d897a7c)