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

  1. Validate 0 <= questionIndex < interaction.payload.questions.length before calling publishPhotonPrompt
  2. Iterate with interaction.payload.questions.map/forEach so the index is always in bounds
  3. 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

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


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).payload

View on GitHub (pinned to 3f1d897a7c)