fix(config): clear stale context limit cache on provider updates

Rebuilding provider model limits prevents removed entries from leaking into later compaction decisions after config changes.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-14 13:48:59 +09:00
parent 16b0d9eb77
commit 612b9c163d
3 changed files with 138 additions and 1 deletions
@@ -6,6 +6,46 @@ import { createModelCacheState } from "../plugin-state"
import { clearVisionCapableModelsCache, readVisionCapableModelsCache } from "../shared/vision-capable-models-cache"
describe("applyProviderConfig", () => {
test("clears stale model context limits when provider config changes", () => {
// given
const modelCacheState = createModelCacheState()
applyProviderConfig({
config: {
provider: {
opencode: {
models: {
"kimi-k2.5-free": {
limit: { context: 262144 },
},
},
},
},
},
modelCacheState,
})
// when
applyProviderConfig({
config: {
provider: {
google: {
models: {
"gemini-2.5-pro": {
limit: { context: 1048576 },
},
},
},
},
},
modelCacheState,
})
// then
expect(Array.from(modelCacheState.modelContextLimitsCache.entries())).toEqual([
["google/gemini-2.5-pro", 1048576],
])
})
test("caches vision-capable models from modalities and capabilities", () => {
// given
const modelCacheState = createModelCacheState()
@@ -33,6 +33,9 @@ export function applyProviderConfig(params: {
const providers = params.config.provider as
| Record<string, ProviderConfig>
| undefined;
const modelContextLimitsCache = params.modelCacheState.modelContextLimitsCache;
modelContextLimitsCache.clear()
const anthropicBeta = providers?.anthropic?.options?.headers?.["anthropic-beta"];
params.modelCacheState.anthropicContext1MEnabled =
@@ -61,7 +64,7 @@ export function applyProviderConfig(params: {
const contextLimit = modelConfig?.limit?.context;
if (!contextLimit) continue;
params.modelCacheState.modelContextLimitsCache.set(
modelContextLimitsCache.set(
`${providerID}/${modelID}`,
contextLimit,
);