deepseek-ai/deepseek-harness · error · TargetPressureConfigError

BasicCompactionConfig: contextWindow (${contextWindow}) must

Error message

BasicCompactionConfig: contextWindow (${contextWindow}) must be a positive integer

What it means

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.

Source

Thrown at packages/compaction/compaction-basic/src/config.ts:139

    maxTokens: override?.maxTokens ?? config.maxTokens,
    compactionRetries: override?.compactionRetries ?? config.compactionRetries,
    maxOverflowRetries: override?.maxOverflowRetries ?? config.maxOverflowRetries,
  })
}

/**
 * Scale one routed policy into concrete token budgets for its model capacity.
 * @param policy - merged policy for the exact routed target.
 * @param contextWindow - positive adapter-owned capacity for that target.
 * @returns detached immutable pressure and retention budgets.
 */
export function resolveCompactSpec(
  policy: ResolvedTargetPolicy,
  contextWindow: number,
): ResolvedCompactSpec {
  const targetKey = `${policy.target.provider}/${policy.target.model}`
  if (!Number.isInteger(contextWindow) || contextWindow <= 0) {
    throw new TargetPressureConfigError(
      targetKey,
      `BasicCompactionConfig: contextWindow (${contextWindow}) must be a positive integer`,
    )
  }
  const thresholdTokens = Math.floor(contextWindow * policy.thresholdRatio)
  const retainTokens = policy.retainTokens === undefined
    ? Math.floor(contextWindow * policy.retainRatio)
    : policy.retainTokens
  if (retainTokens >= thresholdTokens) {
    throw new TargetPressureConfigError(
      targetKey,
      `BasicCompactionConfig: ${policy.target.provider}/${policy.target.model} retainTokens `
      + `(${retainTokens}) must be less than threshold tokens ${thresholdTokens}`,
    )
  }
  return deepFreeze({
    target: { ...policy.target },
    contextWindow,

View on GitHub (pinned to b150a551b8)

Solutions

  1. Check the model registration in the LLM provider/adapter and give the failing provider/model a positive integer contextWindow.
  2. Verify the configured provider/model strings match the registered metadata exactly — a typo mints an unknown target with no capacity.
  3. For targets you never intend to compact, catch TargetPressureConfigError and downgrade it to a warning; that suppression is what the class exists for.

Example fix

// before — custom model has no capacity metadata; adapter reports 0
{ provider: 'deepseek', model: 'my-ft-model' } // contextWindow 0 → throws

// after — register the real capacity with the provider metadata
{ provider: 'deepseek', model: 'my-ft-model', contextWindow: 131072 }
Defensive patterns

Strategy: try-catch

Validate before calling

const usable = Number.isInteger(model.contextWindow) && model.contextWindow > 0
if (!usable) {
  // register capacity or exclude this target from auto compaction before routing
  throw new Error(`no usable contextWindow for ${model.provider}/${model.model}`)
}

Type guard

function hasUsableContextWindow(m: { contextWindow: number }): boolean {
  return Number.isInteger(m.contextWindow) && m.contextWindow > 0
}

Try / catch

try {
  const spec = resolveCompactSpec(policy, contextWindow)
} catch (err) {
  if (err instanceof TargetPressureConfigError) {
    // err.targetKey names the exact provider/model: fix metadata for targets
    // you route to; warn-and-skip for targets you never compact
    warn(`compaction config for ${err.targetKey}: ${err.message}`)
  } else throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24). Data as JSON: /api/errors/b93d4d7e99c2ee04. Report an issue: GitHub.