Skip to content

fix(config): NudgeConfig docstring defaults drift from actuals; validateConfig accepts non-finite nudge scalars that silently kill growth nudges #163

Description

@Tyan66666

Problem

Two defects found while auditing the npm package (0.0.29) during a downstream host-adapter review (billion-context-dsh PR #72); both re-verified against the v0.0.45 source today and still present.

1. NudgeConfig docstrings drift from actual defaults (src/types.ts)

Field Docstring says Actual default (defaultConfig, src/config.ts)
minGrowthFloor Default 5000 (src/types.ts:124) 20000 (src/config.ts:18)
emergencyThresholdPct Default 0.98 (98%) (src/types.ts:129) 0.95 (src/config.ts:20)

The other 10 nudge fields' docstrings were checked against defaultConfig() and are correct.

Impact: these docstrings are the only tuning contract for config authors — e.g. someone relying on "Default 0.98" will misdiagnose why emergency nudges start at 95%; anti-thrash floor math computed from a 5000 base is off by 4×. The published .d.ts in the npm tarball carries the same stale text.

2. validateConfig accepts non-finite / out-of-range nudge scalars, which silently disable growth nudges

validateConfig (src/config.ts:55) checks only ordering relations among the pct fields (min <= max <= emergency). None of the 12 nudge scalars gets a Number.isFinite or range check — and since every comparison against NaN is false, a NaN anywhere passes with zero errors.

Empirical failure chain for nudge.growthFloor: NaN (probed live on 0.0.29; code path identical at v0.0.45):

// resolveAdaptiveGrowth, src/compress.ts:1015
nudgeGrowthTokens = Math.min(cap, Math.max(NaN, Math.round(limit * ratio)))   // → NaN
// anti-thrash floor, src/compress.ts:1097
growthFloor = Math.max(minGrowthFloor, minGrowthRatio * NaN)                  // → NaN
// src/compress.ts:1122
growthReady = growthSinceReference >= NaN                                     // → false forever

Net effect: the growth-gated nudge path (the normal working band below maxContextLimitPct) never fires again; only the pressure band (usage >= maxContextLimitPct / emergency) still fires when pending content exists. No error, no warning — validateConfig returns [] and processing proceeds normally (call site src/compress.ts:351).

Also unvalidated today: negative or >1 pct values, frequency/iterationThreshold < 1, negative floors/caps. Conspicuous because the newer absorb config does get Number.isFinite checks (src/config.ts:90), so nudge is now the gap.

Fix (suggestion)

  1. Correct the two docstrings; optionally add a test asserting docstring defaults match defaultConfig() output to stop future drift.
  2. Extend validateConfig: Number.isFinite on all nudge scalars; [0, 1] range for maxContextLimitPct/minContextLimitPct/emergencyThresholdPct; > 0 for growthRatio/minGrowthRatio/tier2GrowthMultiplier; >= 0 (integer where sensible) for frequency/iterationThreshold/growthFloor/growthCap/minGrowthFloor. The existing ordering checks stay and become meaningful once finiteness is guaranteed.

Happy to send a PR if you'd take one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions