fix(ui): unblock ask_user promise when Stop is clicked (fixes #183)#411
Open
octo-patch wants to merge 1 commit intoalibaba:mainfrom
Open
fix(ui): unblock ask_user promise when Stop is clicked (fixes #183)#411octo-patch wants to merge 1 commit intoalibaba:mainfrom
octo-patch wants to merge 1 commit intoalibaba:mainfrom
Conversation
…#183) When the agent invokes the ask_user tool and the user clicks Stop before answering, the promise returned by Panel.#askUser() was never resolved or rejected. The LLM layer awaits tool execution before checking the abort signal, so the execute() loop stayed permanently blocked with status='running', leaving the panel stuck on the stop button with no way to close it. Fix: introduce #cancelUserAnswer() which rejects the pending promise with an AbortError-shaped error. The LLM layer recognises this as a non-retryable user abort, propagates it to the execute() catch block, and calls #onDone(false), transitioning status to 'error'. The panel button then changes to X and the user can close it normally. Also cancel any pending promise in Panel.dispose() to prevent memory leaks when the agent is disposed while waiting for user input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #183
Problem
When the agent invokes the
ask_usertool and the user clicks Stop before typing an answer, the panel becomes permanently stuck:Panel.#askUser()returns aPromiseand stores only itsresolvecallback.OpenAIClient)awaitstool.execute(), which in turnawaitsonAskUser()— without passing the abort signal to that inner await.agent.stop()→abortController.abort(), which cancels the outgoing HTTP request but has no effect on an already-running tool execution.execute()stays blocked atawait tool.execute()withstatus = 'running'forever.Solution
Introduce
#cancelUserAnswer()which rejects the pending#askUserpromise with an AbortError-shaped error (error.name = 'AbortError').The LLM retry layer already checks
rawError.name === 'AbortError'to skip retries for user aborts, so the error propagates immediately toexecute()'s catch block →#onDone(false)→status = 'error'. The panel button then becomes X, allowing the user to close it.Changes in
packages/ui/src/panel/Panel.ts:#userAnswerRejecterfield alongside the existing#userAnswerResolver.rejectin#askUser().#cancelUserAnswer()— rejects the promise, clears state, and removes temporary question cards from the history panel.#cancelUserAnswer()in#handleActionButton()beforeagent.stop()when#isWaitingForUserAnsweris true.#cancelUserAnswer()indispose()(after removing event listeners) to prevent memory leaks if the agent is disposed while waiting for user input.#userAnswerRejecterinreset()and#handleUserAnswer().Testing
ask_usertool (e.g. configure the agent so the LLM asks a clarifying question).