-
Notifications
You must be signed in to change notification settings - Fork 893
[dotnet] Fix SendAndWaitAsync to throw OperationCanceledException on external cancellation #543
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
Changes from all commits
d0403cb
7d71db9
e2569eb
eeac5fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,6 +403,30 @@ public async Task SendAndWait_Throws_On_Timeout() | |
| Assert.Contains("timed out", ex.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SendAndWait_Throws_OperationCanceledException_When_Token_Cancelled() | ||
| { | ||
| var session = await Client.CreateSessionAsync(); | ||
|
|
||
| // Set up wait for tool execution to start BEFORE sending | ||
| var toolStartTask = TestHelper.GetNextEventOfTypeAsync<ToolExecutionStartEvent>(session); | ||
|
|
||
|
Comment on lines
+409
to
+413
|
||
| using var cts = new CancellationTokenSource(); | ||
|
|
||
| // Start SendAndWaitAsync - don't await it yet | ||
| var sendTask = session.SendAndWaitAsync( | ||
| new MessageOptions { Prompt = "run the shell command 'sleep 10' (note this works on both bash and PowerShell)" }, | ||
| cancellationToken: cts.Token); | ||
|
|
||
| // Wait for the tool to begin executing before cancelling | ||
| await toolStartTask; | ||
|
|
||
| // Cancel the token | ||
| cts.Cancel(); | ||
SteveSandersonMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await Assert.ThrowsAnyAsync<OperationCanceledException>(() => sendTask); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Should_Create_Session_With_Custom_Config_Dir() | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| models: | ||
| - claude-sonnet-4.5 | ||
| conversations: | ||
| - messages: | ||
| - role: system | ||
| content: ${system} | ||
| - role: user | ||
| content: run the shell command 'sleep 10' (note this works on both bash and PowerShell) | ||
| - role: assistant | ||
| content: I'll run the sleep command for you. | ||
| - role: assistant | ||
| tool_calls: | ||
| - id: toolcall_0 | ||
| type: function | ||
| function: | ||
| name: report_intent | ||
| arguments: '{"intent":"Running sleep command"}' | ||
| - role: assistant | ||
| tool_calls: | ||
| - id: toolcall_1 | ||
| type: function | ||
| function: | ||
| name: ${shell} | ||
| arguments: '{"command":"sleep 10","description":"Execute sleep 10 command","initial_wait":15,"mode":"sync"}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method name uses
Token_Cancelled(double-l). In .NET APIs and the rest of the framework, the standard spelling isCanceled(single-l), e.g.OperationCanceledException/CancellationToken. Consider renaming the test (and corresponding snapshot filename) to..._When_Token_Canceledfor consistency/searchability.