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)
- Correct the two docstrings; optionally add a test asserting docstring defaults match
defaultConfig() output to stop future drift.
- 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.
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.
NudgeConfigdocstrings drift from actual defaults (src/types.ts)defaultConfig, src/config.ts)minGrowthFloorDefault 5000(src/types.ts:124)emergencyThresholdPctDefault 0.98 (98%)(src/types.ts:129)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.tsin the npm tarball carries the same stale text.2.
validateConfigaccepts non-finite / out-of-range nudge scalars, which silently disable growth nudgesvalidateConfig(src/config.ts:55) checks only ordering relations among the pct fields (min <= max <= emergency). None of the 12 nudge scalars gets aNumber.isFiniteor range check — and since every comparison againstNaNis false, aNaNanywhere passes with zero errors.Empirical failure chain for
nudge.growthFloor: NaN(probed live on 0.0.29; code path identical at v0.0.45):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 —validateConfigreturns[]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 newerabsorbconfig does getNumber.isFinitechecks (src/config.ts:90), so nudge is now the gap.Fix (suggestion)
defaultConfig()output to stop future drift.validateConfig:Number.isFiniteon all nudge scalars;[0, 1]range formaxContextLimitPct/minContextLimitPct/emergencyThresholdPct;> 0forgrowthRatio/minGrowthRatio/tier2GrowthMultiplier;>= 0(integer where sensible) forfrequency/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.