fix(agents): avoid alias setup load for matching refs · openclaw/openclaw@b334e7e
vincentkoc
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
|
3 | 3 | import { testing as cliBackendsTesting } from "./cli-backends.js"; |
4 | 4 | import { createModelPickerVisibleProviderPredicate } from "./model-picker-visibility.js"; |
5 | 5 | import { |
| 6 | +areRuntimeModelRefsEquivalent, |
6 | 7 | isCliRuntimeProvider, |
7 | 8 | resolveCliRuntimeExecutionProvider, |
8 | 9 | } from "./model-runtime-aliases.js"; |
@@ -164,3 +165,24 @@ describe("resolveCliRuntimeExecutionProvider", () => {
|
164 | 165 | expect(isVisibleProvider("acme-cli")).toBe(true); |
165 | 166 | }); |
166 | 167 | }); |
| 168 | + |
| 169 | +describe("areRuntimeModelRefsEquivalent", () => { |
| 170 | +afterEach(() => { |
| 171 | +cliBackendsTesting.resetDepsForTest(); |
| 172 | +}); |
| 173 | + |
| 174 | +it("does not load setup runtime aliases for already-identical refs", () => { |
| 175 | +cliBackendsTesting.setDepsForTest({ |
| 176 | +resolvePluginSetupRegistry: () => { |
| 177 | +throw new Error("setup registry should not load for identical refs"); |
| 178 | +}, |
| 179 | +resolveRuntimeCliBackends: () => [], |
| 180 | +}); |
| 181 | + |
| 182 | +expect( |
| 183 | +areRuntimeModelRefsEquivalent("anthropic/claude", "anthropic/claude", { |
| 184 | +config: {}, |
| 185 | +}), |
| 186 | +).toBe(true); |
| 187 | +}); |
| 188 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -81,11 +81,26 @@ function normalizeRuntimeModelRefForComparison(
|
81 | 81 | return model ? `${canonicalProvider}/${model}` : canonicalProvider; |
82 | 82 | } |
83 | 83 | |
| 84 | +function normalizeRuntimeModelRefWithoutAlias(raw: string): string { |
| 85 | +const trimmed = raw.trim(); |
| 86 | +const slash = trimmed.indexOf("/"); |
| 87 | +if (slash <= 0 || slash >= trimmed.length - 1) { |
| 88 | +return normalizeProviderId(trimmed); |
| 89 | +} |
| 90 | +const provider = trimmed.slice(0, slash).trim(); |
| 91 | +const model = trimmed.slice(slash + 1).trim(); |
| 92 | +const normalizedProvider = normalizeProviderId(provider); |
| 93 | +return model ? `${normalizedProvider}/${model}` : normalizedProvider; |
| 94 | +} |
| 95 | + |
84 | 96 | export function areRuntimeModelRefsEquivalent( |
85 | 97 | left: string, |
86 | 98 | right: string, |
87 | 99 | options: RuntimeAliasComparisonOptions = {}, |
88 | 100 | ): boolean { |
| 101 | +if (normalizeRuntimeModelRefWithoutAlias(left) === normalizeRuntimeModelRefWithoutAlias(right)) { |
| 102 | +return true; |
| 103 | +} |
89 | 104 | return ( |
90 | 105 | normalizeRuntimeModelRefForComparison(left, options) === |
91 | 106 | normalizeRuntimeModelRefForComparison(right, options) |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -270,6 +270,16 @@ describe("runReplyAgent heartbeat followup guard", () => {
|
270 | 270 | runOverrides: { sessionId: "stale-session" }, |
271 | 271 | sessionStore, |
272 | 272 | }); |
| 273 | +state.runEmbeddedAgentMock.mockResolvedValueOnce({ |
| 274 | +payloads: [{ text: "final" }], |
| 275 | +meta: { |
| 276 | +agentMeta: { |
| 277 | +provider: "anthropic", |
| 278 | +model: "claude", |
| 279 | +usage: { input: 1, output: 1 }, |
| 280 | +}, |
| 281 | +}, |
| 282 | +}); |
273 | 283 | |
274 | 284 | const pending = run(); |
275 | 285 | await new Promise<void>((resolve) => setTimeout(resolve, 0)); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。