Skip to content

Commit ba2781d

Browse files
fix(clawsweeper): address review for automerge-openclaw-openclaw-75840 (1)
1 parent b58e84f commit ba2781d

4 files changed

Lines changed: 67 additions & 16 deletions

File tree

src/cron/isolated-agent.model-formatting.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe("cron model formatting and precedence edge cases", () => {
404404
});
405405

406406
describe("CLI runtime compatibility", () => {
407-
it("uses a configured per-agent Claude CLI runtime for resolved Anthropic models", async () => {
407+
it("keeps the canonical Anthropic provider when a per-agent Claude CLI runtime is configured", async () => {
408408
await expectSelectedModel(
409409
{
410410
cfg: {
@@ -422,7 +422,7 @@ describe("cron model formatting and precedence edge cases", () => {
422422
},
423423
agentId: "scheduler",
424424
},
425-
{ provider: "claude-cli", model: "claude-opus-4-6" },
425+
{ provider: "anthropic", model: "claude-opus-4-6" },
426426
);
427427
});
428428

@@ -453,7 +453,7 @@ describe("cron model formatting and precedence edge cases", () => {
453453
);
454454
});
455455

456-
it("uses a configured default Claude CLI runtime for resolved Anthropic models", async () => {
456+
it("keeps the canonical Anthropic provider when a default Claude CLI runtime is configured", async () => {
457457
await expectSelectedModel(
458458
{
459459
cfg: {
@@ -465,7 +465,7 @@ describe("cron model formatting and precedence edge cases", () => {
465465
},
466466
},
467467
},
468-
{ provider: "claude-cli", model: "claude-opus-4-6" },
468+
{ provider: "anthropic", model: "claude-opus-4-6" },
469469
);
470470
});
471471

src/cron/isolated-agent/model-selection.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { resolveCliRuntimeExecutionProvider } from "../../agents/model-runtime-aliases.js";
21
import type { OpenClawConfig } from "../../config/types.openclaw.js";
32
import type { CronJob } from "../types.js";
43
import {
@@ -149,12 +148,5 @@ export async function resolveCronModelSelection(
149148
}
150149
}
151150

152-
const executionProvider =
153-
resolveCliRuntimeExecutionProvider({
154-
provider,
155-
cfg: params.cfgWithAgentDefaults,
156-
agentId: params.agentId,
157-
}) ?? provider;
158-
159-
return { ok: true, provider: executionProvider, model };
151+
return { ok: true, provider, model };
160152
}

src/cron/isolated-agent/run-executor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resolveCliRuntimeExecutionProvider } from "../../agents/model-runtime-aliases.js";
12
import type { SkillSnapshot } from "../../agents/skills.js";
23
import { normalizeToolList } from "../../agents/tool-policy.js";
34
import type { ThinkLevel, VerboseLevel } from "../../auto-reply/thinking.js";
@@ -135,12 +136,18 @@ export function createCronPromptExecutor(params: {
135136
if (params.abortSignal?.aborted) {
136137
throw new Error(params.abortReason());
137138
}
139+
const executionProvider =
140+
resolveCliRuntimeExecutionProvider({
141+
provider: providerOverride,
142+
cfg: params.cfgWithAgentDefaults,
143+
agentId: params.agentId,
144+
}) ?? providerOverride;
138145
const bootstrapPromptWarningSignature =
139146
bootstrapPromptWarningSignaturesSeen[bootstrapPromptWarningSignaturesSeen.length - 1];
140-
if (isCliProvider(providerOverride, params.cfgWithAgentDefaults)) {
147+
if (isCliProvider(executionProvider, params.cfgWithAgentDefaults)) {
141148
const cliSessionId = params.cronSession.isNewSession
142149
? undefined
143-
: await getCliSessionId(params.cronSession.sessionEntry, providerOverride);
150+
: await getCliSessionId(params.cronSession.sessionEntry, executionProvider);
144151
const result = await runCliAgent({
145152
sessionId: params.cronSession.sessionEntry.sessionId,
146153
sessionKey: params.runSessionKey,
@@ -151,7 +158,7 @@ export function createCronPromptExecutor(params: {
151158
workspaceDir: params.workspaceDir,
152159
config: params.cfgWithAgentDefaults,
153160
prompt: promptText,
154-
provider: providerOverride,
161+
provider: executionProvider,
155162
model: modelOverride,
156163
thinkLevel: params.thinkLevel,
157164
timeoutMs: params.timeoutMs,

src/cron/isolated-agent/run.payload-fallbacks.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
setupRunCronIsolatedAgentTurnSuite,
66
} from "./run.suite-helpers.js";
77
import {
8+
isCliProviderMock,
89
loadRunCronIsolatedAgentTurn,
10+
resolveConfiguredModelRefMock,
911
resolveAgentModelFallbacksOverrideMock,
12+
runCliAgentMock,
1013
runWithModelFallbackMock,
1114
} from "./run.test-harness.js";
1215

@@ -54,4 +57,53 @@ describe("runCronIsolatedAgentTurn — payload.fallbacks", () => {
5457
expect(runWithModelFallbackMock).toHaveBeenCalledOnce();
5558
expect(runWithModelFallbackMock.mock.calls[0][0].fallbacksOverride).toEqual(expectedFallbacks);
5659
});
60+
61+
it("plans Anthropic fallbacks canonically while executing compatible attempts through Claude CLI", async () => {
62+
isCliProviderMock.mockImplementation((provider: string) => provider === "claude-cli");
63+
resolveConfiguredModelRefMock.mockReturnValue({
64+
provider: "anthropic",
65+
model: "claude-opus-4-6",
66+
});
67+
runCliAgentMock.mockResolvedValue({
68+
payloads: [{ text: "fallback ok" }],
69+
meta: { agentMeta: { usage: { input: 10, output: 20 } } },
70+
});
71+
runWithModelFallbackMock.mockImplementation(async ({ provider, model, run }) => {
72+
const firstResult = await run(provider, model);
73+
const secondResult = await run("anthropic", "claude-sonnet-4-6");
74+
return {
75+
result: secondResult ?? firstResult,
76+
provider: "anthropic",
77+
model: "claude-sonnet-4-6",
78+
attempts: [],
79+
};
80+
});
81+
82+
const result = await runCronIsolatedAgentTurn(
83+
makeIsolatedAgentTurnParams({
84+
cfg: {
85+
agents: {
86+
defaults: {
87+
agentRuntime: { id: "claude-cli" },
88+
model: {
89+
primary: "anthropic/claude-opus-4-6",
90+
fallbacks: ["anthropic/claude-sonnet-4-6"],
91+
},
92+
},
93+
},
94+
},
95+
}),
96+
);
97+
98+
expect(result.status).toBe("ok");
99+
expect(runWithModelFallbackMock).toHaveBeenCalledOnce();
100+
expect(runWithModelFallbackMock.mock.calls[0][0]).toMatchObject({
101+
provider: "anthropic",
102+
model: "claude-opus-4-6",
103+
});
104+
expect(runCliAgentMock.mock.calls.map((call) => [call[0].provider, call[0].model])).toEqual([
105+
["claude-cli", "claude-opus-4-6"],
106+
["claude-cli", "claude-sonnet-4-6"],
107+
]);
108+
});
57109
});

0 commit comments

Comments
 (0)