mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 23:00:41 +00:00
fix(gateway): invalidate bootstrap cache on session rollover (openclaw#38535)
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: yfge <1186273+yfge@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
|
||||
vi.mock("../../config/sessions.js", () => ({
|
||||
@@ -8,6 +8,16 @@ vi.mock("../../config/sessions.js", () => ({
|
||||
resolveSessionResetPolicy: vi.fn().mockReturnValue({ mode: "idle", idleMinutes: 60 }),
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/bootstrap-cache.js", () => ({
|
||||
clearBootstrapSnapshot: vi.fn(),
|
||||
clearBootstrapSnapshotOnSessionRollover: vi.fn(({ sessionKey, previousSessionId }) => {
|
||||
if (sessionKey && previousSessionId) {
|
||||
clearBootstrapSnapshot(sessionKey);
|
||||
}
|
||||
}),
|
||||
}));
|
||||
|
||||
import { clearBootstrapSnapshot } from "../../agents/bootstrap-cache.js";
|
||||
import { loadSessionStore, evaluateSessionFreshness } from "../../config/sessions.js";
|
||||
import { resolveCronSession } from "./session.js";
|
||||
|
||||
@@ -40,6 +50,10 @@ function resolveWithStoredEntry(params?: {
|
||||
}
|
||||
|
||||
describe("resolveCronSession", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(clearBootstrapSnapshot).mockReset();
|
||||
});
|
||||
|
||||
it("preserves modelOverride and providerOverride from existing session entry", () => {
|
||||
const result = resolveWithStoredEntry({
|
||||
sessionKey: "agent:main:cron:test-job",
|
||||
@@ -100,6 +114,7 @@ describe("resolveCronSession", () => {
|
||||
expect(result.sessionEntry.sessionId).toBe("existing-session-id-123");
|
||||
expect(result.isNewSession).toBe(false);
|
||||
expect(result.systemSent).toBe(true);
|
||||
expect(clearBootstrapSnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("creates new sessionId when session is stale", () => {
|
||||
@@ -121,6 +136,7 @@ describe("resolveCronSession", () => {
|
||||
expect(result.sessionEntry.modelOverride).toBe("gpt-4.1-mini");
|
||||
expect(result.sessionEntry.providerOverride).toBe("openai");
|
||||
expect(result.sessionEntry.sendPolicy).toBe("allow");
|
||||
expect(clearBootstrapSnapshot).toHaveBeenCalledWith("webhook:stable-key");
|
||||
});
|
||||
|
||||
it("creates new sessionId when forceNew is true", () => {
|
||||
@@ -141,6 +157,7 @@ describe("resolveCronSession", () => {
|
||||
expect(result.systemSent).toBe(false);
|
||||
expect(result.sessionEntry.modelOverride).toBe("sonnet-4");
|
||||
expect(result.sessionEntry.providerOverride).toBe("anthropic");
|
||||
expect(clearBootstrapSnapshot).toHaveBeenCalledWith("webhook:stable-key");
|
||||
});
|
||||
|
||||
it("clears delivery routing metadata and deliveryContext when forceNew is true", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
import { clearBootstrapSnapshotOnSessionRollover } from "../../agents/bootstrap-cache.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import {
|
||||
evaluateSessionFreshness,
|
||||
@@ -58,6 +59,11 @@ export function resolveCronSession(params: {
|
||||
systemSent = false;
|
||||
}
|
||||
|
||||
clearBootstrapSnapshotOnSessionRollover({
|
||||
sessionKey: params.sessionKey,
|
||||
previousSessionId: isNewSession ? entry?.sessionId : undefined,
|
||||
});
|
||||
|
||||
const sessionEntry: SessionEntry = {
|
||||
// Preserve existing per-session overrides even when rolling to a new sessionId.
|
||||
...entry,
|
||||
|
||||
Reference in New Issue
Block a user