Skip to content

fix(chat): submit AskUserQuestion answers keyed by question text#84

Open
hanifnr wants to merge 2 commits into
mainfrom
fix-interactive-input
Open

fix(chat): submit AskUserQuestion answers keyed by question text#84
hanifnr wants to merge 2 commits into
mainfrom
fix-interactive-input

Conversation

@hanifnr
Copy link
Copy Markdown
Collaborator

@hanifnr hanifnr commented May 15, 2026

Summary

  • Braid was sending AskUserQuestion answers keyed by q.header (the short chip label), but the Claude Agent SDK expects them keyed by q.question (the full question text — see AskUserQuestionOutput in @anthropic-ai/claude-agent-sdk: "question text -> answer string").
  • As a result, the SDK couldn't correlate the user's selections with the asked questions, and Claude effectively saw the answers as unreadable.
  • Fix: iterate pendingQuestion.questions and emit each answer under q.question. Drops the now-unnecessary header→question lookup and makes the "other" override precedence explicit.

Root cause

  • Schema (AskUserQuestionOutput.answers, sdk-tools.d.ts:2666): keys are question text → answer string.
  • SDK CLI uses answers[V.question] when rendering / formatting the tool result back to the model.
  • AskUserQuestionPrompt.tsx#handleSubmit previously keyed final by header, so the lookup failed silently downstream.

Test plan

  • Run a session and trigger AskUserQuestion with a single question — verify Claude correctly reads the chosen option.
  • Trigger AskUserQuestion with multiple questions — verify Claude correlates each answer with the right question.
  • Select the "Other" option and submit free-text — verify Claude reads the typed value.
  • Multi-select question: pick several options + Other (no text) — verify Claude reads the joined labels.
  • yarn test passes (pre-existing unrelated failures in lsp/helpers and useSwipeNavigation remain).

The Claude Agent SDK's AskUserQuestion tool expects the `answers` map
keyed by the full question text (see AskUserQuestionOutput in
@anthropic-ai/claude-agent-sdk: "question text -> answer string"). Braid
was sending answers keyed by `header` (the short chip label), so the SDK
could not correlate answers back to their questions and the model saw
the user's selections as unreadable.

Iterate over `pendingQuestion.questions` directly and write each answer
under `q.question`. This also drops the now-unnecessary header→question
lookup map and makes the "other" override precedence explicit.
@hanifnr hanifnr requested a review from gedeagas May 15, 2026 01:28
@hanifnr hanifnr self-assigned this May 15, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the handleSubmit function in AskUserQuestionPrompt.tsx to use question text as keys for the final output, ensuring compatibility with the SDK. The implementation was also changed to have free-text 'other' values override selections. Feedback suggests merging these values instead of overriding them to prevent potential data loss in multi-select scenarios.

Comment thread src/renderer/components/Center/AskUserQuestionPrompt.tsx
Previously the free-text "other" value replaced any selected labels, so a
multi-select user who picked "Option A" + "Other" with typed "Option B"
would lose "Option A". Single-select is unaffected because the UI
already replaces selections with `['__other__']` when "Other" is picked.
@hanifnr
Copy link
Copy Markdown
Collaborator Author

hanifnr commented May 15, 2026

@gemini-code-assist Thanks for the review. Addressed the data-loss concern in a77019c — multi-select labels and "other" free-text are now merged into a single comma-separated answer instead of overriding, matching multi-select semantics. Single-select behavior is unchanged because the UI replaces selections with ['__other__'] when Other is picked, so the merge degenerates to just the "other" text.

@gemini-code-assist
Copy link
Copy Markdown

Thanks for the update, @hanifnr. The logic in handleSubmit now correctly aligns with the AskUserQuestionOutput schema by using q.question as the key and merging multi-select labels with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant