mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
fix: rehydrate context token cache after module reload
This commit is contained in:
@@ -116,6 +116,38 @@ describe("lookupContextTokens", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("rehydrates config-backed cache entries after module reload when runtime config survives", async () => {
|
||||
const firstLoadConfigMock = vi.fn(() => ({
|
||||
models: {
|
||||
providers: {
|
||||
openrouter: {
|
||||
models: [{ id: "openrouter/claude-sonnet", contextWindow: 321_000 }],
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
mockContextModuleDeps(firstLoadConfigMock);
|
||||
|
||||
let { lookupContextTokens } = await importContextModule();
|
||||
expect(lookupContextTokens("openrouter/claude-sonnet", { allowAsyncLoad: false })).toBe(
|
||||
321_000,
|
||||
);
|
||||
expect(firstLoadConfigMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
vi.resetModules();
|
||||
|
||||
const secondLoadConfigMock = vi.fn(() => {
|
||||
throw new Error("config should come from shared runtime state");
|
||||
});
|
||||
mockContextModuleDeps(secondLoadConfigMock);
|
||||
|
||||
({ lookupContextTokens } = await importContextModule());
|
||||
expect(lookupContextTokens("openrouter/claude-sonnet", { allowAsyncLoad: false })).toBe(
|
||||
321_000,
|
||||
);
|
||||
expect(secondLoadConfigMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("only warms eagerly for real openclaw startup commands that need model metadata", async () => {
|
||||
const argvSnapshot = process.argv;
|
||||
try {
|
||||
|
||||
@@ -158,6 +158,12 @@ function shouldEagerWarmContextWindowCache(argv: string[] = process.argv): boole
|
||||
|
||||
function primeConfiguredContextWindows(): OpenClawConfig | undefined {
|
||||
if (CONTEXT_WINDOW_RUNTIME_STATE.configuredConfig) {
|
||||
applyConfiguredContextWindows({
|
||||
cache: MODEL_CONTEXT_TOKEN_CACHE,
|
||||
modelsConfig: CONTEXT_WINDOW_RUNTIME_STATE.configuredConfig.models as
|
||||
| ModelsConfig
|
||||
| undefined,
|
||||
});
|
||||
return CONTEXT_WINDOW_RUNTIME_STATE.configuredConfig;
|
||||
}
|
||||
if (Date.now() < CONTEXT_WINDOW_RUNTIME_STATE.nextConfigLoadAttemptAtMs) {
|
||||
|
||||
Reference in New Issue
Block a user