fix: validate lmstudio discovered context lengths

This commit is contained in:
Peter Steinberger
2026-05-28 18:10:55 -04:00
parent 8e806e9125
commit 80f7e36ddc
3 changed files with 42 additions and 21 deletions
+3 -12
View File
@@ -3,6 +3,7 @@ import { readProviderJsonArrayFieldResponse } from "openclaw/plugin-sdk/provider
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
import { SELF_HOSTED_DEFAULT_COST } from "openclaw/plugin-sdk/provider-setup";
import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
import { asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
import { LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH } from "./defaults.js";
import {
buildLmstudioModelName,
@@ -214,18 +215,8 @@ export async function ensureLmstudioModelLoaded(params: {
}
const matchingModel = preflight.models.find((entry) => entry.key?.trim() === modelKey);
const loadedContextWindow = matchingModel ? resolveLoadedContextWindow(matchingModel) : null;
const advertisedContextLimit =
matchingModel?.max_context_length !== undefined &&
Number.isFinite(matchingModel.max_context_length) &&
matchingModel.max_context_length > 0
? Math.floor(matchingModel.max_context_length)
: null;
const requestedContextLength =
params.requestedContextLength !== undefined &&
Number.isFinite(params.requestedContextLength) &&
params.requestedContextLength > 0
? Math.floor(params.requestedContextLength)
: null;
const advertisedContextLimit = asPositiveSafeInteger(matchingModel?.max_context_length) ?? null;
const requestedContextLength = asPositiveSafeInteger(params.requestedContextLength) ?? null;
const contextLengthForLoad =
advertisedContextLimit === null
? (requestedContextLength ?? LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH)