Skip to content

Commit efda812

Browse files
shanselmanCopilot
andcommitted
fix(chat): restore default reasoning effort
Co-authored-by: Copilot App <[email protected]>
1 parent 1955282 commit efda812

15 files changed

Lines changed: 192 additions & 42 deletions

‎src/OpenClaw.Chat/ChatModels.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ Task SendMessageAsync(string threadId, string message, CancellationToken cancell
362362
/// </summary>
363363
Task ClearModelAsync(string threadId, CancellationToken cancellationToken = default) => Task.CompletedTask;
364364
Task SetThinkingLevelAsync(string threadId, string thinkingLevel, CancellationToken cancellationToken = default);
365+
/// <summary>
366+
/// Clears the session's explicit thinking-level override so the gateway can
367+
/// restore its provider default. Distinct from <see cref="SetThinkingLevelAsync"/>
368+
/// because the gateway models this as an explicit null.
369+
/// </summary>
370+
Task ClearThinkingLevelAsync(string threadId, CancellationToken cancellationToken = default) => Task.CompletedTask;
365371
Task SetPermissionModeAsync(string threadId, bool allowAll, CancellationToken cancellationToken = default);
366372
Task RespondToPermissionAsync(string threadId, string requestId, string action, CancellationToken cancellationToken = default);
367373
Task RespondToPermissionAsync(string threadId, string requestId, bool allow, CancellationToken cancellationToken = default) =>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ public void SetThinkingLevel(string level)
318318
FireAndForget(_ => _port.SetThinkingLevelAsync(threadId, level, _lifetimeToken));
319319
}
320320

321+
public void ClearThinkingLevel()
322+
{
323+
if (_disposed)
324+
return;
325+
if (_vm.Inputs?.CurrentThread.Id is not { } threadId)
326+
return;
327+
328+
FireAndForget(_ => _port.ClearThinkingLevelAsync(threadId, _lifetimeToken));
329+
}
330+
321331
/// <summary>Requests a command-catalog refresh. Assigns a monotonic operation ID
322332
/// and threads the shared lifetime token so the outstanding request is actually
323333
/// canceled on dispose. Refreshed results flow back only through the root's

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ public async Task SetThinkingLevelAsync(string threadId, string thinkingLevel, C
8989
catch (Exception ex) { System.Diagnostics.Trace.WriteLine($"[chat] operation failed: {ex}"); }
9090
}
9191

92+
public async Task ClearThinkingLevelAsync(string threadId, CancellationToken cancellationToken)
93+
{
94+
try { await provider.ClearThinkingLevelAsync(threadId, cancellationToken).ConfigureAwait(true); }
95+
catch (OperationCanceledException) { }
96+
catch (Exception ex) { System.Diagnostics.Trace.WriteLine($"[chat] operation failed: {ex}"); }
97+
}
98+
9299
public async Task EnsureCommandCatalogAsync(CancellationToken cancellationToken)
93100
{
94101
try { await provider.EnsureCommandCatalogAsync(cancellationToken).ConfigureAwait(true); }

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,22 +392,22 @@ internal ChatDataSnapshot ApplyModels(
392392
}
393393
}
394394

395-
internal ChatModelPatchLease BeginModelPatch(string threadId)
395+
internal ChatSessionOptionPatchLease BeginSessionOptionPatch(string threadId)
396396
{
397397
lock (_gate)
398-
return _presentation.BeginModelPatch(threadId);
398+
return _presentation.BeginSessionOptionPatch(threadId);
399399
}
400400

401-
internal void CompleteModelPatch(ChatModelPatchLease lease, Exception? error)
401+
internal void CompleteSessionOptionPatch(ChatSessionOptionPatchLease lease, Exception? error)
402402
{
403403
lock (_gate)
404-
_presentation.CompleteModelPatch(lease, error);
404+
_presentation.CompleteSessionOptionPatch(lease, error);
405405
}
406406

407-
internal Task? GetPendingModelPatch(string threadId)
407+
internal Task? GetPendingSessionOptionPatch(string threadId)
408408
{
409409
lock (_gate)
410-
return _presentation.GetPendingModelPatch(threadId);
410+
return _presentation.GetPendingSessionOptionPatch(threadId);
411411
}
412412

413413
internal bool TryBeginCommandCatalogFetch(out int epoch)

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ internal sealed record ChatUsageSnapshot(
1111
long ContextTokens);
1212

1313
/// <summary>
14-
/// Owns session/model/catalog presentation inputs, serialized model patches,
14+
/// Owns session/model/catalog presentation inputs, serialized session-option patches,
1515
/// keyless diagnostics, and remembered chat selection. The root serializes
1616
/// every operation and supplies immutable timeline/queue snapshots.
1717
/// </summary>
1818
internal sealed class ChatPresentationState
1919
{
20-
private readonly Dictionary<string, Task> _pendingModelPatches = new();
20+
private readonly Dictionary<string, Task> _pendingSessionOptionPatches = new();
2121

2222
private SessionInfo[] _sessions = [];
2323
private bool _sessionsListReceived;
@@ -150,33 +150,33 @@ internal void LeaveConnected()
150150
_commandsFetchInFlight = false;
151151
}
152152

153-
internal ChatModelPatchLease BeginModelPatch(string threadId)
153+
internal ChatSessionOptionPatchLease BeginSessionOptionPatch(string threadId)
154154
{
155-
_pendingModelPatches.TryGetValue(threadId, out var previous);
155+
_pendingSessionOptionPatches.TryGetValue(threadId, out var previous);
156156
var completion = new TaskCompletionSource(
157157
TaskCreationOptions.RunContinuationsAsynchronously);
158-
_pendingModelPatches[threadId] = completion.Task;
158+
_pendingSessionOptionPatches[threadId] = completion.Task;
159159
return new(threadId, previous, completion);
160160
}
161161

162-
internal void CompleteModelPatch(
163-
ChatModelPatchLease lease,
162+
internal void CompleteSessionOptionPatch(
163+
ChatSessionOptionPatchLease lease,
164164
Exception? error)
165165
{
166166
if (error is null)
167167
lease.Completion.TrySetResult();
168168
else
169169
lease.Completion.TrySetException(error);
170170

171-
if (_pendingModelPatches.TryGetValue(lease.ThreadId, out var current) &&
171+
if (_pendingSessionOptionPatches.TryGetValue(lease.ThreadId, out var current) &&
172172
ReferenceEquals(current, lease.Completion.Task))
173173
{
174-
_pendingModelPatches.Remove(lease.ThreadId);
174+
_pendingSessionOptionPatches.Remove(lease.ThreadId);
175175
}
176176
}
177177

178-
internal Task? GetPendingModelPatch(string threadId) =>
179-
_pendingModelPatches.TryGetValue(threadId, out var pending)
178+
internal Task? GetPendingSessionOptionPatch(string threadId) =>
179+
_pendingSessionOptionPatches.TryGetValue(threadId, out var pending)
180180
? pending
181181
: null;
182182

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ internal sealed record ChatSendPreparation(
136136
bool IsCurrent,
137137
ChatDataSnapshot? Snapshot);
138138

139-
internal sealed record ChatModelPatchLease(
139+
internal sealed record ChatSessionOptionPatchLease(
140140
string ThreadId,
141141
Task? Previous,
142142
TaskCompletionSource Completion);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ Task<bool> SendMessageAsync(
3737

3838
Task SetThinkingLevelAsync(string threadId, string thinkingLevel, CancellationToken cancellationToken);
3939

40+
Task ClearThinkingLevelAsync(string threadId, CancellationToken cancellationToken);
41+
4042
Task EnsureCommandCatalogAsync(CancellationToken cancellationToken);
4143
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Task<SessionCompactResult> CompactSessionDetailedAsync(string sessionKey) =>
7979
/// </summary>
8080
Task ClearSessionModelAsync(string sessionKey);
8181
Task PatchSessionThinkingLevelAsync(string sessionKey, string thinkingLevel);
82+
/// <summary>
83+
/// Clears the session's thinking-level override with an explicit JSON null,
84+
/// restoring the gateway/provider default.
85+
/// </summary>
86+
Task ClearSessionThinkingLevelAsync(string sessionKey);
8287
Task<ChatHistoryInfo> RequestChatHistoryAsync(string? sessionKey);
8388
Task<AssistantMediaResolutionResult> ResolveAssistantMediaAsync(
8489
string sessionKey,
@@ -219,6 +224,9 @@ public Task ClearSessionModelAsync(string sessionKey) =>
219224
public Task PatchSessionThinkingLevelAsync(string sessionKey, string thinkingLevel) =>
220225
_client.PatchSessionAsync(sessionKey, new SessionPatch { ThinkingLevel = thinkingLevel });
221226

227+
public Task ClearSessionThinkingLevelAsync(string sessionKey) =>
228+
_client.PatchSessionAsync(sessionKey, new SessionPatch { ThinkingLevel = SessionPatch.Clear });
229+
222230
public Task<CommandCatalog> ListCommandsAsync(CommandCatalogQuery? query = null) =>
223231
_client.ListCommandsAsync(query);
224232

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ await DispatchQueuedLifecycleCommandAsync(
403403

404404
try
405405
{
406-
await AwaitPendingModelPatchAsync(threadId, cancellationToken);
406+
await AwaitPendingSessionOptionPatchAsync(threadId, cancellationToken);
407407
var preparation = _state.PrepareSendAttempt(
408408
dispatch,
409409
ProjectionContext());
@@ -761,20 +761,20 @@ public async Task SetModelAsync(string threadId, string model, CancellationToken
761761
// string; a blank value here is a no-op rather than a clear. Use
762762
// ClearModelAsync to revert a session to the gateway default.
763763
if (string.IsNullOrWhiteSpace(model)) return;
764-
await TrackModelPatchAsync(threadId, () => _bridge.PatchSessionModelAsync(threadId, model));
764+
await TrackSessionOptionPatchAsync(threadId, () => _bridge.PatchSessionModelAsync(threadId, model));
765765
}
766766

767767
public async Task ClearModelAsync(string threadId, CancellationToken cancellationToken = default)
768768
{
769769
cancellationToken.ThrowIfCancellationRequested();
770770
// Tri-state clear: removes the session's model override (explicit null)
771771
// so it tracks the gateway/agent default again.
772-
await TrackModelPatchAsync(threadId, () => _bridge.ClearSessionModelAsync(threadId));
772+
await TrackSessionOptionPatchAsync(threadId, () => _bridge.ClearSessionModelAsync(threadId));
773773
}
774774

775-
private async Task TrackModelPatchAsync(string threadId, Func<Task> patchOperation)
775+
private async Task TrackSessionOptionPatchAsync(string threadId, Func<Task> patchOperation)
776776
{
777-
var lease = _state.BeginModelPatch(threadId);
777+
var lease = _state.BeginSessionOptionPatch(threadId);
778778
Exception? failure = null;
779779
try
780780
{
@@ -783,7 +783,7 @@ private async Task TrackModelPatchAsync(string threadId, Func<Task> patchOperati
783783
try { await lease.Previous; }
784784
catch (Exception ex)
785785
{
786-
Logger.Debug($"ChatDataProvider: continuing model patch after previous patch failed: {ex.Message}");
786+
Logger.Debug($"ChatDataProvider: continuing session option patch after previous patch failed: {ex.Message}");
787787
}
788788
}
789789
await patchOperation();
@@ -795,28 +795,38 @@ private async Task TrackModelPatchAsync(string threadId, Func<Task> patchOperati
795795
}
796796
finally
797797
{
798-
_state.CompleteModelPatch(lease, failure);
798+
_state.CompleteSessionOptionPatch(lease, failure);
799799
}
800800
}
801801

802-
private async Task AwaitPendingModelPatchAsync(string threadId, CancellationToken cancellationToken)
802+
private async Task AwaitPendingSessionOptionPatchAsync(string threadId, CancellationToken cancellationToken)
803803
{
804-
var pending = _state.GetPendingModelPatch(threadId);
804+
var pending = _state.GetPendingSessionOptionPatch(threadId);
805805
if (pending is not null)
806806
{
807807
try { await pending.WaitAsync(cancellationToken); }
808808
catch (OperationCanceledException) { throw; }
809809
catch (Exception ex)
810810
{
811-
Logger.Debug($"ChatDataProvider: continuing send after model patch failed: {ex.Message}");
811+
Logger.Debug($"ChatDataProvider: continuing send after session option patch failed: {ex.Message}");
812812
}
813813
}
814814
}
815815

816816
public async Task SetThinkingLevelAsync(string threadId, string thinkingLevel, CancellationToken cancellationToken = default)
817817
{
818818
cancellationToken.ThrowIfCancellationRequested();
819-
await _bridge.PatchSessionThinkingLevelAsync(threadId, thinkingLevel);
819+
await TrackSessionOptionPatchAsync(
820+
threadId,
821+
() => _bridge.PatchSessionThinkingLevelAsync(threadId, thinkingLevel));
822+
}
823+
824+
public async Task ClearThinkingLevelAsync(string threadId, CancellationToken cancellationToken = default)
825+
{
826+
cancellationToken.ThrowIfCancellationRequested();
827+
await TrackSessionOptionPatchAsync(
828+
threadId,
829+
() => _bridge.ClearSessionThinkingLevelAsync(threadId));
820830
}
821831

822832
public async Task EnsureCommandCatalogAsync(CancellationToken cancellationToken = default)

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,21 @@ void Send()
139139
.Select(model => new ChatModelChoice(model, model))
140140
.ToArray();
141141
var selectableModels = modelChoices.Where(model => model.IsSelectable).ToArray();
142-
var modelNames = new[] { Localized("Chat_Composer_Reasoning_Default", "Default") }
142+
var defaultReasoningLabel = Localized("Chat_Composer_Reasoning_Default", "Default");
143+
var modelNames = new[] { defaultReasoningLabel }
143144
.Concat(selectableModels.Select(ChatModelLabels.BuildMenuLabel))
144145
.ToArray();
145146
var modelIndex = string.IsNullOrWhiteSpace(inputs.CurrentThread.Model)
146147
? 0
147148
: Math.Max(0, Array.FindIndex(
148149
selectableModels,
149150
model => model.MatchesModel(inputs.CurrentThread.Model, inputs.CurrentThread.ModelProvider)) + 1);
150-
var thinkingIndex = Math.Max(0, Array.IndexOf(
151-
ThinkingLevels,
152-
inputs.CurrentThread.ThinkingLevel ?? "medium"));
151+
var thinkingIndex = string.IsNullOrWhiteSpace(inputs.CurrentThread.ThinkingLevel)
152+
? 0
153+
: Math.Max(0, Array.IndexOf(ThinkingLevels, inputs.CurrentThread.ThinkingLevel) + 1);
154+
var thinkingNames = new[] { defaultReasoningLabel }
155+
.Concat(ThinkingLevels)
156+
.ToArray();
153157
var actionLabel = inputs.TurnActive
154158
? Localized("Chat_Composer_Tooltip_Stop", "Stop")
155159
: Localized("Chat_Composer_Tooltip_Send", "Send");
@@ -575,7 +579,7 @@ Element PickerButton(
575579
.ToArray());
576580

577581
var modelPickerLabel = modelIndex == 0
578-
? Localized("Chat_Composer_Reasoning_Default", "Default")
582+
? defaultReasoningLabel
579583
: selectableModels[modelIndex - 1].DisplayName;
580584
var modelPicker = MenuFlyout(
581585
PickerButton(
@@ -600,17 +604,23 @@ Element PickerButton(
600604

601605
var reasoningPicker = MenuFlyout(
602606
PickerButton(
603-
ThinkingLevels[thinkingIndex],
604-
$"{Localized("Chat_Composer_Accessibility_Reasoning", "Reasoning")}: {ThinkingLevels[thinkingIndex]}",
607+
thinkingNames[thinkingIndex],
608+
$"{Localized("Chat_Composer_Accessibility_Reasoning", "Reasoning")}: {thinkingNames[thinkingIndex]}",
605609
"ChatComposerReasoningPicker",
606610
!inputs.MessageOptionsDisabled,
607611
props.IsCompact ? 54 : 96),
608-
ThinkingLevels
612+
thinkingNames
609613
.Select((level, index) => RadioMenuItem(
610614
level,
611615
"chat-thinking-level",
612616
index == thinkingIndex,
613-
() => controller.SetThinkingLevel(level)))
617+
() =>
618+
{
619+
if (index == 0)
620+
controller.ClearThinkingLevel();
621+
else
622+
controller.SetThinkingLevel(ThinkingLevels[index - 1]);
623+
}))
614624
.ToArray());
615625

616626
var attachButton = IconButton(

0 commit comments

Comments
 (0)