Skip to content

Commit d971a62

Browse files
shanselmanCopilot
andcommitted
Dedupe cached model ids
Keep provider-qualified picker choices distinct while preserving a unique legacy raw-id cache for reconnect fallback selection. Co-authored-by: Copilot <[email protected]>
1 parent 2d1cee3 commit d971a62

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,20 +1500,27 @@ private void OnModelsListUpdated(object? sender, ModelsListInfo info)
15001500
private static string[] ModelIdsFromChoices(IReadOnlyList<ChatModelChoice> choices)
15011501
{
15021502
if (choices.Count == 0) return Array.Empty<string>();
1503-
var ids = new string[choices.Count];
1504-
for (int i = 0; i < choices.Count; i++) ids[i] = choices[i].Id;
1505-
return ids;
1503+
var seen = new HashSet<string>(StringComparer.Ordinal);
1504+
var ids = new List<string>(choices.Count);
1505+
foreach (var choice in choices)
1506+
{
1507+
if (seen.Add(choice.Id))
1508+
ids.Add(choice.Id);
1509+
}
1510+
return ids.ToArray();
15061511
}
15071512

15081513
// Rehydrate minimal choices from a cached id list (reconnect / pre-connect
15091514
// path) when richer gateway metadata isn't available yet.
15101515
private static IReadOnlyList<ChatModelChoice> ChoicesFromIds(string[] ids)
15111516
{
15121517
if (ids.Length == 0) return Array.Empty<ChatModelChoice>();
1518+
var seen = new HashSet<string>(StringComparer.Ordinal);
15131519
var list = new List<ChatModelChoice>(ids.Length);
15141520
foreach (var id in ids)
15151521
{
15161522
if (string.IsNullOrEmpty(id)) continue;
1523+
if (!seen.Add(id)) continue;
15171524
list.Add(new ChatModelChoice(id, id));
15181525
}
15191526
return list;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,7 @@ public async Task ModelsListUpdated_KeepsDuplicateRawModelIdsFromDifferentProvid
21012101
Assert.Equal(2, choices.Count);
21022102
Assert.Equal("openai/gpt-5.4", choices[0].SelectionId);
21032103
Assert.Equal("openrouter/gpt-5.4", choices[1].SelectionId);
2104+
Assert.Equal(new[] { "gpt-5.4" }, snapshots[^1].AvailableModels);
21042105
}
21052106

21062107
[Fact]

0 commit comments

Comments
 (0)