Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the entire chat request is cancellable #433

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

makenneth
Copy link
Contributor

@makenneth makenneth commented Aug 23, 2024

Description

The main goal of this PR is to make entire chat request cancellable. Currently, if user cancels before the response streaming starts, the request will still go through. For the fqn piece, we can use Workerpool's "cancel" feature. Otherwise, we just need to early terminate and return a ResponseError with RequestCancelled code.

I tried to make this reusable by creating a wrapper function that creates a promise for cancellation that will "race" against the core logic: the value that is resolved first will be returned.

The other two changes:

  • Combined DocumentContext and TriggerContext into a single TriggerContextExtractor as the separation offer no benefits
  • Removed unneeded start trigger information

Testing

  • Regression test in VS ✅
  • Also tested the end chat flow with temporary UI implementation (not included in this PR)
    • Cancelling during FQN execution ✅
    • Cancelling during outgoing request ✅
    • Cancelling during response streaming ✅

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@makenneth makenneth requested review from a team as code owners August 23, 2024 20:56
@@ -54,26 +55,40 @@ export function registerChat(languageClient: LanguageClient, extensionUri: Uri,
languageClient.info(`vscode client: Received ${JSON.stringify(message)} from chat`)

switch (message.command) {
case END_CHAT_REQUEST_METHOD:
Copy link
Contributor

@ege0zcan ege0zcan Aug 28, 2024

Choose a reason for hiding this comment

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

i would expect this case to be already taken care of by the 'default' case, I think we can remove this specific case I see the default case doesn't send requests right now and only notifications, this comment can be ignored

@@ -35,14 +35,9 @@ interface MessageTrigger extends TriggerContext {
followUpActions?: Set<string>
}

interface StartTrigger {
triggerType?: TriggerType
hasUserSnippet?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean we never logged hasUserSnippet field anywhere so we won't be logging it going forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC currently we are not using hasUserSnippet from the start trigger but from message trigger. (But it could be a mistake since Q would have the snippet if the first request has it.)

this.#log('Response for conversationId:', conversationIdentifier, JSON.stringify(response.$metadata))
} catch (err) {
if (isObject(err) && 'name' in err && err.name === 'AbortError') {
throw new CancellationError('Q api request aborted')
Copy link
Contributor

Choose a reason for hiding this comment

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

here and down below, why do we throw cancellation error instead of returning an error object like we do in other error scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an upstream error handling in withLspCancellation. I guess we should probably do one of the other

@ege0zcan
Copy link
Contributor

ege0zcan commented Sep 9, 2024

Important

I tested this change locally and it works, the changes in this PR LGTM.
However currently the backend doesn't support cancellations and returns an improperly formed request error when you cancel a request and make a new request on the same chat afterwards. Therefore we should not merge this PR until we know the backend is capable of handling this case

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.

2 participants