-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Cancel completed host tool invocations across SDKs #2509
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
Merged
+2,507
−68
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
571126c
Cancel host tool invocations on completion
stephentoub 40921e0
Merge main and address cancellation review feedback
stephentoub 3acb399
Fix cancellation CI validation
stephentoub 718d470
Merge main and fix cleanup CI failures
stephentoub 9045ec3
Address cancellation cleanup alerts
stephentoub b6ac7f4
test: add cross-sdk external tool cancellation e2e
SteveSandersonMS 245cb0c
Fix external tool cancellation E2E validation
stephentoub ca73ddb
test: fix java e2e formatting for spotless
SteveSandersonMS 98db8c2
Narrow connection cleanup exception handling
stephentoub ca9dc79
Merge origin/main into external tool cancellation
stephentoub 3b7e09e
Merge origin/main into external tool cancellation
stephentoub ee560e4
Fix Java close cancellation test after detach migration
stephentoub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| using Microsoft.Extensions.AI; | ||
| using System.ComponentModel; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace GitHub.Copilot.Test.E2E; | ||
|
|
||
| public class ExternalToolCancellationE2ETests(E2ETestFixture fixture, ITestOutputHelper output) | ||
| : E2ETestBase(fixture, "external_tool_cancellation", output) | ||
| { | ||
| [Fact] | ||
| public async Task Should_Cancel_Tool_Handler_When_Session_Disposes() | ||
| { | ||
| var toolStarted = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| var toolCancelled = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| var releaseTool = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| var session = await CreateSessionAsync(new SessionConfig | ||
| { | ||
| Tools = [AIFunctionFactory.Create(SlowTool, "slow_analysis")], | ||
| OnPermissionRequest = PermissionHandler.ApproveAll, | ||
| }); | ||
|
|
||
| _ = session.SendAsync(new MessageOptions | ||
| { | ||
| Prompt = "Use slow_analysis with value 'test_abort'. Wait for the result.", | ||
| }); | ||
|
|
||
| var startedValue = await toolStarted.Task.WaitAsync(TimeSpan.FromSeconds(60)); | ||
| Assert.Equal("test_abort", startedValue); | ||
|
|
||
| await session.DisposeAsync(); | ||
| await toolCancelled.Task.WaitAsync(TimeSpan.FromSeconds(60)); | ||
|
|
||
| releaseTool.TrySetResult("RELEASED"); | ||
|
|
||
| [Description("A slow analysis tool that blocks until released")] | ||
| async Task<string> SlowTool([Description("Value to analyze")] string value, CancellationToken cancellationToken) | ||
| { | ||
| toolStarted.TrySetResult(value); | ||
| try | ||
| { | ||
| var completed = await Task.WhenAny(releaseTool.Task, Task.Delay(Timeout.Infinite, cancellationToken)); | ||
| if (completed == releaseTool.Task) | ||
| { | ||
| return await releaseTool.Task; | ||
| } | ||
|
|
||
| throw new OperationCanceledException(cancellationToken); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| toolCancelled.TrySetResult(true); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.