{"record":{"id":"b93d4d7e99c2ee04","repo":"deepseek-ai/deepseek-harness","slug":"basiccompactionconfig-contextwindow-contextwin","errorCode":null,"errorMessage":"BasicCompactionConfig: contextWindow (${contextWindow}) must be a positive integer","messagePattern":"BasicCompactionConfig: contextWindow \\((.+?)\\) must be a positive integer","errorType":"validation","errorClass":"TargetPressureConfigError","httpStatus":null,"severity":"error","filePath":"packages/compaction/compaction-basic/src/config.ts","lineNumber":139,"sourceCode":"    maxTokens: override?.maxTokens ?? config.maxTokens,\n    compactionRetries: override?.compactionRetries ?? config.compactionRetries,\n    maxOverflowRetries: override?.maxOverflowRetries ?? config.maxOverflowRetries,\n  })\n}\n\n/**\n * Scale one routed policy into concrete token budgets for its model capacity.\n * @param policy - merged policy for the exact routed target.\n * @param contextWindow - positive adapter-owned capacity for that target.\n * @returns detached immutable pressure and retention budgets.\n */\nexport function resolveCompactSpec(\n  policy: ResolvedTargetPolicy,\n  contextWindow: number,\n): ResolvedCompactSpec {\n  const targetKey = `${policy.target.provider}/${policy.target.model}`\n  if (!Number.isInteger(contextWindow) || contextWindow <= 0) {\n    throw new TargetPressureConfigError(\n      targetKey,\n      `BasicCompactionConfig: contextWindow (${contextWindow}) must be a positive integer`,\n    )\n  }\n  const thresholdTokens = Math.floor(contextWindow * policy.thresholdRatio)\n  const retainTokens = policy.retainTokens === undefined\n    ? Math.floor(contextWindow * policy.retainRatio)\n    : policy.retainTokens\n  if (retainTokens >= thresholdTokens) {\n    throw new TargetPressureConfigError(\n      targetKey,\n      `BasicCompactionConfig: ${policy.target.provider}/${policy.target.model} retainTokens `\n      + `(${retainTokens}) must be less than threshold tokens ${thresholdTokens}`,\n    )\n  }\n  return deepFreeze({\n    target: { ...policy.target },\n    contextWindow,","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/compaction/compaction-basic/src/config.ts#L121-L157","documentation":"compaction-basic's resolveCompactSpec — reached through spec() when a request routes to a provider/model — scales the merged policy by the model's contextWindow, a capacity owned by the LLM adapter. A contextWindow that is not a positive integer (0, fractional, NaN) cannot produce token budgets, so it throws TargetPressureConfigError keyed by the exact provider/model route, a failure class explicitly eligible for warning suppression.","triggerScenarios":"A request routes to a model whose adapter-supplied contextWindow is 0 (no capacity metadata registered), fractional, or NaN. This fires per routed target at compaction-spec time, not at config load.","commonSituations":"Pointing a custom base URL at a gateway with model names the adapter has no context-window metadata for; adding a new provider/model without registering its capacity; an adapter version change that stops reporting contextWindow.","solutions":["Check the model registration in the LLM provider/adapter and give the failing provider/model a positive integer contextWindow.","Verify the configured provider/model strings match the registered metadata exactly — a typo mints an unknown target with no capacity.","For targets you never intend to compact, catch TargetPressureConfigError and downgrade it to a warning; that suppression is what the class exists for."],"exampleFix":"// before — custom model has no capacity metadata; adapter reports 0\n{ provider: 'deepseek', model: 'my-ft-model' } // contextWindow 0 → throws\n\n// after — register the real capacity with the provider metadata\n{ provider: 'deepseek', model: 'my-ft-model', contextWindow: 131072 }","handlingStrategy":"try-catch","validationCode":"const usable = Number.isInteger(model.contextWindow) && model.contextWindow > 0\nif (!usable) {\n  // register capacity or exclude this target from auto compaction before routing\n  throw new Error(`no usable contextWindow for ${model.provider}/${model.model}`)\n}","typeGuard":"function hasUsableContextWindow(m: { contextWindow: number }): boolean {\n  return Number.isInteger(m.contextWindow) && m.contextWindow > 0\n}","tryCatchPattern":"try {\n  const spec = resolveCompactSpec(policy, contextWindow)\n} catch (err) {\n  if (err instanceof TargetPressureConfigError) {\n    // err.targetKey names the exact provider/model: fix metadata for targets\n    // you route to; warn-and-skip for targets you never compact\n    warn(`compaction config for ${err.targetKey}: ${err.message}`)\n  } else throw err\n}","preventionTips":["Register a positive integer contextWindow for every custom model before enabling auto compaction.","Smoke-test one request per new provider/model route.","Keep provider/model strings identical across config and registry — typos mint unknown zero-capacity targets."],"tags":["compaction","llm","model-metadata","context-window","validation"],"backgroundTag":"invalid-model-metadata","analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}