Skip to content

AskQuestion tool broken - dialog not appearing in TUI or Web #240

@shuv1337

Description

@shuv1337

Problem

The askquestion tool is invoked correctly by the LLM, but the dialog/wizard UI does not appear in either the TUI or Web interface. The tool call registers and the metadata is set with status: "waiting", but users never see the question wizard.

This regression appears to have occurred during a recent upstream merge (likely v1.0.220-v1.0.222 sync).

Symptoms

  • LLM calls askquestion tool with valid questions
  • Tool state shows status: "running" with metadata.status: "waiting"
  • No dialog appears in TUI (DialogAskQuestion)
  • No wizard appears in Web (AskQuestionWizard)
  • Tool call eventually times out or hangs indefinitely

Technical Context

How AskQuestion Works

  1. Tool invocation (packages/opencode/src/tool/askquestion.ts:19-46):

    • Sets metadata with status: "waiting" and questions array
    • Registers pending request with AskQuestion.register()
    • Awaits promise resolution from user response
  2. State synchronization:

    • Part updates flow via message.part.updated events
    • Web: packages/app/src/context/global-sync.tsx:330-349
    • TUI: packages/opencode/src/cli/cmd/tui/context/sync.tsx:213+
  3. UI detection logic:

    • Web: packages/app/src/pages/session.tsx:162-198 - pendingAskQuestion() memo
    • TUI: packages/opencode/src/cli/cmd/tui/routes/session/index.tsx:402-429 - pendingAskQuestionFromSync() memo
  4. UI rendering:

    • Web: packages/app/src/pages/session.tsx:858-865 - AskQuestionWizard in Switch/Match
    • TUI: packages/opencode/src/cli/cmd/tui/routes/session/index.tsx:1572-1608 - DialogAskQuestion in Switch/Match

Potential Root Causes

  1. Reactivity issue: The createMemo detecting pending questions may not be reactive to state changes
  2. Event propagation: message.part.updated events may not be reaching the UI layer
  3. Sync timing: Part metadata may not be populated when the memo evaluates
  4. Switch/Match ordering: SolidJS Switch/Match may be evaluating conditions incorrectly

Detection Logic (Web)

// packages/app/src/pages/session.tsx:162-198
const pendingAskQuestion = createMemo(() => {
  const sessionID = params.id
  if (!sessionID) return null

  const sessionMessages = sync.data.message[sessionID] ?? []

  for (const message of [...sessionMessages].reverse()) {
    const parts = sync.data.part[message.id] ?? []

    for (const part of [...parts].reverse()) {
      if (part.type !== "tool") continue
      const toolPart = part as ToolPart

      if (toolPart.tool !== "askquestion") continue
      if (toolPart.state.status !== "running") continue

      const metadata = toolPart.state.metadata as { status?: string; questions?: AskQuestionQuestion[] } | undefined
      if (metadata?.status !== "waiting") continue

      const questions = (metadata.questions ?? []) as AskQuestionQuestion[]
      if (questions.length === 0) continue

      return { callID: toolPart.callID, messageID: toolPart.messageID, questions }
    }
  }
  return null
})

Acceptance Criteria

  • AskQuestion dialog appears in TUI when tool is called
  • AskQuestionWizard appears in Web when tool is called
  • User can interact with the wizard (select options, submit, cancel)
  • Answers are properly sent back to the tool via /askquestion/respond
  • Tool completes with formatted user responses

Investigation Steps

  1. Verify event propagation:

    • Add console logs to global-sync.tsx:330 to confirm message.part.updated events arrive
    • Check if part metadata contains status: "waiting" and questions array
  2. Check memo reactivity:

    • Add debug logging inside pendingAskQuestion() memo
    • Verify sync.data.message and sync.data.part are populated
  3. Test Switch/Match rendering:

    • Temporarily replace <Match when={pendingAskQuestion()}> with a hardcoded condition
    • Check if the wizard component renders at all
  4. Compare TUI vs Web:

    • TUI may have different sync timing - check if TUI has same issue
    • If only Web is broken, focus on packages/app context

Related Files

  • packages/opencode/src/tool/askquestion.ts - Tool definition
  • packages/opencode/src/askquestion/index.ts - Core module with bus events and pending request management
  • packages/app/src/pages/session.tsx - Web session page with wizard rendering
  • packages/app/src/components/askquestion-wizard.tsx - Web wizard component
  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx - TUI session with dialog rendering
  • packages/opencode/src/cli/cmd/tui/ui/dialog-askquestion.tsx - TUI dialog component
  • packages/app/src/context/global-sync.tsx - Web event handling
  • packages/opencode/src/cli/cmd/tui/context/sync.tsx - TUI event handling

Configuration Note

The askquestion tool is behind an experimental flag:

// packages/opencode/src/tool/registry.ts:110
...(config.experimental?.askquestion_tool === true ? [AskQuestionTool] : [])

Ensure experimental.askquestion_tool: true is set in config when testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions