Skip to content

Commit edf0c9e

Browse files
committed
fix(chat): observe composer send faults
Preserve the pre-extraction composer boundary by normalizing reset-confirmation and lifecycle failures to a rejected send instead of leaving a fire-and-forget task faulted. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 02754eab-8008-4859-8a80-9e6462133380
1 parent 89a9cee commit edf0c9e

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎src/OpenClaw.Tray.WinUI/Chat/ChatComposerController.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ public async Task<bool> SendAsync()
194194
_vm.SetSending(false);
195195
}
196196
}
197+
catch (OperationCanceledException)
198+
{
199+
return false;
200+
}
201+
catch (Exception ex)
202+
{
203+
System.Diagnostics.Trace.WriteLine($"[chat] composer send failed: {ex}");
204+
return false;
205+
}
197206
finally
198207
{
199208
// Released unconditionally — including on a throw from the snapshot/

‎tests/OpenClaw.Tray.Tests/ChatComposerControllerTests.cs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,40 @@ public async Task SendAsync_Reset_ConfirmationAccepted_Executes()
397397
Assert.Equal(ChatLifecycleCommandKind.Reset, port.LastLifecycleCall!.Value.Command);
398398
}
399399

400+
[Fact]
401+
public async Task SendAsync_Reset_ConfirmationFault_ReturnsFalseAndRestoresSendingState()
402+
{
403+
var actions = new ChatComposerHostActions(
404+
ConfirmResetAsync: (_, _) => Task.FromException<bool>(
405+
new InvalidOperationException("dialog failed")),
406+
null, null, null, null);
407+
var (vm, controller, port, _) = MakeController(actions);
408+
vm.SetDraft("/reset");
409+
410+
var accepted = await controller.SendAsync();
411+
412+
Assert.False(accepted);
413+
Assert.False(vm.IsSending);
414+
Assert.Equal("/reset", vm.Draft);
415+
Assert.Equal(0, port.ExecuteLifecycleCallCount);
416+
}
417+
418+
[Fact]
419+
public async Task SendAsync_LifecycleFault_ReturnsFalseAndRestoresSendingState()
420+
{
421+
var (vm, controller, port, _) = MakeController();
422+
vm.SetDraft("/new");
423+
port.ExecuteLifecycleGate = new TaskCompletionSource<ChatLifecycleCommandResult>();
424+
port.ExecuteLifecycleGate.SetException(new InvalidOperationException("lifecycle failed"));
425+
426+
var accepted = await controller.SendAsync();
427+
428+
Assert.False(accepted);
429+
Assert.False(vm.IsSending);
430+
Assert.Equal("/new", vm.Draft);
431+
Assert.Equal(1, port.ExecuteLifecycleCallCount);
432+
}
433+
400434
[Fact]
401435
public async Task SendAsync_Reset_DisposedWhileConfirmationDialogOpen_DoesNotExecute()
402436
{

0 commit comments

Comments
 (0)