Skip to content

Commit 2f24393

Browse files
Disambiguate duplicate session titles
1 parent c8cd986 commit 2f24393

10 files changed

Lines changed: 707 additions & 67 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ jobs:
281281
# Accessibility Insights CI pass: scans each page in the real app process.
282282
- name: Run Accessibility Tests (Axe.Windows)
283283
id: a11y
284+
env:
285+
OPENCLAW_UI_PROOF_HEAD: ${{ github.event.pull_request.head.sha || github.sha }}
286+
OPENCLAW_UI_PROOF_PATH: ${{ github.workspace }}\TestResults\Accessibility\session-title-uia-proof.txt
287+
OPENCLAW_UI_SCREENSHOT_PATH: ${{ github.workspace }}\TestResults\Accessibility\session-title-proof.png
284288
run: >
285289
dotnet test tests/OpenClaw.Tray.UITests
286290
--no-build
@@ -296,14 +300,25 @@ jobs:
296300
shell: pwsh
297301
run: |
298302
if ("${{ steps.a11y.outcome }}" -eq "failure") {
299-
"### :x: Accessibility violations detected" >> $env:GITHUB_STEP_SUMMARY
303+
"### :x: Real-process UI or accessibility tests failed" >> $env:GITHUB_STEP_SUMMARY
300304
"" >> $env:GITHUB_STEP_SUMMARY
301-
"Axe.Windows scans found WCAG violations in one or more pages." >> $env:GITHUB_STEP_SUMMARY
305+
"A UI Automation behavior proof or Axe.Windows page scan failed." >> $env:GITHUB_STEP_SUMMARY
302306
"See the `Accessibility.trx` artifact for details." >> $env:GITHUB_STEP_SUMMARY
303307
} else {
304-
"### :white_check_mark: Accessibility scans passed" >> $env:GITHUB_STEP_SUMMARY
308+
"### :white_check_mark: Real-process UI and accessibility tests passed" >> $env:GITHUB_STEP_SUMMARY
305309
"" >> $env:GITHUB_STEP_SUMMARY
306-
"All pages passed Axe.Windows accessibility validation." >> $env:GITHUB_STEP_SUMMARY
310+
"All UI Automation behavior proofs and Axe.Windows page scans passed." >> $env:GITHUB_STEP_SUMMARY
311+
}
312+
313+
$proofPath = "TestResults\Accessibility\session-title-uia-proof.txt"
314+
if (Test-Path -LiteralPath $proofPath) {
315+
Write-Host "Session title UIA proof:"
316+
"" >> $env:GITHUB_STEP_SUMMARY
317+
"### Session title UIA proof" >> $env:GITHUB_STEP_SUMMARY
318+
Get-Content -LiteralPath $proofPath | ForEach-Object {
319+
Write-Host $_
320+
"- ``$_``" >> $env:GITHUB_STEP_SUMMARY
321+
}
307322
}
308323
309324
- name: Verify DevBuild identity marker

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

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ internal void RememberSelectedThread(string? threadId)
328328
state = new LastChatState
329329
{
330330
DefaultThreadId = threadId,
331-
ThreadTitle = BuildSessionTitle(session),
331+
ThreadTitle = SessionTitleFormatter.Format(session, _sessions),
332332
Model = session.Model,
333333
ModelProvider = session.Provider,
334334
AvailableModels = _availableModels,
@@ -5608,8 +5608,9 @@ private ChatDataSnapshot BuildSnapshotLocked()
56085608
// a usable composer even before the first session materializes server-
56095609
// side (e.g. fresh install with zero sessions).
56105610
var threadList = new List<ChatThread>(_sessions.Length + 1);
5611+
var threadTitles = SessionTitleFormatter.FormatUnique(_sessions);
56115612
for (int i = 0; i < _sessions.Length; i++)
5612-
threadList.Add(ToThread(_sessions[i]));
5613+
threadList.Add(ToThread(_sessions[i], threadTitles[i]));
56135614

56145615
var composeKey = _bridge.MainSessionKey;
56155616
var composeReady = _bridge.HasHandshakeSnapshot
@@ -5752,7 +5753,7 @@ private void RememberLastSessionStateLocked()
57525753
_lastChatState = new LastChatState
57535754
{
57545755
DefaultThreadId = session.Key,
5755-
ThreadTitle = BuildSessionTitle(session),
5756+
ThreadTitle = SessionTitleFormatter.Format(session, _sessions),
57565757
Model = session.Model,
57575758
ModelProvider = session.Provider,
57585759
AvailableModels = _availableModels,
@@ -5775,10 +5776,8 @@ private bool TryGetSessionLocked(string threadId, out SessionInfo session)
57755776
return false;
57765777
}
57775778

5778-
private static ChatThread ToThread(SessionInfo s)
5779+
private static ChatThread ToThread(SessionInfo s, string title)
57795780
{
5780-
var title = BuildSessionTitle(s);
5781-
57825781
return new ChatThread
57835782
{
57845783
Id = s.Key ?? string.Empty,
@@ -5798,40 +5797,6 @@ private static ChatThread ToThread(SessionInfo s)
57985797
};
57995798
}
58005799

5801-
/// <summary>
5802-
/// Builds a human-readable title from the session key and display name.
5803-
/// Keys follow the pattern agent:{agentId}:{sessionSlot} (e.g. agent:main:main, agent:assistant:main).
5804-
/// When a DisplayName is set, we append the agent/slot as a qualifier to disambiguate
5805-
/// sessions that share the same DisplayName.
5806-
/// </summary>
5807-
private static string BuildSessionTitle(SessionInfo s)
5808-
{
5809-
var baseName = !string.IsNullOrWhiteSpace(s.DisplayName)
5810-
? s.DisplayName!
5811-
: (s.IsMain ? "OpenClaw Windows Tray" : s.ShortKey);
5812-
5813-
// Parse agent:agentId:sessionSlot from the key
5814-
var parts = (s.Key ?? "").Split(':');
5815-
if (parts.Length >= 3 && parts[0] == "agent")
5816-
{
5817-
var agentId = parts[1]; // e.g. "main", "assistant"
5818-
var sessionSlot = parts[2]; // e.g. "main", "assistant", "cron"
5819-
5820-
// For the canonical main session (agent:main:main), just show the base name
5821-
if (agentId == "main" && sessionSlot == "main")
5822-
return baseName;
5823-
5824-
// Otherwise, qualify with agent/slot to distinguish
5825-
var qualifier = agentId == sessionSlot
5826-
? agentId // e.g. "assistant" when both match
5827-
: $"{agentId}/{sessionSlot}"; // e.g. "assistant/main"
5828-
5829-
return $"{baseName} ({qualifier})";
5830-
}
5831-
5832-
return baseName;
5833-
}
5834-
58355800
private static DateTimeOffset ToOffset(DateTime dt)
58365801
{
58375802
// SessionInfo.StartedAt/UpdatedAt arrive as DateTimeKind.Local or

‎src/OpenClaw.Tray.WinUI/Pages/ChatPage.xaml.cs‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ private void ShowFunctionalSurface()
334334

335335
private sealed class AccessibilityChatDataProvider : IChatDataProvider
336336
{
337-
private const string ThreadId = "accessibility-main";
337+
private const string DefaultThreadId = "accessibility-main";
338+
private const string MainThreadId = "agent:main:main";
339+
private const string ForkThreadId = "agent:main:fork";
338340
private static readonly ChatDataSnapshot Snapshot = CreateSnapshot();
339341

340342
public string DisplayName => "Accessibility test chat";
@@ -389,38 +391,58 @@ public Task RespondToPermissionAsync(
389391

390392
private static ChatDataSnapshot CreateSnapshot()
391393
{
392-
var timeline = ChatTimelineState.Initial() with
394+
static ChatTimelineState CreateTimeline(string id) => ChatTimelineState.Initial() with
393395
{
394396
Entries = ChatTimelineState.Initial().Entries
395397
.Add(new ChatTimelineItem(
396-
"accessibility-user",
398+
$"accessibility-user-{id}",
397399
ChatTimelineItemKind.User,
398400
"Verify the native chat surface."))
399401
.Add(new ChatTimelineItem(
400-
"accessibility-assistant",
402+
$"accessibility-assistant-{id}",
401403
ChatTimelineItemKind.Assistant,
402404
"The timeline and composer are ready.")),
403405
NextId = 3,
404406
HistoryLoaded = true,
405407
};
406408

407409
return new ChatDataSnapshot(
408-
[new ChatThread
409-
{
410-
Id = ThreadId,
411-
Title = "Accessibility session",
412-
Status = ChatThreadStatus.Running,
413-
Activity = ChatActivity.Idle,
414-
Model = "test-model",
415-
}],
410+
[
411+
new ChatThread
412+
{
413+
Id = DefaultThreadId,
414+
Title = "Accessibility session",
415+
Status = ChatThreadStatus.Running,
416+
Activity = ChatActivity.Idle,
417+
Model = "test-model",
418+
},
419+
new ChatThread
420+
{
421+
Id = MainThreadId,
422+
Title = $"Route target: {MainThreadId}",
423+
Status = ChatThreadStatus.Running,
424+
Activity = ChatActivity.Idle,
425+
Model = "test-model",
426+
},
427+
new ChatThread
428+
{
429+
Id = ForkThreadId,
430+
Title = $"Route target: {ForkThreadId}",
431+
Status = ChatThreadStatus.Running,
432+
Activity = ChatActivity.Idle,
433+
Model = "test-model",
434+
},
435+
],
416436
new Dictionary<string, ChatTimelineState>
417437
{
418-
[ThreadId] = timeline,
438+
[DefaultThreadId] = CreateTimeline(DefaultThreadId),
439+
[MainThreadId] = CreateTimeline(MainThreadId),
440+
[ForkThreadId] = CreateTimeline(ForkThreadId),
419441
},
420-
ThreadId,
442+
DefaultThreadId,
421443
"Connected (accessibility test)",
422444
["test-model"],
423-
new ChatComposeTarget(ThreadId, IsReady: true));
445+
new ChatComposeTarget(DefaultThreadId, IsReady: true));
424446
}
425447
}
426448

‎src/OpenClaw.Tray.WinUI/Pages/SessionsPage.xaml.cs‎

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ public void Initialize()
5555

5656
var client = CurrentApp.GatewayClient;
5757

58+
// The real-process accessibility suite has no gateway. Give it an
59+
// isolated, deterministic duplicate-name scenario so UI Automation can
60+
// prove both the rendered titles and the row-to-chat key hand-off.
61+
// Requiring the test data directory as well as the explicit flag keeps
62+
// this path unreachable from a normal app launch.
63+
if (Environment.GetEnvironmentVariable("OPENCLAW_ACCESSIBILITY_TEST_SESSIONS") == "1"
64+
&& Environment.GetEnvironmentVariable("OPENCLAW_TRAY_DATA_DIR") is { Length: > 0 })
65+
{
66+
UpdateSessions(
67+
[
68+
new SessionInfo
69+
{
70+
Key = "agent:main:main",
71+
IsMain = true,
72+
Status = "active",
73+
DisplayName = "OpenClaw Windows Tray",
74+
UpdatedAt = DateTime.UtcNow,
75+
},
76+
new SessionInfo
77+
{
78+
Key = "agent:main:fork",
79+
Status = "active",
80+
DisplayName = "OpenClaw Windows Tray",
81+
UpdatedAt = DateTime.UtcNow.AddSeconds(-1),
82+
},
83+
]);
84+
return;
85+
}
86+
5887
// Rebind when the client instance changes so a cached page never holds
5988
// a stale command-result subscription.
6089
if (_subscribedClient != client)
@@ -161,18 +190,23 @@ private void ApplyFilter()
161190
return;
162191
}
163192

164-
IEnumerable<SessionInfo> filtered = _allSessions ?? Array.Empty<SessionInfo>();
165-
filtered = SessionVisibilityFilter.VisibleSessions(filtered, ShowCompletedSessions);
193+
var activeSessions = SessionVisibilityFilter.VisibleSessions(
194+
_allSessions ?? Array.Empty<SessionInfo>(),
195+
ShowCompletedSessions)
196+
.ToList();
197+
var activeTitles = SessionTitleFormatter.FormatUnique(activeSessions);
198+
IEnumerable<(SessionInfo Session, string Title)> filtered = activeSessions
199+
.Select((session, index) => (Session: session, Title: activeTitles[index]));
166200

167201
if (_activeChannel != "all")
168202
{
169-
filtered = filtered.Where(s =>
170-
string.Equals(s.Channel, _activeChannel, StringComparison.OrdinalIgnoreCase));
203+
filtered = filtered.Where(item =>
204+
string.Equals(item.Session.Channel, _activeChannel, StringComparison.OrdinalIgnoreCase));
171205
}
172206

173207
var viewModels = filtered
174-
.OrderByDescending(s => s.UpdatedAt ?? s.LastSeen)
175-
.Select(s => ToViewModel(s))
208+
.OrderByDescending(item => item.Session.UpdatedAt ?? item.Session.LastSeen)
209+
.Select(item => ToViewModel(item.Session, item.Title))
176210
.ToList();
177211

178212
if (viewModels.Count == 0)
@@ -232,7 +266,7 @@ private void OnAppStateChanged(object? sender, PropertyChangedEventArgs e)
232266
}
233267
}
234268

235-
private SessionViewModel ToViewModel(SessionInfo s)
269+
private SessionViewModel ToViewModel(SessionInfo s, string displayName)
236270
{
237271
var parts = new List<string>(3);
238272
if (!string.IsNullOrWhiteSpace(s.Provider)) parts.Add(s.Provider!);
@@ -259,7 +293,7 @@ private SessionViewModel ToViewModel(SessionInfo s)
259293
return new SessionViewModel
260294
{
261295
Key = s.Key,
262-
DisplayName = !string.IsNullOrWhiteSpace(s.DisplayName) ? s.DisplayName! : s.Key,
296+
DisplayName = displayName,
263297
AgeText = s.AgeText,
264298
DetailLine = parts.Count > 0 ? string.Join(" · ", parts) : "",
265299
StatusBrush = ResolveStatusBrush(s),

0 commit comments

Comments
 (0)