Skip to content

Review and consolidate 'ask' tool implementations - response handler mismatch causes spinner hang #197

@shuv1337

Description

@shuv1337

Problem

When using the ask tool with a freeform text prompt, submitting a response does not complete the tool - the active spinner continues indefinitely until the user aborts.

This appears to be caused by having two separate ask tool implementations with different response mechanisms:

  1. ask tool (packages/opencode/src/tool/ask.ts) - Uses TuiEvent.QuestionRequest/QuestionResponse bus events
  2. askquestion tool (packages/opencode/src/tool/askquestion.ts) - Uses AskQuestion.register/respond with HTTP endpoints

The TUI has handlers for both systems, but they're wired to different UI components and response flows.

Current State

Tool 1: ask (ask.ts:285-380)

  • Schema: Supports select, multi-select, confirm, text question types
  • Trigger: Publishes TuiEvent.QuestionRequest via Bus.publish()
  • Response: Listens for TuiEvent.QuestionResponse via Bus.subscribe()
  • UI: Uses DialogQuestion component (app.tsx:555) - opened as overlay dialog

Tool 2: askquestion (askquestion.ts:7-80)

  • Schema: Uses AskQuestion.QuestionSchema with id, label, question, options fields
  • Trigger: Calls AskQuestion.register()
  • Response: HTTP POST to /askquestion/respond endpoint
  • UI: Uses DialogAskQuestion component (session/index.tsx:1428) - inline in session view

The Mismatch

  • DialogQuestion (for ask tool) publishes response via SDK client: sdk.client.tui.publish()
  • DialogAskQuestion (for askquestion tool) posts to HTTP endpoint: fetch(\${sdk.url}/askquestion/respond`)`

When the ask tool's DialogQuestion is shown with a text question, the response is published via SDK events, but the tool is waiting for TuiEvent.QuestionResponse via the Bus - and these may not be connecting properly.

Acceptance Criteria

  • Only one user-facing ask tool exists and works reliably
  • Text/freeform input questions work correctly without spinner hang
  • All question types (select, multi-select, confirm, text) function properly
  • Response submission completes the tool and returns output to the LLM
  • Cleanup of any dead code from the deprecated implementation

Investigation Tasks

  • Trace why TuiEvent.QuestionResponse doesn't reach the ask tool's Bus subscription
  • Determine which implementation is intended to be the "current" one (likely askquestion based on recent merges)
  • Check if ask tool should be removed or if both serve different purposes
  • Verify server-side event routing between SDK client and Bus

Relevant Files

File Purpose
packages/opencode/src/tool/ask.ts Original ask tool using Bus events
packages/opencode/src/tool/askquestion.ts New askquestion tool using HTTP endpoints
packages/opencode/src/askquestion/index.ts AskQuestion namespace with register/respond
packages/opencode/src/question/index.ts Question schemas for ask tool
packages/opencode/src/cli/cmd/tui/app.tsx:550-597 QuestionRequest handler for ask tool
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx:1426-1461 DialogAskQuestion for askquestion tool
packages/opencode/src/cli/cmd/tui/ui/dialog-askquestion.tsx Wizard UI for askquestion
packages/opencode/src/cli/cmd/tui/component/dialog-question/ Dialog UI for ask tool
packages/opencode/src/tool/registry.ts:96,110 Both tools registered

Git History Context

a1c9fec1c feat: merge upstream PR #5958 askquestion tool (replaces #5563)
3a23fec31 feat(askquestion): fix race condition and improve TUI UX
7ff537213 fix: ask tool schema validation and bash carriage return handling
36a1f210e feat: add Ask tool for collecting user input via dialogs

The commit message "replaces anomalyco#5563" suggests askquestion was intended to replace the original ask tool, but both remain registered.

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