Skip to content

Commit 9374c83

Browse files
bkudiessCopilot
andcommitted
fix(sessions): reject raw key display names
Co-authored-by: Copilot App <[email protected]>
1 parent 9e2b337 commit 9374c83

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/OpenClaw.Shared/Sessions/SessionDisplayResolver.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ public static SessionDisplayInfo Resolve(SessionInfo session)
2323
var peerKind = NonEmpty(session.PeerKind) ?? fallback.PeerKind;
2424
var isDirect = classification.Equals("direct", StringComparison.OrdinalIgnoreCase)
2525
|| peerKind?.Equals("direct", StringComparison.OrdinalIgnoreCase) == true;
26+
var displayName = isDirect
27+
? null
28+
: UsefulTitle(session.Key, SafeLegacyDisplayName(session.DisplayName));
2629
var title = UsefulTitle(session.Key, session.Label)
27-
?? (isDirect ? null : SafeLegacyDisplayName(session.DisplayName))
30+
?? displayName
2831
?? UsefulTitle(session.Key, session.DerivedTitle)
2932
?? (gatewayClassification is null
3033
? fallback.Title
@@ -34,7 +37,7 @@ public static SessionDisplayInfo Resolve(SessionInfo session)
3437
{
3538
Title = title,
3639
TitleSource = UsefulTitle(session.Key, session.Label) is not null ? "label"
37-
: !isDirect && SafeLegacyDisplayName(session.DisplayName) is not null ? "displayName"
40+
: displayName is not null ? "displayName"
3841
: UsefulTitle(session.Key, session.DerivedTitle) is not null ? "derivedTitle"
3942
: "generated",
4043
Subtitle = BuildSubtitle(channel, accountId, agentId, session.ExecNode, session.Worktree),

‎tests/OpenClaw.Shared.Tests/Protocol/gateway-protocol-snapshot.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"key", "isMain", "status", "model", "label", "channel", "displayName",
7070
"derivedTitle", "modelProvider", "provider", "subject", "groupChannel", "room",
7171
"space", "chatType", "execNode", "parentSessionKey", "spawnDepth", "origin",
72-
"worktree", "classification", "agentId", "accountId", "peerKind", "isMain", "isBackground", "sessionId", "thinkingLevel", "verboseLevel",
72+
"worktree", "classification", "agentId", "accountId", "peerKind", "isBackground", "sessionId", "thinkingLevel", "verboseLevel",
7373
"systemSent", "abortedLastRun", "inputTokens", "outputTokens", "totalTokens",
7474
"contextTokens", "updatedAt", "startedAt"
7575
]

‎tests/OpenClaw.Shared.Tests/SessionDisplayResolverTests.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ public void Resolve_UsesFlatFactsAndDoesNotExposeDirectPeerDisplayName()
2323
Assert.DoesNotContain("491234567890", resolved.Title, StringComparison.Ordinal);
2424
}
2525

26+
[Fact]
27+
public void Resolve_DoesNotUseRawKeyEchoAsDisplayName()
28+
{
29+
const string key = "agent:main:dashboard:new";
30+
31+
var resolved = SessionDisplayResolver.Resolve(new SessionInfo
32+
{
33+
Key = key,
34+
DisplayName = key,
35+
});
36+
37+
Assert.Equal("New session", resolved.Title);
38+
Assert.Equal("generated", resolved.TitleSource);
39+
}
40+
2641
[Theory]
2742
[InlineData("agent:main:main", true, "main", "Main session", false)]
2843
[InlineData("agent:main:subagent:child", false, "subagent", "Subagent", true)]

0 commit comments

Comments
 (0)