Skip to content

Commit f9d4a62

Browse files
committed
fix(chat): hide completed sessions from picker
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4f0e93ff-d320-454d-b00a-865dac727d0c
1 parent 8e79ace commit f9d4a62

6 files changed

Lines changed: 84 additions & 4 deletions

File tree

‎src/OpenClaw.Chat/ChatModels.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum ChatThreadStatus
44
{
55
Created,
66
Running,
7-
Suspended
7+
Suspended,
8+
Completed
89
}
910

1011
public enum ChatActivity

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6016,7 +6016,7 @@ private static ChatThread ToThread(SessionInfo s, string title)
60166016
{
60176017
Id = s.Key ?? string.Empty,
60186018
Title = title,
6019-
Status = ChatThreadStatus.Running,
6019+
Status = SessionVisibilityFilter.ToChatThreadStatus(s),
60206020
Activity = string.IsNullOrEmpty(s.CurrentActivity) ? ChatActivity.Idle : ChatActivity.Working,
60216021
Workspace = s.Channel,
60226022
Model = s.Model,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ Element BuildLoadingElement()
532532
// Session list for the composer dropdown — grouped by agent, keyed by
533533
// ID so every session gets its own entry regardless of display name.
534534
// Exclude cron sessions which are automated/background.
535-
var channelGroups = snapshot.Threads
535+
var channelGroups = SessionVisibilityFilter.VisibleChatPickerThreads(snapshot.Threads)
536536
.Where(t => !string.IsNullOrEmpty(t.Title)
537537
&& !t.Id.Contains(":cron:", StringComparison.Ordinal))
538538
.GroupBy(t =>
@@ -560,7 +560,9 @@ Element BuildLoadingElement()
560560
// the slot/session-instance within that agent. When the key
561561
// doesn't match this layout we fall back to a generic "Main"
562562
// label rather than mis-parsing some other id shape.
563-
if (effectiveThread is not null && !ChannelGroupsContain(channelGroups, effectiveThread.Id))
563+
if (effectiveThread is not null
564+
&& SessionVisibilityFilter.IsVisibleInChatPicker(effectiveThread)
565+
&& !ChannelGroupsContain(channelGroups, effectiveThread.Id))
564566
{
565567
var parts = (effectiveThread.Id ?? "").Split(':');
566568
var agentId = parts.Length >= 3 && parts[0] == "agent" ? parts[1] : "main";

‎src/OpenClaw.Tray.WinUI/Services/SessionVisibilityFilter.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using OpenClaw.Chat;
12
using OpenClaw.Shared;
23

34
namespace OpenClawTray.Services;
@@ -20,6 +21,15 @@ public static bool IsCleanCompleted(SessionInfo session)
2021
|| string.Equals(status, "completed", StringComparison.OrdinalIgnoreCase);
2122
}
2223

24+
public static ChatThreadStatus ToChatThreadStatus(SessionInfo session)
25+
=> IsCleanCompleted(session) ? ChatThreadStatus.Completed : ChatThreadStatus.Running;
26+
27+
public static IEnumerable<ChatThread> VisibleChatPickerThreads(IEnumerable<ChatThread> threads)
28+
=> threads.Where(IsVisibleInChatPicker);
29+
30+
public static bool IsVisibleInChatPicker(ChatThread thread)
31+
=> thread.Status != ChatThreadStatus.Completed;
32+
2333
public static string ResolveActiveChannel(string activeChannel, IEnumerable<string> visibleChannels)
2434
{
2535
if (!string.Equals(activeChannel, "all", StringComparison.OrdinalIgnoreCase)

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,36 @@ public async Task LoadAsync_ReturnsSeededSessionsAsThreads()
575575
Assert.True(snapshot.Timelines.ContainsKey("main"));
576576
}
577577

578+
[Fact]
579+
public async Task LoadAsync_MapsOnlyCleanCompletedSessionsToCompletedThreads()
580+
{
581+
var sessions = new[]
582+
{
583+
new SessionInfo { Key = "done", DisplayName = "Done", Status = "done" },
584+
new SessionInfo
585+
{
586+
Key = "aborted",
587+
DisplayName = "Aborted",
588+
Status = "done",
589+
AbortedLastRun = true,
590+
},
591+
new SessionInfo { Key = "unknown", DisplayName = "Unknown", Status = "unknown" },
592+
};
593+
var (_, provider, _, _) = CreateProvider(sessions);
594+
595+
var snapshot = await provider.LoadAsync();
596+
597+
Assert.Equal(
598+
ChatThreadStatus.Completed,
599+
Assert.Single(snapshot.Threads, thread => thread.Id == "done").Status);
600+
Assert.Equal(
601+
ChatThreadStatus.Running,
602+
Assert.Single(snapshot.Threads, thread => thread.Id == "aborted").Status);
603+
Assert.Equal(
604+
ChatThreadStatus.Running,
605+
Assert.Single(snapshot.Threads, thread => thread.Id == "unknown").Status);
606+
}
607+
578608
[Fact]
579609
public async Task LoadAsync_DistinguishesDuplicateMultiSegmentSessionTitles()
580610
{

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using OpenClaw.Chat;
12
using OpenClaw.Shared;
23
using OpenClawTray.Services;
34

@@ -80,6 +81,42 @@ public void VisibleSessions_ShowCompletedPreservesAllSessions()
8081
Assert.Equal(new[] { "done", "failed" }, visible);
8182
}
8283

84+
[Theory]
85+
[InlineData("done", false, ChatThreadStatus.Completed)]
86+
[InlineData("completed", false, ChatThreadStatus.Completed)]
87+
[InlineData("done", true, ChatThreadStatus.Running)]
88+
[InlineData("unknown", false, ChatThreadStatus.Running)]
89+
public void ToChatThreadStatus_ReusesCleanCompletionSemantics(
90+
string status,
91+
bool abortedLastRun,
92+
ChatThreadStatus expected)
93+
{
94+
var session = new SessionInfo
95+
{
96+
Status = status,
97+
AbortedLastRun = abortedLastRun,
98+
};
99+
100+
Assert.Equal(expected, SessionVisibilityFilter.ToChatThreadStatus(session));
101+
}
102+
103+
[Fact]
104+
public void VisibleChatPickerThreads_HidesCompletedThreads()
105+
{
106+
var threads = new[]
107+
{
108+
new ChatThread { Id = "running", Title = "Running", Status = ChatThreadStatus.Running },
109+
new ChatThread { Id = "completed", Title = "Completed", Status = ChatThreadStatus.Completed },
110+
new ChatThread { Id = "suspended", Title = "Suspended", Status = ChatThreadStatus.Suspended },
111+
};
112+
113+
var visible = SessionVisibilityFilter.VisibleChatPickerThreads(threads)
114+
.Select(thread => thread.Id)
115+
.ToArray();
116+
117+
Assert.Equal(new[] { "running", "suspended" }, visible);
118+
}
119+
83120
[Theory]
84121
[InlineData("all", "all")]
85122
[InlineData("Slack", "Slack")]

0 commit comments

Comments
 (0)