JuliusBrussee/caveman · error

cave_compaction_option_invalid

cave_compaction_option_invalid

Error message

cave_compaction_option_invalid

What it means

normalizeCompaction validates user-supplied compaction options (minYieldTokens, headroomCalls, pinnedUserTokens, etc.) after applying defaults. Every merged value must be a positive safe integer; otherwise it throws the coded error cave_compaction_option_invalid.

Solutions

  1. Set all numeric compaction options to positive safe integers
  2. Remove the invalid option to fall back to the library default
  3. Convert string values from config to Number and validate before passing

Example fix

// before
normalizeCompaction({ minYieldTokens: 0.5 })
// after
normalizeCompaction({ minYieldTokens: 512 })
Defensive patterns

Strategy: validation

Validate before calling

const opts = { minYieldTokens: 512, headroomCalls: 3, pinnedUserTokens: 128 };
for (const [k, v] of Object.entries(opts)) {
  if (!Number.isSafeInteger(v) || v <= 0) throw new Error(`${k} must be a positive integer, got ${v}`);
}

Type guard

const isValidCompactionOption = (v: unknown): v is number =>
  typeof v === "number" && Number.isSafeInteger(v) && v > 0;

Try / catch

try {
  const cfg = normalizeCompaction(userOptions);
} catch (err) {
  if ((err as Error).message === "cave_compaction_option_invalid") {
    console.error("Compaction options must be positive safe integers; using defaults");
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a compaction option that is 0, negative, fractional (e.g. 0.5), NaN, or exceeds Number.MAX_SAFE_INTEGER; passing a non-numeric value from parsed JSON/YAML config.

Common situations: Config files with token budgets written as strings; '0' used to mean 'disable' when 0 is rejected; copying a percentage (e.g. 0.25) where an absolute token count is expected.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/e7233c7190bfab88. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/compaction.ts:100

  keepRecentTokens: 8_000,
  summaryMaxTokens: 2_048,
  minYieldTokens: 20_000,
  headroomCalls: 3,
  pinnedUserTokens: 20_000,
});

export function normalizeCompaction(options: CompactionOptions = {}): NormalizedCompaction {
  const merged = {
    maxCompactions: options.maxCompactions ?? DEFAULTS.maxCompactions,
    keepRecentTokens: options.keepRecentTokens ?? DEFAULTS.keepRecentTokens,
    summaryMaxTokens: options.summaryMaxTokens ?? DEFAULTS.summaryMaxTokens,
    minYieldTokens: options.minYieldTokens ?? DEFAULTS.minYieldTokens,
    headroomCalls: options.headroomCalls ?? DEFAULTS.headroomCalls,
    pinnedUserTokens: options.pinnedUserTokens ?? DEFAULTS.pinnedUserTokens,
  };
  for (const value of Object.values(merged)) {
    if (!Number.isSafeInteger(value) || value <= 0) {
      throw new Error("cave_compaction_option_invalid");
    }
  }
  return Object.freeze({
    ...merged,
    summarizerModel: options.summarizerModel,
  });
}

/** Version of the summary contract the summarizer is asked to emit. */
export const SUMMARY_SCHEMA_VERSION = 1;

/**
 * The sectioned summary the summarizer must produce.
 *
 * Structure rather than prose keeps required fields explicit. `constraintsRestated`
 * is a restatement only — the pinned buffer is the carrier, and a summary that
 * becomes the only carrier reproduces the failure this design exists to avoid.
 */

View on GitHub (pinned to 3ee70a1026)