mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 23:57:28 +00:00
fix: preserve Gmail hook model precedence (openclaw#14983) thanks @shtse8
This commit is contained in:
@@ -23,7 +23,10 @@ async function withTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
||||
return withTempHomeBase(fn, { prefix: "openclaw-cron-" });
|
||||
}
|
||||
|
||||
async function writeSessionStore(home: string) {
|
||||
async function writeSessionStore(
|
||||
home: string,
|
||||
entries: Record<string, Record<string, unknown>> = {},
|
||||
) {
|
||||
const dir = path.join(home, ".openclaw", "sessions");
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
const storePath = path.join(dir, "sessions.json");
|
||||
@@ -37,6 +40,7 @@ async function writeSessionStore(home: string) {
|
||||
lastProvider: "webchat",
|
||||
lastTo: "",
|
||||
},
|
||||
...entries,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
@@ -337,6 +341,56 @@ describe("runCronIsolatedAgentTurn", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps hooks.gmail.model precedence over stored session override", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const storePath = await writeSessionStore(home, {
|
||||
"agent:main:hook:gmail:msg-1": {
|
||||
sessionId: "existing-gmail-session",
|
||||
updatedAt: Date.now(),
|
||||
providerOverride: "anthropic",
|
||||
modelOverride: "claude-opus-4-5",
|
||||
},
|
||||
});
|
||||
const deps: CliDeps = {
|
||||
sendMessageWhatsApp: vi.fn(),
|
||||
sendMessageTelegram: vi.fn(),
|
||||
sendMessageDiscord: vi.fn(),
|
||||
sendMessageSignal: vi.fn(),
|
||||
sendMessageIMessage: vi.fn(),
|
||||
};
|
||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||
payloads: [{ text: "ok" }],
|
||||
meta: {
|
||||
durationMs: 5,
|
||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
||||
},
|
||||
});
|
||||
|
||||
const res = await runCronIsolatedAgentTurn({
|
||||
cfg: makeCfg(home, storePath, {
|
||||
hooks: {
|
||||
gmail: {
|
||||
model: "openrouter/meta-llama/llama-3.3-70b:free",
|
||||
},
|
||||
},
|
||||
}),
|
||||
deps,
|
||||
job: makeJob({ kind: "agentTurn", message: "do it", deliver: false }),
|
||||
message: "do it",
|
||||
sessionKey: "hook:gmail:msg-1",
|
||||
lane: "cron",
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
const call = vi.mocked(runEmbeddedPiAgent).mock.calls[0]?.[0] as {
|
||||
provider?: string;
|
||||
model?: string;
|
||||
};
|
||||
expect(call?.provider).toBe("openrouter");
|
||||
expect(call?.model).toBe("meta-llama/llama-3.3-70b:free");
|
||||
});
|
||||
});
|
||||
|
||||
it("wraps external hook content by default", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const storePath = await writeSessionStore(home);
|
||||
|
||||
@@ -173,6 +173,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
||||
};
|
||||
// Resolve model - prefer hooks.gmail.model for Gmail hooks.
|
||||
const isGmailHook = baseSessionKey.startsWith("hook:gmail:");
|
||||
let hooksGmailModelApplied = false;
|
||||
const hooksGmailModelRef = isGmailHook
|
||||
? resolveHooksGmailModel({
|
||||
cfg: params.cfg,
|
||||
@@ -190,6 +191,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
||||
if (status.allowed) {
|
||||
provider = hooksGmailModelRef.provider;
|
||||
model = hooksGmailModelRef.model;
|
||||
hooksGmailModelApplied = true;
|
||||
}
|
||||
}
|
||||
const modelOverrideRaw =
|
||||
@@ -250,7 +252,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
||||
// Respect session model override — check session.modelOverride before falling
|
||||
// back to the default config model. This ensures /model changes are honoured
|
||||
// by cron and isolated agent runs.
|
||||
if (!modelOverride) {
|
||||
if (!modelOverride && !hooksGmailModelApplied) {
|
||||
const sessionModelOverride = cronSession.sessionEntry.modelOverride?.trim();
|
||||
if (sessionModelOverride) {
|
||||
const sessionProviderOverride =
|
||||
|
||||
Reference in New Issue
Block a user