{"record":{"id":"2cb1d860d69a0cb1","repo":"can1357/oh-my-pi","slug":"provider-providername-model-modeldef-id-in","errorCode":null,"errorMessage":"Provider ${providerName}, model ${modelDef.id}: invalid contextWindow","messagePattern":"Provider (.+?), model (.+?): invalid contextWindow","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/config/models-config.ts","lineNumber":98,"sourceCode":"\n\tif (mode === \"models-config\" && config.discovery && !config.api && config.discovery.type !== \"proxy\") {\n\t\tthrow new Error(`Provider ${providerName}: \"api\" is required when discovery is enabled at provider level.`);\n\t}\n\n\tfor (const modelDef of models) {\n\t\tif (!hasProviderApi && !modelDef.api) {\n\t\t\tthrow new Error(\n\t\t\t\tmode === \"runtime-register\"\n\t\t\t\t\t? `Provider ${providerName}, model ${modelDef.id}: no \"api\" specified.`\n\t\t\t\t\t: `Provider ${providerName}, model ${modelDef.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t);\n\t\t}\n\t\tif (!modelDef.id) {\n\t\t\tthrow new Error(`Provider ${providerName}: model missing \"id\"`);\n\t\t}\n\t\tif (mode === \"models-config\") {\n\t\t\tif (modelDef.contextWindow !== undefined && modelDef.contextWindow <= 0) {\n\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid contextWindow`);\n\t\t\t}\n\t\t\tif (modelDef.maxTokens !== undefined && modelDef.maxTokens <= 0) {\n\t\t\t\tthrow new Error(`Provider ${providerName}, model ${modelDef.id}: invalid maxTokens`);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const ModelsConfigFile = new ConfigFile<ModelsConfig>(\"models\", {\n\tkind: \"deferred\",\n\tresolve: getModelsConfigSchema,\n}).withValidation(\"models\", config => {\n\tconst providers = config.providers ?? {};\n\tfor (const providerName in providers) {\n\t\tconst providerConfig = providers[providerName];\n\t\tvalidateProviderConfiguration(\n\t\t\tproviderName,\n\t\t\t{","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/config/models-config.ts#L80-L116","documentation":"Thrown by validateProviderConfiguration in models-config mode when a model declares a contextWindow that is not a positive number (zero or negative). The context window bounds prompt sizing and truncation logic; a non-positive value would break token budgeting. Runtime registration skips this check.","triggerScenarios":"Loading a models-config file where any model entry has contextWindow set to 0, a negative number, or a value computed to be <= 0.","commonSituations":"Hand-edited configs with placeholder values left at 0; templated configs where an env-substituted value resolved to empty/0; unit mistakes (writing context window in billions vs tokens).","solutions":["Set contextWindow to the model's real positive token limit","Remove the contextWindow field entirely if unknown (it is optional)","Fix templates/env vars so substitution yields a positive integer"],"exampleFix":"// before\n{ \"id\": \"my-model\", \"contextWindow\": 0 }\n// after\n{ \"id\": \"my-model\", \"contextWindow\": 128000 }","handlingStrategy":"validation","validationCode":"function assertContextWindows(cfg) {\n  (cfg.models ?? []).forEach(m => {\n    if (m.contextWindow !== undefined && m.contextWindow <= 0) throw new Error(`${m.id}: contextWindow must be > 0`);\n  });\n}","typeGuard":"function hasPositiveContextWindow(m) { return m.contextWindow === undefined || (Number.isFinite(m.contextWindow) && m.contextWindow > 0); }","tryCatchPattern":"try { registerProvider(cfg); } catch (e) { if (String(e).includes('invalid contextWindow')) { logger.error('Fix non-positive contextWindow', { provider: cfg.name }); } else throw e; }","preventionTips":["Omit contextWindow when unknown instead of writing 0","Sanity-check generated configs: all numeric limits must be positive integers","Guard template substitutions against empty values resolving to 0"],"tags":["config","validation","models"],"backgroundTag":"invalid-config-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}