Skip to content

feat(site/src/pages/AgentsPage): collapse the question dock and keep focus in the chat - #31372

Closed
ibetitsmike wants to merge 160 commits into
mike/codagt-1460-question-dockfrom
mike/codagt-1460-question-focus
Closed

ibetitsmike wants to merge 160 commits into
mike/codagt-1460-question-dockfrom
mike/codagt-1460-question-focus

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Xum opened this PR for Mike.

Stack

This stack lets the agent in Coder Agents web UI chats ask a question with ask_user_question without ending its turn (CODAGT-1460).

  1. feat: let web UI chats ask questions without ending the turn #31310: chatd exposes the async tool to web UI chats and sends a web push.
  2. feat(site/src/pages/AgentsPage): show async question answers without their call line #31315: the web UI shows async answers without their call line.
  3. feat(site/src): answer async agent questions in the timeline while the agent works #31294: the web UI answers async questions, plus docs.
  4. feat: pin the open async question above the chat input #31312: pins the open async question above the chat input.
  5. feat(site/src/pages/AgentsPage): collapse the question dock and keep focus in the chat #31372 (this PR): keeps keyboard focus in the chat when a question form closes, and reworks the question form (Skip, an always-visible Other field, saved drafts).
  6. feat(site/src/pages/AgentsPage): show ask_user_question options as numbered one-line answers #31555: shows the options as numbered one-line answers that number keys can pick.

Refs CODAGT-1460

Why

Two review threads on #31294 and #31312 found two cases where focus falls to the page body, so the next Tab starts from the top of the page:

  • After Submit on a screen narrower than 640 px. The chat input moves focus back to itself after every send, except on narrow screens, where it stays put so the on-screen keyboard does not open. An answered question form closes, so focus had nowhere to go. Every question card on main does the same.
  • When a newer async question replaces the open question panel while focus is in the old form.

What changes (site/src/pages/AgentsPage)

  • Sending an answer, from the panel or from a question card, moves focus to the chat input on every screen size once the send succeeds. On narrow screens this opens the on-screen keyboard, which is the intended trade: the user can type at once, and focus does not fall to the page body. On narrow screens, a failed send leaves the form open with its error and does not move focus to the chat input, and if the user clicks anywhere or moves focus while the answer sends, focus stays where they put it. Leaving the window during the send does not stop the refocus, because focus() only sets the page's focused element and cannot take focus from the address bar or another window. Composer sends keep their narrow-screen behavior.
    • useComposerFocusAfterSend wraps the answer's send and focuses the chat input in an effect once the send succeeds. The focus cannot happen right after the request, because the editor is disabled while the send is pending and accepts focus only in the commit that enables it again.
  • When a newer question replaces the panel while focus is inside it, the "Open question" region takes focus instead of the page body: screen readers announce "Open question", and the next Tab reaches the new form. Focus anywhere else, including the page body, stays where it is. The region shows an inset focus ring, which the new AsyncQuestionDockFocused story captures.
    • AskUserQuestionDock now stays mounted across questions and keys only its inner section, by call ID and start time as before, so each question still gets a fresh draft and starts scrolled to the top. The section's ref cleanup records whether the section held focus: React detaches a ref before it removes the node, so the replaced section still contains the focused element at that point. The new section's ref then takes the focus when it finds focus on the page body, as MessageAttachmentCard does on main.
  • The question panel drops its "Open question" header, and the region keeps "Open question" as its accessible name. The whole header row of the panel collapses it to one "X/Y questions answered" line and expands it again; the draft survives collapsing, and a newer question always opens expanded.
  • The question form, in the panel and in question cards:
    • The question text, option descriptions, and the answered "Asked" list render Markdown with Response, as the transcript does. An option's description sits beside its label rather than inside it, because Markdown links and copy buttons must not nest in a label, so clicking the description no longer selects the option.
    • The header is a small grey label with an icon ("Question 2 of 6 · Database"), and the question text sits on its own line in larger, bold text.
    • The "Other" text field is always visible. Clicking or typing in it selects Other; tabbing through it does not change the choice.
    • A Skip button answers the current question with "Skipped" and moves to the next one. On the last question, or a single question, it sends at once.
    • The options lose their bordered box and inner scroll area. In the panel, the form grows to fit the question and scrolls only past 60% of the screen height, with Back, Next, Submit, and Skip pinned at the bottom.
  • questionDraft.ts saves the unsent answers and the current step in local storage, keyed by call ID and start time together with the questions they answer. A reload or a navigation restores them; a successful send, or the answer showing in the chat, removes them. A draft for a question that closed without an answer stays, because a history edit can reopen it.

Tests

  • AskUserQuestionTool.test.tsx: Other is selected from its field but not when Tab passes through; a skipped question sends as "Skipped", and skipping the last question sends at once; an unsent draft is restored after a remount and removed once the answer sends or the question shows an answer.
  • questionDraft.test.ts: a draft reads back only for the same questions, and malformed drafts are ignored.
  • AgentChatPage.test.tsx: on a narrow viewport, answering from the panel with the keyboard leaves focus in the chat input; a failed send does not move focus there; and focus that the user moved during the send, to another control or by a click on the page background, stays there.
  • ChatPageContent.test.tsx: the existing replacement test (new and reused call ID) now also checks that the panel holds focus, and a new test checks that focus on a control outside the panel, or on the page body, stays put when a newer question arrives.
  • ChatPageContent.test.tsx: collapsing and expanding the panel keeps the chosen option for Submit; it fails when the panel remounts the form on collapse. The new AsyncQuestionDockCollapsed story captures the collapsed line.
  • The new assertions fail without the production change. The page-body case fails when the dock moves focus whenever it finds focus on the page body, the failure and moved-focus tests fail when the hook refocuses after every settled send, and the page-background click case fails when the hook treats page-body focus as dropped by the form.
  • Remote dogfood UAT with a real model, run before the question form changes, with the earlier code as the control:
    • Round 9 passed on 7441fdd, with feat: pin the open async question above the chat input #31312's head as the control. After a keyboard or pointer Submit at 390x844 and 1440x900, and from a plan-mode question card, focus was in the chat input; the control left it on the page body at 390x844. A newer question that replaced the panel while focus was on an option moved focus to the "Open question" region, and typing in the chat input kept focus and text.
    • Round 10 passed on fadf637, with round 9's head as the control. At 390x844, a forced 500 kept the form open with its error, and focus did not go to the chat input; a retry stored the answer and focused the chat input. Also at 390x844, when the user moved focus to "Edit message", or clicked transcript text or empty transcript space, while a held send was pending, focus stayed there; the control moved it to the chat input. Focus on the page body stayed there when a newer question arrived.

Known follow-up (not in this PR)

  • On screens 640 px and wider, the chat input refocuses itself after every send, as on main, so a failed answer or a focus move during the send still ends with focus in the chat input there.
  • When the open question disappears without the user's own action, for example because it was answered from another tab, focus inside the panel still falls to the page body.
  • After a failed send, focus that was on Submit stays on the page body, because the form disables its controls while the answer sends. Question cards on main behave the same.
  • The chats sidebar shows an idle chat with an open async question as Idle. Flagging it needs server data, because the chat list does not say that a question is open.

…he turn

In chats created from the web UI, ask_user_question is now available
outside plan mode. The call returns at once with async: true, the agent
keeps working, and chatd sends the chat owner a web push. The UI keeps
the question answerable while the agent runs, sends the answer as a user
message that names the tool call, and shows superseded questions as
closed. API chats and plan mode keep today's behavior.
…l call ID

Address frontend review: branch on async instead of an empty prefix,
recognize a prefixed answer even when a queued message lands first,
replace the attribute-asserting test with a story for the blocking
while-running state, and add stories for answered async questions.
…ions open

A question still in the live stream is now the latest question, so it
does not render as closed before its step persists and the persisted
question it supersedes does. Also share one spelling of the async
answer prefix and read each user message's text once.
…pers to a module

The async answer format is shared by the question component and the
conversation timeline, so it lives in its own module.
…ching

Nest the answer lookup under one guard, tighten the helper docs, and
reuse the shared question fixture in the live-stream story.
…until answered

An async ask_user_question is now answered only by a user message whose
first line names its call, and closed only by a newer valid question.
Unrelated messages and failed calls no longer close it. A queued answer
counts as the answer, so a reload or another tab does not offer the
question again, and removing that answer from the queue reopens it.
User bubbles and queue rows show the answer without the call ID line.
…nc answer handling

Move ask_user_question result parsing next to parseArgs, reuse the async
check in Tool.tsx, rename the answered-question prop and helpers to say
what they track, build story fixtures from getAsyncAnswerPrefix, and
tighten comments.
…ixtures and docs

Share text part concatenation with getEditableUserMessagePayload, add a
story for a question left open by an unrelated message, replace a story
that duplicated the answered state with a getAsyncAnswerText test, and
trim comments that restated code.
…async answer

Cover the timeline state where the answer to an async question waits in
the queue, and tighten three comments.
…ers at the timeline boundary

Move the running-chat async answer test from the Tool renderer to
ConversationTimeline, where it also covers the unrelated-message
regression and the tool call ID plumbing through MessageBlocks.
…c-ask-user-question

# Conflicts:
#	site/src/pages/AgentsPage/components/ChatPageContent.tsx
Copy and Edit on a delivered async answer exposed the hidden
'Answer to ask_user_question call <id>:' line. Copy now uses the answer
body, and Edit shows the body and restores the line on send so the
answer stays tied to its question. Also moves the answer submission
state into useAnswerSubmission, drops a comment that restated a field,
and records webpush mock messages before bumping the dispatch count.
… failed edit

The history-edit rollback now restores the answer prefix line with the
rest of the edit snapshot. Also moves the answer submission state back
into AskUserQuestionTool, because FE3 disallows a one-consumer hook
that component state can express.
The async ask_user_question tool sent its web push from inside the
tool run, before the step that holds the result committed. A failed
commit left the user with a push for a question the UI never showed,
and a re-run after a retryable failure pushed the same question again.

chatd now reads the async question from the step's tool results and
sends the push from afterGenerationOutcome once the step commits. A
fail-closed commit sends only the error push, and a step that asks more
than once pushes only the last question, the one the UI offers.
…smallest result budget

chatloop truncates a tool result longer than its byte budget into
invalid JSON, which hid the async marker from the UI and the question
push. Async results now fail validation above the smallest budget, so
the model shortens them instead.
… call they name

Providers choose tool call IDs, and chatd stores them raw, so the answer
prefix parser now accepts any ID on the first line, spaces included. An
answer to an earlier async call no longer closes a newer plan mode
question; only an ordinary message or one that names that call does.
…he turn

Expose ask_user_question outside plan mode for chats created from the
web UI. Outside plan mode the tool returns at once, the turn keeps
running, and the answer arrives later as a user message that names the
tool call. API-created chats keep the tool in plan mode only.
Adds stories for a two-question async dock advanced to its second step and for a blocking question that stays inline, renames the read-only story to an archived chat, defaults the story page height, and trims JSDoc on the dock, showsStreamOutput, and createPreferenceSeededQueryClient.
…m without the transcript card

The dock rendered AskUserQuestionTool, the transcript card, and turned the
card's own behavior off: it passed isLatestAskUserQuestion, silenced the
announcement with announcesQuestion={false}, and reached the questions
through the exported AskUserQuestionRenderer.

AskUserQuestionForm now owns the answers, the wizard, the send, and the
answered view. The card keeps the error, running, closed, and docked
states, the announcement, and the async call ID: it strips the answer's
prefix line and adds it to the answer it sends. The dock renders the form
directly with getAskUserQuestions, so announcesQuestion and the exported
renderer go away.
…r sender

The card already wraps its send in a named function that adds the async
prefix line; the dock now does the same instead of an inline ternary
lambda.
…turn the result's questions when the args have none

Once the args have no questions, the old fallback chain could only
return an empty list or the result's questions, so getAskUserQuestions
now returns the parsed result or an empty list, and parses the result
only when it needs it. The card also gets blank lines between its steps.
…prefix in the question form

The card and the dock each wrapped the form's send to add the async
answer's prefix line, and each stripped that line before passing the
answer in, so the form's previousResponseText and onSubmitAnswer carried
other text than the card's props with the same names. The form now takes
asyncToolCallId and handles the prefix line in both directions, and
getAnswerBody replaces getAsyncAnswerBody so the card and the form share
the same check.

Also from the frontend review: showSubmittedAnswer is required and named
like other boolean props, getAskUserQuestions parses the result itself,
the docked notice takes precedence explicitly, the card's running header
is written once, and the announcement comment says why its live region
renders early.
…dy the question form after review

From the second frontend review round: the form and the card document
what they own, getAnswerBody's doc names the argument that passes text
through, both question lists build their keys with getQuestionKey, and
the asked-question text drops an id that nothing reads, so the card no
longer needs useId. getAnswerBody gets unit tests for each case.
…line the asked-question row

From the third frontend review round: AskedQuestions renders its rows
itself, since it was the only caller of AnsweredQuestionText. The form's
docs state the async contract once, and the getAnswerBody tests name the
expected result and cover a message without the prefix line.
…when the question form is read-only

The dock keeps passing onSubmitAnswer while its answer waits in the
queue, so the prop doc now says the form is also read-only once it shows
an answer. getAskUserQuestions' doc names its empty-list result.
…nd answer

- The question label ("Question 2 of 6 · Header") is a small header, and
  the question text sits on its own line in a larger, bolder font. The
  options lose their border box.
- The "Other" field is always visible. Clicking it or typing in it
  selects "Other"; tabbing through it keeps the chosen option.
- A Skip button answers the current question with "Skipped" and moves
  on, or sends the answers on the last question.
- In the question panel, the label is a header button that collapses
  and expands the whole panel.
- Unsent answers and the current question are saved in localStorage
  per call until a send succeeds.
- The panel grows to show the whole question instead of scrolling
  inside a 50vh box; it scrolls only past 60vh.
…ew of the question form changes

- Key the inline card's draft by call ID and start time, as the dock does.
- Extract the panel header into QuestionPanelHeader and inline the label.
- Tighten the draft types and reuse asRecord and parseJSON in questionDraft.
- Move the new keyboard checks from story play functions into Vitest.
- Restore "questions answered" in the collapsed header; trim comments.
… scroll and clear answered drafts

- Key the dock's scroller by call, so a newer question starts at the top.
- Remove a saved draft once the form shows any answer, including one sent
  as a chat message.
- Name the radio group by the question label and text.
- Compare saved questions with isEqual, and cover a Skip on the last question.
…can no longer be sent

- A closed async question removes its saved draft.
- Type the restored drafts, keep focused options clear of the sticky
  actions with scroll padding, and test the draft removal on an answer.
…raft

A history edit can reopen a closed question, so its saved draft stays
until the form shows an answer. Also rename getDraftKey to
getQuestionCallKey, since the dock keys its panel by it too.
…ment on the scroller

Also document the empty selection of a question draft.
…Markdown in ask_user_question forms

Agents write question text and option descriptions in Markdown
(headings, tables, bold, code), which the form showed as raw source.
Render them with Response, as the transcript does.
…tion descriptions out of the radio label

A Markdown description can hold links and copy buttons, which must not
nest inside the option's label, so the description now sits beside the
label and describes the radio. Stories show Markdown in the open form
and in the answered list; the Markdown unit test is dropped in favor
of them.
… the question focus assertions

A substring match also passes when focus falls to the page body.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

🤖 Xum posted this comment for Mike.

Closing: the stack was reshaped into five layers, and this PR's changes (collapsing the question dock and returning focus to the chat input after an answer) now live in #31312.

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2026
mafredri pushed a commit that referenced this pull request Nov 3, 2026
The agent keeps working after an async question, so its transcript
card scrolls away under new output. While the question is open, its
answer form moves to a collapsible panel above the chat input, and
sending an answer returns focus to the chat input.

This is the net change of mike/codagt-1460-question-dock at
c455707, collapsed into one commit to rebase it onto main without
replaying the merges from the layer below. It includes the focus
handling from the closed #31372.
mafredri pushed a commit that referenced this pull request Nov 6, 2026
The agent keeps working after an async question, so its transcript
card scrolls away under new output. While the question is open, its
answer form moves to a collapsible panel above the chat input, and
sending an answer returns focus to the chat input.

This is the net change of mike/codagt-1460-question-dock at
c455707, collapsed into one commit to rebase it onto main without
replaying the merges from the layer below. It includes the focus
handling from the closed #31372.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant